[PATCH v10 02/15] scsi: core: release the device tree node at final device release
From: Phil Pemberton
Date: Fri Oct 09 2026 - 12:28:52 EST
libata's ata_scsi_assign_ofnode() retains the reference returned by
for_each_available_child_of_node() when assigning a matching child to
sdev_gendev.of_node. Neither SCSI nor the generic device release path
currently drops that reference, leaking it with CONFIG_OF_DYNAMIC.
Drop the reference in scsi_device_dev_release(), after the last reference
to the SCSI device has gone away. The node must remain valid for the
lifetime of the device; putting it at assignment would leave an unowned
pointer. Final release also covers assignment racing with device removal
while the scanner still holds a SCSI device reference.
Fixes: 45b8084f3fcb ("libata: Assign OF node to the SCSI device")
Assisted-by: LLM
Signed-off-by: Phil Pemberton <philpem@xxxxxxxxxxxxx>
---
drivers/scsi/scsi_sysfs.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 9480432f650b..5e766e976a1d 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -14,6 +14,7 @@
#include <linux/device.h>
#include <linux/pm_runtime.h>
#include <linux/bsg.h>
+#include <linux/of.h>
#include <scsi/scsi.h>
#include <scsi/scsi_device.h>
@@ -517,6 +518,7 @@ static void scsi_device_dev_release(struct device *dev)
if (vpd_pgb7)
kfree_rcu(vpd_pgb7, rcu);
kfree(sdev->inquiry);
+ of_node_put(dev->of_node);
kfree(sdev);
if (parent)
--
2.43.0