Re: [PATCH] can: c_can: Use platform id data when OF data is absent
From: Vincent Mailhol
Date: Wed Jun 24 2026 - 05:57:04 EST
On 24/06/2026 at 07:49, Pengpeng Hou wrote:
> The platform driver keeps controller metadata in both the OF match table
> and the platform id table. Probe reads the metadata with
> device_get_match_data(), which does not fall back to platform id-table
> driver_data.
>
> When the device is matched through the platform id table, drvdata can
> therefore be NULL before it is dereferenced for msg_obj_num and the
> controller type. Fall back to platform_get_device_id() when firmware
> match data is not available.
So, you are telling me that this patch fixes a NULL pointer
dereference? In that case, it needs to be backported. Please add a
Fixes: tag.
Fixes: 5e6c3454b405 ("net: can: Use device_get_match_data()")
> Signed-off-by: Pengpeng Hou <pengpeng@xxxxxxxxxxx>
> ---
> drivers/net/can/c_can/c_can_platform.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/drivers/net/can/c_can/c_can_platform.c b/drivers/net/can/c_can/c_can_platform.c
> index 19c86b94a40e..564c9e5b4c2c 100644
> --- a/drivers/net/can/c_can/c_can_platform.c
> +++ b/drivers/net/can/c_can/c_can_platform.c
> @@ -263,9 +263,17 @@ static int c_can_plat_probe(struct platform_device *pdev)
> int irq;
> struct clk *clk;
> const struct c_can_driver_data *drvdata;
> + const struct platform_device_id *id;
> struct device_node *np = pdev->dev.of_node;
>
> drvdata = device_get_match_data(&pdev->dev);
> + if (!drvdata) {
> + id = platform_get_device_id(pdev);
> + if (!id)
> + return -ENODEV;
> +
> + drvdata = (const struct c_can_driver_data *)id->driver_data;
> + }
Reduce the visibility of id:
if (!drvdata) {
const struct platform_device_id *id;
id = platform_get_device_id(pdev);
if (!id)
return -ENODEV;
drvdata = (const struct c_can_driver_data *)id->driver_data;
}
>
> /* get the appropriate clk */
> clk = devm_clk_get(&pdev->dev, NULL);
With the Fixes: tag added and above nitpick addressed:
Reviewed-by: Vincent Mailhol <mailhol@xxxxxxxxxx>
Yours sincerely,
Vincent Mailhol