Skip to contentSkip to conversation

iommu/dart: check return value after calling platform_get_resource()

PATCH In review Yang Yingliang 3 participants 3 messages Apr 25, 2022 – Apr 28, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/dart: check return value after calling platform_get_resource()

It will cause null-ptr-deref in resource_size(), if platform_get_resource() returns NULL, move calling resource_size() after devm_ioremap_resource() that will check 'res' to avoid null-ptr-deref.
And use devm_platform_get_and_ioremap_resource() to simplify code.

Fixes 46d1fb072e76 ("iommu/dart: Add DART iommu driver")
---
 drivers/iommu/apple-dart.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/iommu/apple-dart.c +4 -5
index decafb07ad08..15b77f16cfa3 100644
@@ -859,16 +859,15 @@ static int apple_dart_probe(struct platform_device *pdev)
 	dart->dev = dev;
 	spin_lock_init(&dart->lock);
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	dart->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
+	if (IS_ERR(dart->regs))
+		return PTR_ERR(dart->regs);
+
 	if (resource_size(res) < 0x4000) {
 		dev_err(dev, "MMIO region too small (%pr)\n", res);
 		return -EINVAL;
 	}
 
-	dart->regs = devm_ioremap_resource(dev, res);
-	if (IS_ERR(dart->regs))
-		return PTR_ERR(dart->regs);
-
 	dart->irq = platform_get_irq(pdev, 0);
 	if (dart->irq < 0)
 		return -ENODEV;
Signature · 6 lines
2.25.1

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Yang Yingliang

It will cause null-ptr-deref in resource_size(), if platform_get_resource() returns NULL, move calling resource_size() after devm_ioremap_resource() that will check 'res' to avoid null-ptr-deref.
And use devm_platform_get_and_ioremap_resource() to simplify code.

Fixes 46d1fb072e76 ("iommu/dart: Add DART iommu driver")

Thanks,

Sven

maintainer
#2 lore raw
In reply to Yang Yingliang
Quoted 10 lines · Yang Yingliang

It will cause null-ptr-deref in resource_size(), if platform_get_resource() returns NULL, move calling resource_size() after devm_ioremap_resource() that will check 'res' to avoid null-ptr-deref.
And use devm_platform_get_and_ioremap_resource() to simplify code.

Fixes 46d1fb072e76 ("iommu/dart: Add DART iommu driver")
---
 drivers/iommu/apple-dart.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Applied to iommu/fixes, thanks.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu