linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Zhang Shurong <zhang_shurong@foxmail.com>, joro@8bytes.org
Cc: will@kernel.org, wens@csie.org, jernej.skrabec@gmail.com,
	samuel@sholland.org, iommu@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] The sun50i_iommu_of_xlate() function didn't properly handle the case where of_find_device_by_node() returns NULL. This could lead to a NULL pointer dereference when accessing platform_get_drvdata(iommu_pdev) if the device node couldn't be found.
Date: Wed, 25 Jun 2025 11:41:35 +0100	[thread overview]
Message-ID: <ad58db6e-7c1d-42c4-8039-0d7f0f057726@arm.com> (raw)
In-Reply-To: <tencent_889D023A2A9B04DE8D592DFE961C5893C706@qq.com>

On 2025-06-24 9:35 am, Zhang Shurong wrote:
> Add a WARN_ON() check to detect this condition and return -ENODEV when it
> occurs. This ensures proper error handling and helps diagnose incorrect
> device tree configurations at runtime.

Please look at how this op is called in of_iommu_xlate(), then at how 
the ops are registered by sun50i_iommu_probe(), and then clarify how you 
think the driver could ever be bound to a device which does not exist.

Thanks,
Robin.

> Fixes: 4100b8c229b3 ("iommu: Add Allwinner H6 IOMMU driver")
> Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.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 76c9620af4bb..0f85850269ae 100644
> --- a/drivers/iommu/sun50i-iommu.c
> +++ b/drivers/iommu/sun50i-iommu.c
> @@ -833,6 +833,9 @@ static int sun50i_iommu_of_xlate(struct device *dev,
>   				 const struct of_phandle_args *args)
>   {
>   	struct platform_device *iommu_pdev = of_find_device_by_node(args->np);
> +	if (WARN_ON(!iommu_pdev))
> +		return -ENODEV;
> +
>   	unsigned id = args->args[0];
>   
>   	dev_iommu_priv_set(dev, platform_get_drvdata(iommu_pdev));


  reply	other threads:[~2025-06-25 10:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-24  8:35 [PATCH] The sun50i_iommu_of_xlate() function didn't properly handle the case where of_find_device_by_node() returns NULL. This could lead to a NULL pointer dereference when accessing platform_get_drvdata(iommu_pdev) if the device node couldn't be found Zhang Shurong
2025-06-25 10:41 ` Robin Murphy [this message]
2025-06-27  7:16 ` Joerg Roedel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ad58db6e-7c1d-42c4-8039-0d7f0f057726@arm.com \
    --to=robin.murphy@arm.com \
    --cc=iommu@lists.linux.dev \
    --cc=jernej.skrabec@gmail.com \
    --cc=joro@8bytes.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=samuel@sholland.org \
    --cc=wens@csie.org \
    --cc=will@kernel.org \
    --cc=zhang_shurong@foxmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).