[PATCH] scsi_sysfs: Fix runtime PM usage count leak on device add failure
From: Haoxiang Li
Date: Mon Jun 22 2026 - 11:43:12 EST
Balance the scsi_autopm_get_device() call on the error paths of
scsi_sysfs_add_sdev() by releasing the runtime PM reference before
returning.
Signed-off-by: Haoxiang Li <haoxiang_li2024@xxxxxxx>
---
drivers/scsi/scsi_sysfs.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index dfc3559e7e04..6b009e4f4b9e 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -1427,7 +1427,7 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
if (error) {
sdev_printk(KERN_INFO, sdev,
"failed to add device: %d\n", error);
- return error;
+ goto out_autopm_put;
}
device_enable_async_suspend(&sdev->sdev_dev);
@@ -1436,7 +1436,7 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
sdev_printk(KERN_INFO, sdev,
"failed to add class device: %d\n", error);
device_del(&sdev->sdev_gendev);
- return error;
+ goto out_autopm_put;
}
transport_add_device(&sdev->sdev_gendev);
sdev->is_visible = 1;
@@ -1452,6 +1452,7 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
}
}
+out_autopm_put:
scsi_autopm_put_device(sdev);
return error;
}
--
2.25.1