Skip to contentSkip to conversation

scsi: core: fix error handling for scsi_alloc_sdev()

PATCH Superseded Junxiao Bi 2 participants 2 messages Mar 3 – Mar 4 SCSI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Junxiao Bi

author
#0 lore raw

PATCH 1/1 scsi: core: fix error handling for scsi_alloc_sdev()

scsi_sysfs_device_initialize() was already invoked when scsi_realloc_sdev_budget_map() fail, it will need invoke __scsi_remove_device() to do the error handling.

Fixes 1ac22c8eae81 ("scsi: core: Fix refcount leak for tagset_refcnt")
---
 drivers/scsi/scsi_scan.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/scsi/scsi_scan.c +2 -6
index 2cfcf1f5d6a4..7b11bc7de0e3 100644
@@ -360,12 +360,8 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
 	 * default device queue depth to figure out sbitmap shift
 	 * since we use this queue depth most of times.
 	 */
-	if (scsi_realloc_sdev_budget_map(sdev, depth)) {
-		kref_put(&sdev->host->tagset_refcnt, scsi_mq_free_tags);
-		put_device(&starget->dev);
-		kfree(sdev);
-		goto out;
-	}
+	if (scsi_realloc_sdev_budget_map(sdev, depth))
+		goto out_device_destroy;
 
 	scsi_change_queue_depth(sdev, depth);
 
Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw
Quoted 3 lines · Junxiao Bi

scsi_sysfs_device_initialize() was already invoked when scsi_realloc_sdev_budget_map() fail, it will need invoke __scsi_remove_device() to do the error handling.

That's too vague. The description should mention that after scsi_sysfs_device_initialize() has been called, error paths must call __scsi_remove_device().

Otherwise this patch looks good to me.

Thanks,

Bart.