diff mbox series

iommu/sun50i: check return value of of_find_device_by_node() in sun50i_iommu_of_xlate()

Message ID 20201029092244.900564-1-yukuai3@huawei.com (mailing list archive)
State New, archived
Headers show
Series iommu/sun50i: check return value of of_find_device_by_node() in sun50i_iommu_of_xlate() | expand

Commit Message

Yu Kuai Oct. 29, 2020, 9:22 a.m. UTC
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(+)

Comments

Maxime Ripard Oct. 29, 2020, 9:25 a.m. UTC | #1
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
Robin Murphy Oct. 29, 2020, 10:21 a.m. UTC | #2
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);
>
diff mbox series

Patch

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);