From: weiping zhang Date: Wed, 29 Nov 2017 01:23:01 +0000 (+0800) Subject: virtio: release virtio index when fail to device_register X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=e60ea67bb60459b95a50a156296041a13e0e380e;p=openwrt%2Fstaging%2Fblogic.git 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 Reviewed-by: Cornelia Huck Signed-off-by: Michael S. Tsirkin --- 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);