diff mbox

[RFC,6/9] tcmu: fix tcmu_free_device cleanup from configuration failures

Message ID 1497262209-5635-7-git-send-email-mchristi@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Mike Christie June 12, 2017, 10:10 a.m. UTC
If the configure_device fails udev->node will not have been added
to the root dev and we would have already freed or not setup
the mb_addr and block lookup handler. Move that cleanup to under
the tcmu_dev_configured check.

Signed-off-by: Mike Christie <mchristi@redhat.com>
---
 drivers/target/target_core_user.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)
diff mbox

Patch

diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
index 9f133ee..3220e77 100644
--- a/drivers/target/target_core_user.c
+++ b/drivers/target/target_core_user.c
@@ -1553,12 +1553,6 @@  static void tcmu_free_device(struct se_device *dev)
 
 	del_timer_sync(&udev->timeout);
 
-	mutex_lock(&root_udev_mutex);
-	list_del(&udev->node);
-	mutex_unlock(&root_udev_mutex);
-
-	vfree(udev->mb_addr);
-
 	/* Upper layer should drain all requests before calling this */
 	spin_lock_irq(&udev->commands_lock);
 	idr_for_each_entry(&udev->commands, cmd, i) {
@@ -1569,13 +1563,17 @@  static void tcmu_free_device(struct se_device *dev)
 	spin_unlock_irq(&udev->commands_lock);
 	WARN_ON(!all_expired);
 
-	tcmu_blocks_release(udev);
-
-	if (tcmu_dev_configured(udev)) {
-		tcmu_netlink_event(TCMU_CMD_REMOVED_DEVICE, udev->uio_info.name,
-				   udev->uio_info.uio_dev->minor, 0, NULL);
+	if (tcmu_dev_configured(udev)) {	
+		tcmu_netlink_event(udev, TCMU_CMD_REMOVED_DEVICE, 0, NULL);
 
 		uio_unregister_device(&udev->uio_info);
+
+		mutex_lock(&root_udev_mutex);
+		list_del(&udev->node);
+		mutex_unlock(&root_udev_mutex);
+
+		vfree(udev->mb_addr);
+		tcmu_blocks_release(udev);
 	}
 
 	/* release ref from init */