Linux CAN drivers development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sean Nyekjaer" <sean@geanix.com>
Cc: "Oliver Hartkopp" <socketcan@hartkopp.net>,
	"Vincent Mailhol" <mailhol@kernel.org>,
	"Oleksij Rempel" <o.rempel@pengutronix.de>,
	linux-can@vger.kernel.org,
	"Marc Kleine-Budde" <mkl@pengutronix.de>
Subject: Re: [PATCH v2] can: tcan4x5x: put tcan into sleep when removing driver
Date: Mon, 03 Aug 2026 10:33:19 +0000	[thread overview]
Message-ID: <20260803103319.E155A1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260803101927.17122-1-sean@geanix.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [High] The function signature of `tcan4x5x_power_enable()` was changed to accept a `struct tcan4x5x_priv *` instead of `struct regulator *`, but the call site in `tcan4x5x_can_remove()` was not updated. This causes a severe type mismatch leading to a wild pointer dereference.
- [Medium] The transceiver is not explicitly put into sleep mode via SPI during driver removal if it is powered by a regulator, undermining the patch's intended power savings.

Pre-existing issues:
- [High] The polling hrtimer is not synchronously cancelled during device teardown, allowing its callback to execute concurrently on freed memory.
--

--- Patch [1]: [PATCH v2] can: tcan4x5x: put tcan into sleep when removing driver ---
commit b49d2b844c12ed05e9ff4437bc458dbace9b23e8
Author: Sean Nyekjaer <sean@geanix.com>

can: tcan4x5x: put tcan into sleep when removing driver

Put the tcan4x5x transceiver into sleep mode when the driver is
removed, instead of leaving it in its current operating mode.
This reduces power consumption(3mA@12V) once the driver is
no longer bound to the device.

> diff --git a/drivers/net/can/m_can/tcan4x5x-core.c b/drivers/net/can/m_can/tcan4x5x-core.c
> index 31cc9d0abd453..67902b8b0fab4 100644
> --- a/drivers/net/can/m_can/tcan4x5x-core.c
> +++ b/drivers/net/can/m_can/tcan4x5x-core.c
> @@ -211,15 +211,21 @@ static int tcan4x5x_write_fifo(struct m_can_classdev *cdev,
>  	return regmap_bulk_write(priv->regmap, TCAN4X5X_MRAM_START + addr_offset, val, val_count);
>  }
>  
> -static int tcan4x5x_power_enable(struct regulator *reg, int enable)
> +static int tcan4x5x_power_enable(struct tcan4x5x_priv *priv, int enable)
>  {

[Severity: High]
Did this signature change miss updating the call site in
tcan4x5x_can_remove()?

When the driver is unloaded, tcan4x5x_can_remove() still passes priv->power
which is a struct regulator pointer:

drivers/net/can/m_can/tcan4x5x-core.c:tcan4x5x_can_remove() {
	...
	tcan4x5x_power_enable(priv->power, 0);
	...
}

Could this cause a panic when tcan4x5x_power_enable() tries to dereference
the regulator pointer as a struct tcan4x5x_priv?

> -	if (IS_ERR_OR_NULL(reg))
> +	if (IS_ERR_OR_NULL(priv->power)) {
> +		if (priv->reset_gpio && !enable)
> +			return regmap_update_bits(priv->regmap, TCAN4X5X_CONFIG,
> +						  TCAN4X5X_MODE_SEL_MASK,
> +						  TCAN4X5X_MODE_SLEEP);
> +
>  		return 0;
> +	}

[Severity: Medium]
If the device tree specifies a regulator for the transceiver, will this
skip putting the device into sleep mode?

Since the sleep configuration is gated inside the check for
IS_ERR_OR_NULL(priv->power), if a regulator is present, the function skips
this block and just disables the regulator.

If this regulator is shared with other components on the board, does it leave
the transceiver powered and in its previous state instead of entering sleep
mode?

[ ... ]

[Severity: High]
This isn't a bug introduced by this patch, but is there a race condition
with the polling hrtimer during device teardown?

During device teardown, m_can_disable_all_interrupts() uses a non-blocking
cancel:

drivers/net/can/m_can/m_can.c:m_can_disable_all_interrupts() {
	...
	if (!cdev->net->irq) {
		netdev_dbg(cdev->net, "Stop hrtimer\n");
		hrtimer_try_to_cancel(&cdev->hrtimer);
	}
}

If the timer callback m_can_polling_timer() is concurrently running on another
CPU, hrtimer_try_to_cancel() will fail.

If the callback reads the state before it is updated to CAN_STATE_STOPPED,
will it reschedule itself and eventually execute on freed memory?

drivers/net/can/m_can/m_can.c:m_can_polling_timer() {
	...
	hrtimer_forward_now(timer, ms_to_ktime(HRTIMER_POLL_INTERVAL_MS));

	return HRTIMER_RESTART;
}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260803101927.17122-1-sean@geanix.com?part=1

  reply	other threads:[~2026-08-03 10:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03 10:19 [PATCH v2] can: tcan4x5x: put tcan into sleep when removing driver Sean Nyekjaer
2026-08-03 10:33 ` sashiko-bot [this message]
2026-08-03 11:00   ` Marc Kleine-Budde
2026-08-03 11:16   ` Sean Nyekjaer
2026-08-03 10:59 ` Marc Kleine-Budde
2026-08-03 11:32   ` Sean Nyekjaer

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=20260803103319.E155A1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=o.rempel@pengutronix.de \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sean@geanix.com \
    --cc=socketcan@hartkopp.net \
    /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