Skip to contentSkip to conversation

virtio: release virtio index when fail to device_register

PATCH New weiping zhang 1 participant 1 message Nov 28, 2017 virtio core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio: release virtio index when fail to device_register

index can be reused by other virtio device.

---
 drivers/virtio/virtio.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/virtio/virtio.c +2 -0
index 48230a5..bf7ff39 100644
@@ -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);
Signature · 1 line
2.9.4