diff options
author | Michael S. Tsirkin <mst@redhat.com> | 2014-10-14 19:52:33 -0400 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2014-10-14 19:55:14 -0400 |
commit | 1bbc26062754b012656d34103215f7552e02b999 (patch) | |
tree | 29f9d12a2b0c773d0fe5ef466e60e8c5abdd27be /drivers/char/hw_random | |
parent | 5d8f16d08ba42937ae8c4152d218a77671be4b8f (diff) |
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: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'drivers/char/hw_random')
-rw-r--r-- | drivers/char/hw_random/virtio-rng.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c index 2e3139eda93b..14e351d094ae 100644 --- a/drivers/char/hw_random/virtio-rng.c +++ b/drivers/char/hw_random/virtio-rng.c | |||
@@ -105,8 +105,8 @@ static int probe_common(struct virtio_device *vdev) | |||
105 | 105 | ||
106 | vi->index = index = ida_simple_get(&rng_index_ida, 0, 0, GFP_KERNEL); | 106 | vi->index = index = ida_simple_get(&rng_index_ida, 0, 0, GFP_KERNEL); |
107 | if (index < 0) { | 107 | if (index < 0) { |
108 | kfree(vi); | 108 | err = index; |
109 | return index; | 109 | goto err_ida; |
110 | } | 110 | } |
111 | sprintf(vi->name, "virtio_rng.%d", index); | 111 | sprintf(vi->name, "virtio_rng.%d", index); |
112 | init_completion(&vi->have_data); | 112 | init_completion(&vi->have_data); |
@@ -124,13 +124,16 @@ static int probe_common(struct virtio_device *vdev) | |||
124 | vi->vq = virtio_find_single_vq(vdev, random_recv_done, "input"); | 124 | vi->vq = virtio_find_single_vq(vdev, random_recv_done, "input"); |
125 | if (IS_ERR(vi->vq)) { | 125 | if (IS_ERR(vi->vq)) { |
126 | err = PTR_ERR(vi->vq); | 126 | err = PTR_ERR(vi->vq); |
127 | vi->vq = NULL; | 127 | goto err_find; |
128 | kfree(vi); | ||
129 | ida_simple_remove(&rng_index_ida, index); | ||
130 | return err; | ||
131 | } | 128 | } |
132 | 129 | ||
133 | return 0; | 130 | return 0; |
131 | |||
132 | err_find: | ||
133 | ida_simple_remove(&rng_index_ida, index); | ||
134 | err_ida: | ||
135 | kfree(vi); | ||
136 | return err; | ||
134 | } | 137 | } |
135 | 138 | ||
136 | static void remove_common(struct virtio_device *vdev) | 139 | static void remove_common(struct virtio_device *vdev) |