[PATCH v1 1/4] iommu/arm-smmu: Fix fwnode lookup lifetime handling

From: weimin xiong

Date: Tue Jul 14 2026 - 02:12:21 EST


bus_find_device_by_fwnode() returns a device with its reference count
incremented. arm_smmu_get_by_fwnode() drops that reference before
reading the driver data, which leaves the returned pointer derived from
a device after its reference has been released.

Read the driver data before put_device(). Also handle a failed lookup in
arm_smmu_probe_device() before dereferencing the returned SMMU pointer.

Signed-off-by: weimin xiong <xiongwm2026@xxxxxxx>
---
drivers/iommu/arm/arm-smmu/arm-smmu.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c
index 0bd21d206..b70c307b8 100644
--- a/drivers/iommu/arm/arm-smmu/arm-smmu.c
+++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c
@@ -1426,9 +1426,15 @@ static
struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
{
struct device *dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
+ struct arm_smmu_device *smmu;
+
+ if (!dev)
+ return NULL;

+ smmu = dev_get_drvdata(dev);
put_device(dev);
- return dev ? dev_get_drvdata(dev) : NULL;
+
+ return smmu;
}

static struct iommu_device *arm_smmu_probe_device(struct device *dev)
@@ -1451,6 +1457,10 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev)
goto out_free;
} else {
smmu = arm_smmu_get_by_fwnode(fwspec->iommu_fwnode);
+ if (!smmu) {
+ ret = -ENODEV;
+ goto out_free;
+ }
}

ret = -EINVAL;
--
2.43.0