iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iommu/sun50i: check return value of of_find_device_by_node() in sun50i_iommu_of_xlate()
@ 2020-10-29  9:22 Yu Kuai
  2020-10-29  9:25 ` Maxime Ripard
  2020-10-29 10:21 ` Robin Murphy
  0 siblings, 2 replies; 3+ messages in thread
From: Yu Kuai @ 2020-10-29  9:22 UTC (permalink / raw)
  To: joro, mripard, wens
  Cc: yukuai3, iommu, linux-kernel, linux-arm-kernel, yi.zhang

If of_find_device_by_node() failed in sun50i_iommu_of_xlate(), null
pointer dereference will be triggered. Thus return error code if
of_find_device_by_node() failed.

Fixes: 4100b8c229b3("iommu: Add Allwinner H6 IOMMU driver")
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 drivers/iommu/sun50i-iommu.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c
index ea6db1341916..ce94ffa15215 100644
--- a/drivers/iommu/sun50i-iommu.c
+++ b/drivers/iommu/sun50i-iommu.c
@@ -764,6 +764,9 @@ static int sun50i_iommu_of_xlate(struct device *dev,
 	struct platform_device *iommu_pdev = of_find_device_by_node(args->np);
 	unsigned id = args->args[0];
 
+	if (!iommu_pdev)
+		return -ENODEV;
+
 	dev_iommu_priv_set(dev, platform_get_drvdata(iommu_pdev));
 
 	return iommu_fwspec_add_ids(dev, &id, 1);
-- 
2.25.4

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iommu/sun50i: check return value of of_find_device_by_node() in sun50i_iommu_of_xlate()
  2020-10-29  9:22 [PATCH] iommu/sun50i: check return value of of_find_device_by_node() in sun50i_iommu_of_xlate() Yu Kuai
@ 2020-10-29  9:25 ` Maxime Ripard
  2020-10-29 10:21 ` Robin Murphy
  1 sibling, 0 replies; 3+ messages in thread
From: Maxime Ripard @ 2020-10-29  9:25 UTC (permalink / raw)
  To: Yu Kuai; +Cc: yi.zhang, iommu, linux-kernel, wens, linux-arm-kernel


[-- Attachment #1.1: Type: text/plain, Size: 414 bytes --]

On Thu, Oct 29, 2020 at 05:22:44PM +0800, Yu Kuai wrote:
> If of_find_device_by_node() failed in sun50i_iommu_of_xlate(), null
> pointer dereference will be triggered. Thus return error code if
> of_find_device_by_node() failed.
> 
> Fixes: 4100b8c229b3("iommu: Add Allwinner H6 IOMMU driver")
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>

Acked-by: Maxime Ripard <mripard@kernel.org>

Thanks!
Maxime

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 156 bytes --]

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iommu/sun50i: check return value of of_find_device_by_node() in sun50i_iommu_of_xlate()
  2020-10-29  9:22 [PATCH] iommu/sun50i: check return value of of_find_device_by_node() in sun50i_iommu_of_xlate() Yu Kuai
  2020-10-29  9:25 ` Maxime Ripard
@ 2020-10-29 10:21 ` Robin Murphy
  1 sibling, 0 replies; 3+ messages in thread
From: Robin Murphy @ 2020-10-29 10:21 UTC (permalink / raw)
  To: Yu Kuai, joro, mripard, wens
  Cc: iommu, linux-kernel, linux-arm-kernel, yi.zhang

On 2020-10-29 09:22, Yu Kuai wrote:
> If of_find_device_by_node() failed in sun50i_iommu_of_xlate(), null
> pointer dereference will be triggered. Thus return error code if
> of_find_device_by_node() failed.

Again, by what means can that ever actually happen?

Robin.

> Fixes: 4100b8c229b3("iommu: Add Allwinner H6 IOMMU driver")
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
>   drivers/iommu/sun50i-iommu.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c
> index ea6db1341916..ce94ffa15215 100644
> --- a/drivers/iommu/sun50i-iommu.c
> +++ b/drivers/iommu/sun50i-iommu.c
> @@ -764,6 +764,9 @@ static int sun50i_iommu_of_xlate(struct device *dev,
>   	struct platform_device *iommu_pdev = of_find_device_by_node(args->np);
>   	unsigned id = args->args[0];
>   
> +	if (!iommu_pdev)
> +		return -ENODEV;
> +
>   	dev_iommu_priv_set(dev, platform_get_drvdata(iommu_pdev));
>   
>   	return iommu_fwspec_add_ids(dev, &id, 1);
> 
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-10-29 10:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-29  9:22 [PATCH] iommu/sun50i: check return value of of_find_device_by_node() in sun50i_iommu_of_xlate() Yu Kuai
2020-10-29  9:25 ` Maxime Ripard
2020-10-29 10:21 ` Robin Murphy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).