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-Tag: v4.4.106~97 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=94739ddf35cba7c4002489f212186010888b421e;p=thirdparty%2Fkernel%2Fstable.git virtio: release virtio index when fail to device_register commit e60ea67bb60459b95a50a156296041a13e0e380e upstream. index can be reused by other virtio device. Signed-off-by: weiping zhang Reviewed-by: Cornelia Huck Signed-off-by: Michael S. Tsirkin Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c index 7062bb0975a52..462e183609b6b 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c @@ -323,6 +323,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) add_status(dev, VIRTIO_CONFIG_S_FAILED);