Skip to contentSkip to conversation

media: rkvdec: Fix incorrect NULL check for iommu_paging_domain_alloc

PATCH In review Miaoqian Lin 3 participants 3 messages Aug 5, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: rkvdec: Fix incorrect NULL check for iommu_paging_domain_alloc

iommu_paging_domain_alloc returns error pointers on failure. Replace the NULL check with IS_ERR to correctly handle error cases and avoid invalid pointer dereference.

Fixes ff8c5622f9f7 ("media: rkvdec: Restore iommu addresses on errors")
---
 drivers/media/platform/rockchip/rkvdec/rkvdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/rockchip/rkvdec/rkvdec.c +1 -1
index d707088ec0dc..1d40e81f44b9 100644
@@ -1162,7 +1162,7 @@ static int rkvdec_probe(struct platform_device *pdev)
 	if (iommu_get_domain_for_dev(&pdev->dev)) {
 		rkvdec->empty_domain = iommu_paging_domain_alloc(rkvdec->dev);
 
-		if (!rkvdec->empty_domain)
+		if (IS_ERR(rkvdec->empty_domain))
 			dev_warn(rkvdec->dev, "cannot alloc new empty domain\n");
 	}
 
Signature · 1 line
2.35.1
maintainer Reviewed-by on v1 1/1
#1 lore raw

Am Dienstag, 5. August 2025, 08:18:33 Mitteleuropäische Sommerzeit schrieb Miaoqian Lin:

Quoted 6 lines

iommu_paging_domain_alloc returns error pointers on failure. Replace the NULL check with IS_ERR to correctly handle error cases and avoid invalid pointer dereference.

Fixes ff8c5622f9f7 ("media: rkvdec: Restore iommu addresses on errors")

Going from the (static inline) function definition [0] to the iommu_paging_domain_alloc_flags() function [1] it uses, the doc states
"Return [...] or an ERR pointer for failure."

So this is the correct fix,

[0] https://elixir.bootlin.com/linux/v6.16/source/include/linux/iommu.h#L858
[1] https://elixir.bootlin.com/linux/v6.16/source/drivers/iommu/iommu.c#L2046

#2 lore raw
In reply to Miaoqian Lin

Hi,

Le mardi 05 août 2025 à 10:18 +0400, Miaoqian Lin a écrit :

Quoted 20 lines

iommu_paging_domain_alloc returns error pointers on failure. Replace the NULL check with IS_ERR to correctly handle error cases and avoid invalid pointer dereference.

Fixes ff8c5622f9f7 ("media: rkvdec: Restore iommu addresses on errors")

---
 drivers/media/platform/rockchip/rkvdec/rkvdec.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/rockchip/rkvdec/rkvdec.c +0 -0
index d707088ec0dc..1d40e81f44b9 100644
@@ -1162,7 +1162,7 @@ static int rkvdec_probe(struct platform_device *pdev)
  	if (iommu_get_domain_for_dev(&pdev->dev)) {

  rkvdec->empty_domain = iommu_paging_domain_alloc(rkvdec-

Quoted 1 line

dev);

drivers/media/platform/rockchip/rkvdec/rkvdec.c static int rkvdec_probe(struct platform_device *pdev) · line 1165

Quoted 2 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +1 -1
-		if (!rkvdec->empty_domain)
+		if (IS_ERR(rkvdec->empty_domain))

Thanks for the fix, but Dan Carpenter have already sent this fix. It will be included soon.

https://lore.kernel.org/linux-media/[email protected]/

regards,
Nicolas

Quoted 4 lines

  dev_warn(rkvdec->dev, "cannot alloc new empty domain\n");
  }