* [PATCH] iommu/dart: check return value after calling platform_get_resource()
@ 2022-04-25 9:08 ` Yang Yingliang via iommu
0 siblings, 0 replies; 6+ messages in thread
From: Yang Yingliang @ 2022-04-25 9:08 UTC (permalink / raw)
To: linux-kernel, iommu; +Cc: will, joro, alyssa, sven
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")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
drivers/iommu/apple-dart.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
index decafb07ad08..15b77f16cfa3 100644
--- a/drivers/iommu/apple-dart.c
+++ b/drivers/iommu/apple-dart.c
@@ -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;
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] iommu/dart: check return value after calling platform_get_resource()
@ 2022-04-25 9:08 ` Yang Yingliang via iommu
0 siblings, 0 replies; 6+ messages in thread
From: Yang Yingliang via iommu @ 2022-04-25 9:08 UTC (permalink / raw)
To: linux-kernel, iommu; +Cc: will, alyssa
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")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
drivers/iommu/apple-dart.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
index decafb07ad08..15b77f16cfa3 100644
--- a/drivers/iommu/apple-dart.c
+++ b/drivers/iommu/apple-dart.c
@@ -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;
--
2.25.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] iommu/dart: check return value after calling platform_get_resource()
2022-04-25 9:08 ` Yang Yingliang via iommu
@ 2022-04-26 20:22 ` Sven Peter via iommu
-1 siblings, 0 replies; 6+ messages in thread
From: Sven Peter @ 2022-04-26 20:22 UTC (permalink / raw)
To: Yang Yingliang; +Cc: linux-kernel, iommu, will, joro, alyssa
> On 25. Apr 2022, at 10:56, Yang Yingliang <yangyingliang@huawei.com> wrote:
>
> 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")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Reviewed-by: Sven Peter <sven@svenpeter.dev>
Thanks,
Sven
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] iommu/dart: check return value after calling platform_get_resource()
@ 2022-04-26 20:22 ` Sven Peter via iommu
0 siblings, 0 replies; 6+ messages in thread
From: Sven Peter via iommu @ 2022-04-26 20:22 UTC (permalink / raw)
To: Yang Yingliang; +Cc: iommu, will, linux-kernel, alyssa
> On 25. Apr 2022, at 10:56, Yang Yingliang <yangyingliang@huawei.com> wrote:
>
> 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")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Reviewed-by: Sven Peter <sven@svenpeter.dev>
Thanks,
Sven
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] iommu/dart: check return value after calling platform_get_resource()
2022-04-25 9:08 ` Yang Yingliang via iommu
@ 2022-04-28 9:39 ` Joerg Roedel
-1 siblings, 0 replies; 6+ messages in thread
From: Joerg Roedel @ 2022-04-28 9:39 UTC (permalink / raw)
To: Yang Yingliang; +Cc: iommu, will, linux-kernel, alyssa
On Mon, Apr 25, 2022 at 05:08:26PM +0800, Yang Yingliang wrote:
> 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")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
> drivers/iommu/apple-dart.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
Applied to iommu/fixes, thanks.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] iommu/dart: check return value after calling platform_get_resource()
@ 2022-04-28 9:39 ` Joerg Roedel
0 siblings, 0 replies; 6+ messages in thread
From: Joerg Roedel @ 2022-04-28 9:39 UTC (permalink / raw)
To: Yang Yingliang; +Cc: linux-kernel, iommu, will, alyssa, sven
On Mon, Apr 25, 2022 at 05:08:26PM +0800, Yang Yingliang wrote:
> 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")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
> drivers/iommu/apple-dart.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
Applied to iommu/fixes, thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-04-28 9:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-25 9:08 [PATCH] iommu/dart: check return value after calling platform_get_resource() Yang Yingliang
2022-04-25 9:08 ` Yang Yingliang via iommu
2022-04-26 20:22 ` Sven Peter
2022-04-26 20:22 ` Sven Peter via iommu
2022-04-28 9:39 ` Joerg Roedel
2022-04-28 9:39 ` Joerg Roedel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.