All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@baylibre.com>
To: Pengpeng Hou <pengpeng@iscas.ac.cn>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>,
	 Vincent Mailhol <mailhol@kernel.org>,
	Rob Herring <robh@kernel.org>,
	linux-can@vger.kernel.org,  linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v2] can: c_can: Use platform id data when OF data is absent
Date: Tue, 30 Jun 2026 18:43:43 +0200	[thread overview]
Message-ID: <akPwf-nq2vTAlITA@monoceros> (raw)
In-Reply-To: <20260625054152.68413-1-pengpeng@iscas.ac.cn>

[-- Attachment #1: Type: text/plain, Size: 2246 bytes --]

Hello,

On Thu, Jun 25, 2026 at 01:41:52PM +0800, 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.
> 
> Fixes: 5e6c3454b405 ("net: can: Use device_get_match_data()")
> Cc: stable@vger.kernel.org
> Reviewed-by: Vincent Mailhol <mailhol@kernel.org>
> Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
> ---
> Changes in v2:
> - Add the Fixes tag requested by Vincent.
> - Scope the platform id variable inside the fallback block.
> - Carry Vincent's Reviewed-by for the requested v2 shape.
> 
>  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..8a0c88839d24 100644
> --- a/drivers/net/can/c_can/c_can_platform.c
> +++ b/drivers/net/can/c_can/c_can_platform.c
> @@ -267,6 +267,14 @@ static int c_can_plat_probe(struct platform_device *pdev)
>  	struct device_node *np = pdev->dev.of_node;
>  
>  	drvdata = device_get_match_data(&pdev->dev);
> +	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;
> +	}

Given that there are no devices probed via the platform_driver's
id_table (or my grep misses it:

	$ git grep -E '"(c_can_platform|c_can|d_can)"'
	drivers/net/can/c_can/c_can_platform.c:         .name = "c_can",
	drivers/net/can/c_can/c_can_platform.c:         .name = "d_can",
)

just do:

	if (!drvdata)
		return -ENODEV;

and drop c_can_id_table[].

An error message would be nice, but the other error exits don't have one
either.

Unless I missed something a backport to stable isn't needed then,
either.

Best regards
Uwe

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

      parent reply	other threads:[~2026-06-30 16:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-24  5:49 [PATCH] can: c_can: Use platform id data when OF data is absent Pengpeng Hou
2026-06-24  9:53 ` Vincent Mailhol
2026-06-24 18:22   ` Vincent Mailhol
2026-06-25  5:41 ` [PATCH v2] " Pengpeng Hou
2026-06-25  5:50   ` sashiko-bot
2026-06-30 16:43   ` Uwe Kleine-König [this message]

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=akPwf-nq2vTAlITA@monoceros \
    --to=u.kleine-koenig@baylibre.com \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=pengpeng@iscas.ac.cn \
    --cc=robh@kernel.org \
    --cc=stable@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.