Commit 1bbc2606 authored by Michael S. Tsirkin's avatar Michael S. Tsirkin Committed by Rusty Russell

virtio-rng: refactor probe error handling

Code like
	vi->vq = NULL;
	kfree(vi)
does not make sense.

Clean it up, use goto error labels for cleanup.
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 5d8f16d0
...@@ -105,8 +105,8 @@ static int probe_common(struct virtio_device *vdev) ...@@ -105,8 +105,8 @@ static int probe_common(struct virtio_device *vdev)
vi->index = index = ida_simple_get(&rng_index_ida, 0, 0, GFP_KERNEL); vi->index = index = ida_simple_get(&rng_index_ida, 0, 0, GFP_KERNEL);
if (index < 0) { if (index < 0) {
kfree(vi); err = index;
return index; goto err_ida;
} }
sprintf(vi->name, "virtio_rng.%d", index); sprintf(vi->name, "virtio_rng.%d", index);
init_completion(&vi->have_data); init_completion(&vi->have_data);
...@@ -124,13 +124,16 @@ static int probe_common(struct virtio_device *vdev) ...@@ -124,13 +124,16 @@ static int probe_common(struct virtio_device *vdev)
vi->vq = virtio_find_single_vq(vdev, random_recv_done, "input"); vi->vq = virtio_find_single_vq(vdev, random_recv_done, "input");
if (IS_ERR(vi->vq)) { if (IS_ERR(vi->vq)) {
err = PTR_ERR(vi->vq); err = PTR_ERR(vi->vq);
vi->vq = NULL; goto err_find;
kfree(vi);
ida_simple_remove(&rng_index_ida, index);
return err;
} }
return 0; return 0;
err_find:
ida_simple_remove(&rng_index_ida, index);
err_ida:
kfree(vi);
return err;
} }
static void remove_common(struct virtio_device *vdev) static void remove_common(struct virtio_device *vdev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment