Re: [PATCH v1 1/6] pwm: tegra: Check for match_data being NULL

Mikko Perttunen <[email protected]> Wed, 15 Jul 2026 13:11:00 +0900
Newsgroups org.kernel.vger.linux-pwm,org.kernel.vger.linux-tegra
Message-ID <[email protected]>
On Tuesday, July 14, 2026 9:02 PM Uwe Kleine-König wrote:
> It's unlikely but not impossible that of_device_get_match_data() returns
> NULL. Handle this case instead of triggering a NULL pointer exception.
> 
> Signed-off-by: Uwe Kleine-König <[email protected]>
> ---
>  drivers/pwm/pwm-tegra.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/pwm/pwm-tegra.c b/drivers/pwm/pwm-tegra.c
> index 5cdbe120ba2d..53743f83869a 100644
> --- a/drivers/pwm/pwm-tegra.c
> +++ b/drivers/pwm/pwm-tegra.c
> @@ -322,6 +322,13 @@ static int tegra_pwm_probe(struct platform_device *pdev)
>  	int ret;
>  
>  	soc = of_device_get_match_data(&pdev->dev);
> +	if (!soc)

Very subjective, but my preference is to have curly braces whenever the
if block is more than one line, for clarity.

> +		/*
> +		 * This can only happen if pdev was matched via pdev->name
> +		 * (which should not happen today) or in combination with a
> +		 * driver override.
> +		 */

I feel like driver_override falls in the realm of 'root can mess with
the system as they feel like but if they don't know what they're doing
they get to keep the pieces'. So adding a check in every driver, or
in practice having a random mix of drivers with and without the check,
doesn't seem necessary to me.

If we actually want to check for this condition, could it be done
centrally instead? I.e. don't call probe if there's no match data and
the driver's match table implies it requires it.

> +		return dev_err_probe(dev, -ENODEV, "Unsupported device\n");

'dev' is not defined (yet).

Thank you
Mikko

>  
>  	chip = devm_pwmchip_alloc(&pdev->dev, soc->num_channels, sizeof(*pc));
>  	if (IS_ERR(chip))
> -- 
> 2.55.0.11.g153666a7d9bb
> 
>