public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH 1/5] staging: media: tegra-video: add NULL checks for of_device_get_match_data()
@ 2026-04-12 20:50 Alexandru Hossu
  2026-04-13  3:07 ` Mikko Perttunen
  2026-04-13  5:21 ` Alexandru Hossu
  0 siblings, 2 replies; 3+ messages in thread
From: Alexandru Hossu @ 2026-04-12 20:50 UTC (permalink / raw)
  To: linux-media, linux-tegra
  Cc: thierry.reding, jonathanh, skomatineni, luca.ceresoli, mchehab,
	gregkh, linux-staging, linux-kernel, Alexandru Hossu

tegra_csi_probe(), tegra_vi_probe(), and tegra_vip_probe() all call
of_device_get_match_data() to retrieve SoC-specific data from the device
tree match table, but none of them check the return value for NULL before
eventually dereferencing it.

In tegra_csi_probe(), the pointer is dereferenced on the very next
statement via csi->soc->num_clks. In tegra_vi_probe(), it is dereferenced
later via vi->soc->ops. In tegra_vip_probe(), vip->soc is stored and then
dereferenced at runtime via vip->soc->ops->vip_start_streaming(). A NULL
return would cause a kernel NULL pointer dereference in each case.

Add a NULL check returning -ENODEV in all three probe functions, consistent
with the defensive pattern already used in similar staging drivers such as
drivers/staging/media/sunxi/cedrus/cedrus_hw.c.

Signed-off-by: Alexandru Hossu <hossu.alexandru@gmail.com>
---
 drivers/staging/media/tegra-video/csi.c | 2 ++
 drivers/staging/media/tegra-video/vi.c  | 2 ++
 drivers/staging/media/tegra-video/vip.c | 2 ++
 3 files changed, 6 insertions(+)

diff --git a/drivers/staging/media/tegra-video/csi.c b/drivers/staging/media/tegra-video/csi.c
index 7842104ca933..33369a8c803a 100644
--- a/drivers/staging/media/tegra-video/csi.c
+++ b/drivers/staging/media/tegra-video/csi.c
@@ -781,6 +781,8 @@ static int tegra_csi_probe(struct platform_device *pdev)
 		return PTR_ERR(csi->iomem);
 
 	csi->soc = of_device_get_match_data(&pdev->dev);
+	if (!csi->soc)
+		return -ENODEV;
 
 	csi->clks = devm_kcalloc(&pdev->dev, csi->soc->num_clks,
 				 sizeof(*csi->clks), GFP_KERNEL);
diff --git a/drivers/staging/media/tegra-video/vi.c b/drivers/staging/media/tegra-video/vi.c
index d1d934e361f7..f3b749f059f8 100644
--- a/drivers/staging/media/tegra-video/vi.c
+++ b/drivers/staging/media/tegra-video/vi.c
@@ -1907,6 +1907,8 @@ static int tegra_vi_probe(struct platform_device *pdev)
 		return PTR_ERR(vi->iomem);
 
 	vi->soc = of_device_get_match_data(&pdev->dev);
+	if (!vi->soc)
+		return -ENODEV;
 
 	vi->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(vi->clk)) {
diff --git a/drivers/staging/media/tegra-video/vip.c b/drivers/staging/media/tegra-video/vip.c
index 80cd3b113125..148c68ceb605 100644
--- a/drivers/staging/media/tegra-video/vip.c
+++ b/drivers/staging/media/tegra-video/vip.c
@@ -236,6 +236,8 @@ static int tegra_vip_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	vip->soc = of_device_get_match_data(&pdev->dev);
+	if (!vip->soc)
+		return -ENODEV;
 
 	vip->dev = &pdev->dev;
 	platform_set_drvdata(pdev, vip);
-- 
2.53.0


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

* Re: [PATCH 1/5] staging: media: tegra-video: add NULL checks for of_device_get_match_data()
  2026-04-12 20:50 [PATCH 1/5] staging: media: tegra-video: add NULL checks for of_device_get_match_data() Alexandru Hossu
@ 2026-04-13  3:07 ` Mikko Perttunen
  2026-04-13  5:21 ` Alexandru Hossu
  1 sibling, 0 replies; 3+ messages in thread
From: Mikko Perttunen @ 2026-04-13  3:07 UTC (permalink / raw)
  To: linux-media, linux-tegra, Alexandru Hossu
  Cc: thierry.reding, jonathanh, skomatineni, luca.ceresoli, mchehab,
	gregkh, linux-staging, linux-kernel, Alexandru Hossu

On Monday, April 13, 2026 5:50 AM Alexandru Hossu wrote:
> tegra_csi_probe(), tegra_vi_probe(), and tegra_vip_probe() all call
> of_device_get_match_data() to retrieve SoC-specific data from the device
> tree match table, but none of them check the return value for NULL before
> eventually dereferencing it.
> 
> In tegra_csi_probe(), the pointer is dereferenced on the very next
> statement via csi->soc->num_clks. In tegra_vi_probe(), it is dereferenced
> later via vi->soc->ops. In tegra_vip_probe(), vip->soc is stored and then
> dereferenced at runtime via vip->soc->ops->vip_start_streaming(). A NULL
> return would cause a kernel NULL pointer dereference in each case.
> 
> Add a NULL check returning -ENODEV in all three probe functions, consistent
> with the defensive pattern already used in similar staging drivers such as
> drivers/staging/media/sunxi/cedrus/cedrus_hw.c.
> 
> Signed-off-by: Alexandru Hossu <hossu.alexandru@gmail.com>
> ---
>  drivers/staging/media/tegra-video/csi.c | 2 ++
>  drivers/staging/media/tegra-video/vi.c  | 2 ++
>  drivers/staging/media/tegra-video/vip.c | 2 ++
>  3 files changed, 6 insertions(+)
> 
> diff --git a/drivers/staging/media/tegra-video/csi.c b/drivers/staging/media/tegra-video/csi.c
> index 7842104ca933..33369a8c803a 100644
> --- a/drivers/staging/media/tegra-video/csi.c
> +++ b/drivers/staging/media/tegra-video/csi.c
> @@ -781,6 +781,8 @@ static int tegra_csi_probe(struct platform_device *pdev)
>  		return PTR_ERR(csi->iomem);
>  
>  	csi->soc = of_device_get_match_data(&pdev->dev);
> +	if (!csi->soc)
> +		return -ENODEV;
>  
>  	csi->clks = devm_kcalloc(&pdev->dev, csi->soc->num_clks,
>  				 sizeof(*csi->clks), GFP_KERNEL);
> diff --git a/drivers/staging/media/tegra-video/vi.c b/drivers/staging/media/tegra-video/vi.c
> index d1d934e361f7..f3b749f059f8 100644
> --- a/drivers/staging/media/tegra-video/vi.c
> +++ b/drivers/staging/media/tegra-video/vi.c
> @@ -1907,6 +1907,8 @@ static int tegra_vi_probe(struct platform_device *pdev)
>  		return PTR_ERR(vi->iomem);
>  
>  	vi->soc = of_device_get_match_data(&pdev->dev);
> +	if (!vi->soc)
> +		return -ENODEV;
>  
>  	vi->clk = devm_clk_get(&pdev->dev, NULL);
>  	if (IS_ERR(vi->clk)) {
> diff --git a/drivers/staging/media/tegra-video/vip.c b/drivers/staging/media/tegra-video/vip.c
> index 80cd3b113125..148c68ceb605 100644
> --- a/drivers/staging/media/tegra-video/vip.c
> +++ b/drivers/staging/media/tegra-video/vip.c
> @@ -236,6 +236,8 @@ static int tegra_vip_probe(struct platform_device *pdev)
>  		return -ENOMEM;
>  
>  	vip->soc = of_device_get_match_data(&pdev->dev);
> +	if (!vip->soc)
> +		return -ENODEV;
>  
>  	vip->dev = &pdev->dev;
>  	platform_set_drvdata(pdev, vip);
> -- 
> 2.53.0
> 
> 

These devices are only probed through device tree, so we know the 
returned pointer is always non-NULL. Typically we don't check in such 
cases.

Thanks
Mikko



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

* Re: [PATCH 1/5] staging: media: tegra-video: add NULL checks for of_device_get_match_data()
  2026-04-12 20:50 [PATCH 1/5] staging: media: tegra-video: add NULL checks for of_device_get_match_data() Alexandru Hossu
  2026-04-13  3:07 ` Mikko Perttunen
@ 2026-04-13  5:21 ` Alexandru Hossu
  1 sibling, 0 replies; 3+ messages in thread
From: Alexandru Hossu @ 2026-04-13  5:21 UTC (permalink / raw)
  To: Mikko Perttunen
  Cc: linux-media, linux-tegra, thierry.reding, jonathanh, skomatineni,
	luca.ceresoli, mchehab, gregkh, linux-staging, linux-kernel

On Mon, Apr 13, 2026 at 05:07 AM, Mikko Perttunen wrote:
> These devices are only probed through device tree, so we know the
> returned pointer is always non-NULL. Typically we don't check in such
> cases.

Thanks for the explanation, will drop this patch.

Alexandru

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

end of thread, other threads:[~2026-04-13  5:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-12 20:50 [PATCH 1/5] staging: media: tegra-video: add NULL checks for of_device_get_match_data() Alexandru Hossu
2026-04-13  3:07 ` Mikko Perttunen
2026-04-13  5:21 ` Alexandru Hossu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox