Skip to contentSkip to conversation

iommu: Check dev->iommu in dev_iommu_priv_get() before dereferencing it

PATCH New Joerg Roedel 1 participant 1 message Feb 2, 2021

Subsystems (2)
lore
Share & tools
lore

Joerg Roedel

author maintainer
#0 lore raw

PATCH 1/1 iommu: Check dev->iommu in dev_iommu_priv_get() before dereferencing it

From: Joerg Roedel <[email protected]>

The dev_iommu_priv_get() needs a similar check to dev_iommu_fwspec_get() to make sure no NULL-ptr is dereferenced.

Fixes 05a0542b456e1 ("iommu/amd: Store dev_data as device iommu private data")

Reference: https://bugzilla.kernel.org/show_bug.cgi?id=211241

---
 include/linux/iommu.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/linux/iommu.h +4 -1
index 524ffc2ff64f..5b3a7a08dc70 100644
@@ -616,7 +616,10 @@ static inline void dev_iommu_fwspec_set(struct device *dev,
 
 static inline void *dev_iommu_priv_get(struct device *dev)
 {
-	return dev->iommu->priv;
+	if (dev->iommu)
+		return dev->iommu->priv;
+	else
+		return NULL;
 }
 
 static inline void dev_iommu_priv_set(struct device *dev, void *priv)
Signature · 6 lines
2.30.0

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu