* [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.
@ 2025-06-24 8:35 Zhang Shurong
2025-06-25 10:41 ` Robin Murphy
2025-06-27 7:16 ` Joerg Roedel
0 siblings, 2 replies; 3+ messages in thread
From: Zhang Shurong @ 2025-06-24 8:35 UTC (permalink / raw)
To: joro
Cc: will, robin.murphy, wens, jernej.skrabec, samuel, iommu,
linux-arm-kernel, linux-sunxi, linux-kernel, Zhang Shurong
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.
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));
--
2.39.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* 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.
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
2025-06-27 7:16 ` Joerg Roedel
1 sibling, 0 replies; 3+ messages in thread
From: Robin Murphy @ 2025-06-25 10:41 UTC (permalink / raw)
To: Zhang Shurong, joro
Cc: will, wens, jernej.skrabec, samuel, iommu, linux-arm-kernel,
linux-sunxi, linux-kernel
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));
^ permalink raw reply [flat|nested] 3+ messages in thread
* 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.
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
@ 2025-06-27 7:16 ` Joerg Roedel
1 sibling, 0 replies; 3+ messages in thread
From: Joerg Roedel @ 2025-06-27 7:16 UTC (permalink / raw)
To: Zhang Shurong
Cc: will, robin.murphy, wens, jernej.skrabec, samuel, iommu,
linux-arm-kernel, linux-sunxi, linux-kernel
The subject line is too long, use something short which describes WHAT
the patch does. The WHY can be placed into the commit message.
Thanks,
Joerg
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-06-27 7:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2025-06-27 7:16 ` Joerg Roedel
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).