summaryrefslogtreecommitdiffstats
path: root/drivers/virtio
diff options
context:
space:
mode:
authorweiping zhang <zwp10758@gmail.com>2017-11-29 09:23:01 +0800
committerMichael S. Tsirkin <mst@redhat.com>2017-12-01 16:55:32 +0200
commite60ea67bb60459b95a50a156296041a13e0e380e (patch)
tree3a84c30892f84e70e9ea5c7c24e1ee55ddb8ca0c /drivers/virtio
parent23f1b8d938c861ee0bbb786162f7ce0685f722ec (diff)
downloadlinux-e60ea67bb60459b95a50a156296041a13e0e380e.tar.bz2
virtio: release virtio index when fail to device_register
index can be reused by other virtio device. Cc: stable@vger.kernel.org Signed-off-by: weiping zhang <zhangweiping@didichuxing.com> Reviewed-by: Cornelia Huck <cohuck@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'drivers/virtio')
-rw-r--r--drivers/virtio/virtio.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index 48230a5e12f2..bf7ff3934d7f 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -333,6 +333,8 @@ int register_virtio_device(struct virtio_device *dev)
/* device_register() causes the bus infrastructure to look for a
* matching driver. */
err = device_register(&dev->dev);
+ if (err)
+ ida_simple_remove(&virtio_index_ida, dev->index);
out:
if (err)
virtio_add_status(dev, VIRTIO_CONFIG_S_FAILED);