Linux CAN drivers development
 help / color / mirror / Atom feed
From: Vincent Mailhol <mailhol@kernel.org>
To: Pengpeng Hou <pengpeng@iscas.ac.cn>,
	Marc Kleine-Budde <mkl@pengutronix.de>
Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] can: c_can: Use platform id data when OF data is absent
Date: Wed, 24 Jun 2026 20:22:03 +0200	[thread overview]
Message-ID: <12d20349-6e76-47a6-ab7d-e7429b50de35@kernel.org> (raw)
In-Reply-To: <76288461-98f7-4c72-9d97-3589d301cd9e@kernel.org>

On 24/06/2026 at 11:53, Vincent Mailhol wrote:
> 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.

Also, were you able to trigger that NULL pointer dereference?

> Fixes: 5e6c3454b405 ("net: can: Use device_get_match_data()")
> 
>> Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
>> ---
>>  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@kernel.org>


Yours sincerely,
Vincent Mailhol


  reply	other threads:[~2026-06-24 18:22 UTC|newest]

Thread overview: 5+ 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 [this message]
2026-06-25  5:41 ` [PATCH v2] " Pengpeng Hou
2026-06-25  5:50   ` sashiko-bot

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=12d20349-6e76-47a6-ab7d-e7429b50de35@kernel.org \
    --to=mailhol@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=pengpeng@iscas.ac.cn \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox