public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
From: Mikko Perttunen <mperttunen@nvidia.com>
To: linux-media@vger.kernel.org, linux-tegra@vger.kernel.org,
	Alexandru Hossu <hossu.alexandru@gmail.com>
Cc: thierry.reding@gmail.com, jonathanh@nvidia.com,
	skomatineni@nvidia.com, luca.ceresoli@bootlin.com,
	mchehab@kernel.org, gregkh@linuxfoundation.org,
	linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
	Alexandru Hossu <hossu.alexandru@gmail.com>
Subject: Re: [PATCH 1/5] staging: media: tegra-video: add NULL checks for of_device_get_match_data()
Date: Mon, 13 Apr 2026 12:07:01 +0900	[thread overview]
Message-ID: <546FSeECSqm-ORhiEUYCVw@nvidia.com> (raw)
In-Reply-To: <20260412205057.386856-1-hossu.alexandru@gmail.com>

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



  reply	other threads:[~2026-04-13  3:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-04-13  5:21 ` Alexandru Hossu

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=546FSeECSqm-ORhiEUYCVw@nvidia.com \
    --to=mperttunen@nvidia.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hossu.alexandru@gmail.com \
    --cc=jonathanh@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=linux-tegra@vger.kernel.org \
    --cc=luca.ceresoli@bootlin.com \
    --cc=mchehab@kernel.org \
    --cc=skomatineni@nvidia.com \
    --cc=thierry.reding@gmail.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