From: sashiko-bot@kernel.org
To: "Lucas Martins Alves" <lucas.alves@lumal21.com.br>
Cc: linux-can@vger.kernel.org,
"Oleksij Rempel" <o.rempel@pengutronix.de>,
"Vincent Mailhol" <mailhol@kernel.org>,
"Marc Kleine-Budde" <mkl@pengutronix.de>,
"Oliver Hartkopp" <socketcan@hartkopp.net>
Subject: Re: [PATCH] can: c_can: keep controller in init mode until bittiming is configured
Date: Tue, 14 Jul 2026 16:58:42 +0000 [thread overview]
Message-ID: <20260714165842.923281F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260714164839.771123-1-lucas.alves@lumal21.com.br>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Configuring bit timing temporarily clears the CONTROL_TEST bit, which silently resets the TEST register and breaks loopback/listen-only modes.
--
--- Patch [1]: [PATCH] can: c_can: keep controller in init mode until bittiming is configured ---
commit b7bd06d474febb092c757ff6270ed7de9b22644e
Author: Lucas Martins Alves <lucas.alves@lumal21.com.br>
can: c_can: keep controller in init mode until bittiming is configured
c_can_chip_config() was programming C_CAN_CTRL_REG without CONTROL_INIT,
which may allow the controller to become active before c_can_set_bittiming()
finishes. This patch adds CONTROL_INIT to the writes in c_can_chip_config()
so the controller stays halted until bit timing is fully programmed.
> diff --git a/drivers/net/can/c_can/c_can_main.c b/drivers/net/can/c_can/c_can_main.c
> index 3702cac7fbf0f..32a3975b9d692 100644
> --- a/drivers/net/can/c_can/c_can_main.c
> +++ b/drivers/net/can/c_can/c_can_main.c
> @@ -597,20 +597,20 @@ static int c_can_chip_config(struct net_device *dev)
[ ... ]
> if ((priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) &&
> (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK)) {
> /* loopback + silent mode : useful for hot self-test */
> - priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_TEST);
> + priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_TEST | CONTROL_INIT);
> priv->write_reg(priv, C_CAN_TEST_REG, TEST_LBACK | TEST_SILENT);
> } else if (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK) {
[Severity: High]
This is a pre-existing issue, but does the loopback or listen-only test mode
actually survive the initialization process?
When we configure C_CAN_TEST_REG here in c_can_chip_config(), we set the test
bits. However, shortly after this block, the function calls
c_can_set_bittiming() to configure the timing:
drivers/net/can/c_can/c_can_main.c:c_can_set_bittiming() {
...
ctrl_save = priv->read_reg(priv, C_CAN_CTRL_REG);
ctrl_save &= ~CONTROL_INIT;
priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_CCE | CONTROL_INIT);
...
priv->write_reg(priv, C_CAN_CTRL_REG, ctrl_save);
}
When writing CONTROL_CCE | CONTROL_INIT to the control register, the
CONTROL_TEST bit is explicitly omitted. Doesn't clearing the CONTROL_TEST bit
silently reset the C_CAN_TEST_REG back to 0 in the hardware, destroying the
configuration we just set?
Even though ctrl_save eventually restores the CONTROL_TEST bit in
C_CAN_CTRL_REG, the configuration in C_CAN_TEST_REG appears permanently lost.
Should c_can_set_bittiming() preserve the CONTROL_TEST bit when writing to
C_CAN_CTRL_REG?
> /* loopback mode : useful for self-test function */
> - priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_TEST);
> + priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_TEST | CONTROL_INIT);
> priv->write_reg(priv, C_CAN_TEST_REG, TEST_LBACK);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260714164839.771123-1-lucas.alves@lumal21.com.br?part=1
prev parent reply other threads:[~2026-07-14 16:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 16:48 [PATCH] can: c_can: keep controller in init mode until bittiming is configured Lucas Martins Alves
2026-07-14 16:58 ` sashiko-bot [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=20260714165842.923281F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=lucas.alves@lumal21.com.br \
--cc=mailhol@kernel.org \
--cc=mkl@pengutronix.de \
--cc=o.rempel@pengutronix.de \
--cc=sashiko-reviews@lists.linux.dev \
--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