Re: [PATCH v2 2/3] pwm: tegra: Check for match_data being NULL

From: Thierry Reding

Date: Mon Sep 21 2026 - 05:47:32 EST


On Fri, Sep 18, 2026 at 04:33:46PM +0200, 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 <u.kleine-koenig@xxxxxxxxxxxx>
> ---
> drivers/pwm/pwm-tegra.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/drivers/pwm/pwm-tegra.c b/drivers/pwm/pwm-tegra.c
> index efb7ab60f602..b461d3877f43 100644
> --- a/drivers/pwm/pwm-tegra.c
> +++ b/drivers/pwm/pwm-tegra.c
> @@ -323,6 +323,14 @@ static int tegra_pwm_probe(struct platform_device *pdev)
> int ret;
>
> soc = of_device_get_match_data(dev);
> + if (!soc) {
> + /*
> + * This can only happen if pdev was matched via pdev->name
> + * (which should not happen today) or in combination with a
> + * driver override.
> + */
> + return dev_err_probe(dev, -ENODEV, "Unsupported device\n");
> + }

We don't usually do this. Matching via anything other than OF device ID
tables (or ACPI, I suppose) is a programming error and you deserve the
crash which forces you to fix things rather than continue with an error
that is easy to miss.

Driver overrides aren't going to work with these devices anyway, so I'm
beginning to think it might be worth looking into opting out of the
override behaviour for select drivers.

Thierry

Attachment: signature.asc
Description: PGP signature