Skip to contentSkip to conversation

scsi: core: fix error handling for scsi_alloc_sdev()

PATCH Applied Junxiao Bi 4 participants 4 messages Mar 4 – Mar 11 SCSI

lore
Share & tools
lore

Junxiao Bi

author
#0 lore raw

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

After scsi_sysfs_device_initialize() was called, error paths must call __scsi_remove_device().

Fixes 1ac22c8eae81 ("scsi: core: Fix refcount leak for tagset_refcnt")

---
v2 <- v1:
- fix patch log

 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)
Reviewed-by on v2 1/1
#2 lore raw
In reply to Junxiao Bi
Quoted 2 lines · Junxiao Bi

After scsi_sysfs_device_initialize() was called, error paths must call __scsi_remove_device().

My suggestion was to include the above sentence in the patch description instead of replacing the entire patch description with the above sentence. Anyway: