Re: [PATCH can 2/4] can: flexcan: flexcan_probe(): fix probing for m68k/coldfire and reject devices without match data
From: Uwe Kleine-König
Date: Mon Nov 16 2026 - 04:14:30 EST
Hello Marc,
On Sat, Nov 14, 2026 at 01:56:15PM +0100, Marc Kleine-Budde wrote:
> When determining the device details was reworked in commit 5e6c3454b405
> ("net: can: Use device_get_match_data()") there was no replacement for the
> previous handling of non-of instantiated devices via the device's id_entry
> which then results in a NULL pointer exception. The only in-tree provider
> of such a device is arch/m68k/coldfire/device.c.
>
> Restore retrieving the devtype_data via platform_get_device_id().
>
> Also a device bound through driver_override need not match an entry in
> of_match_table or id_table. In that case device_get_match_data() returns
> NULL, but flexcan_probe() dereferences the result.
>
> Reject devices without match data before continuing probe.
>
> Fixes: 5e6c3454b405 ("net: can: Use device_get_match_data()")
> Cc: stable@xxxxxxxxxxxxxxx
> Reported-by: Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxx>
> Closes: https://lore.kernel.org/all/20260618140147.142489-2-u.kleine-koenig@xxxxxxxxxxxx/
> Reported-by: Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx>
> Closes: https://lore.kernel.org/all/20260528-fluorescent-sage-ladybug-43261b-mkl@xxxxxxxxxxxxxx/
> Signed-off-by: Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx>
> ---
> drivers/net/can/flexcan/flexcan-core.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/net/can/flexcan/flexcan-core.c b/drivers/net/can/flexcan/flexcan-core.c
> index 86b40abe9e76..2bb9e4184eb5 100644
> --- a/drivers/net/can/flexcan/flexcan-core.c
> +++ b/drivers/net/can/flexcan/flexcan-core.c
> @@ -2148,6 +2148,11 @@ static int flexcan_probe(struct platform_device *pdev)
> return PTR_ERR(regs);
>
> devtype_data = device_get_match_data(&pdev->dev);
> + if (!devtype_data && platform_get_device_id(pdev))
> + devtype_data = (struct flexcan_devtype_data *)
> + platform_get_device_id(pdev)->driver_data;
> + if (!devtype_data)
> + return -ENODEV;
My stance is that the ability to bind an "unexpected" device via
driver_override is something that should be handled in the core, see
https://lore.kernel.org/all/0f7446324f6a0c8f0153d6532d92a6eeecd6a308.1790612298.git.u.kleine-koenig@xxxxxxxxxxxx/
for the latest patch to address this. I'll work on this patch to
hopefully get it into v7.5-rc1. IMHO it's ok to not fix this in a driver
specific way now. (And then my patch referenced above in the first
Closes:-trailer is IMHO better than this patch.)
Best regards
Uwe
Attachment:
signature.asc
Description: PGP signature