From: Marc Kleine-Budde <mkl@pengutronix.de>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, linux-can@vger.kernel.org,
kernel@pengutronix.de,
Lucas Martins Alves <lucas.alves@lumal21.com.br>,
stable@kernel.org, Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [PATCH net 17/20] can: c_can: c_can_chip_config(): keep controller in init mode until bittiming is configured
Date: Wed, 29 Jul 2026 12:12:57 +0200 [thread overview]
Message-ID: <20260729102802.505168-18-mkl@pengutronix.de> (raw)
In-Reply-To: <20260729102802.505168-1-mkl@pengutronix.de>
From: Lucas Martins Alves <lucas.alves@lumal21.com.br>
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.
That creates a short timing window where the peripheral can interact with
the bus using a different/default bitrate, potentially generating bus
errors and corrupting traffic.
Set CONTROL_INIT together with the control-mode writes in
c_can_chip_config() (normal, loopback and listen-only paths), so the
controller stays halted until bit timing is fully programmed.
This prevents transient bus disturbance during startup when the configured
bitrate differs from the active bus bitrate.
Signed-off-by: Lucas Martins Alves <lucas.alves@lumal21.com.br>
Link: https://patch.msgid.link/20260714164839.771123-1-lucas.alves@lumal21.com.br
Fixes: 881ff67ad450 ("can: c_can: Added support for Bosch C_CAN controller")
Cc: stable@kernel.org
[mkl: remove space before close parenthesis]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/c_can/c_can_main.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/net/can/c_can/c_can_main.c b/drivers/net/can/c_can/c_can_main.c
index 3702cac7fbf0..b3b321d9ce68 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)
return err;
/* enable automatic retransmission */
- priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_ENABLE_AR);
+ priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_ENABLE_AR | CONTROL_INIT);
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) {
/* 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);
} else if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) {
/* silent mode : bus-monitoring mode */
- 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_SILENT);
}
--
2.53.0
next prev parent reply other threads:[~2026-07-29 10:29 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 10:12 [PATCH net 0/20] pull-request: can 2026-07-29 Marc Kleine-Budde
2026-07-29 10:12 ` [PATCH net 01/20] can: j1939: use netdevice_tracker for j1939_{priv,session,ecu} tracking Marc Kleine-Budde
2026-07-29 10:12 ` [PATCH net 02/20] can: j1939: transport: j1939_session_fresh_new(): initialize receive buffer Marc Kleine-Budde
2026-07-29 10:12 ` [PATCH net 03/20] can: isotp: fix timer drain order, wakeup handling and tx_gen ordering Marc Kleine-Budde
2026-07-29 10:12 ` [PATCH net 04/20] can: isotp: check register_netdevice_notifier() error in module init Marc Kleine-Budde
2026-07-29 10:12 ` [PATCH net 05/20] can: ctucanfd: unmap BAR0 using base address Marc Kleine-Budde
2026-07-29 10:12 ` [PATCH net 06/20] can: ctucanfd: mark error-active controller status valid Marc Kleine-Budde
2026-07-29 10:12 ` [PATCH net 07/20] can: ctucanfd: handle bus error interrupts Marc Kleine-Budde
2026-07-29 10:12 ` [PATCH net 08/20] can: ctucanfd: use self-test mode for PRESUME_ACK Marc Kleine-Budde
2026-07-29 10:12 ` [PATCH net 09/20] can: ctucanfd: add missing MODULE_DEVICE_TABLE() Marc Kleine-Budde
2026-07-29 10:12 ` [PATCH net 10/20] can: peak_usb: add bounds check for USB channel index Marc Kleine-Budde
2026-07-29 10:12 ` [PATCH net 11/20] can: peak_usb: peak_usb_start(): fix double free of transfer buffer on URB submit error Marc Kleine-Budde
2026-07-29 10:12 ` [PATCH net 12/20] can: peak_usb: validate uCAN receive record lengths Marc Kleine-Budde
2026-07-29 10:12 ` [PATCH net 13/20] can: kvaser_usb: kvaser_usb_hydra_get_busparams(): fix memory leak in kvaser_usb_hydra_get_busparams() Marc Kleine-Budde
2026-07-29 10:12 ` [PATCH net 14/20] can: kvaser_usb_leaf: kvaser_usb_leaf_wait_cmd(): validate received command extents Marc Kleine-Budde
2026-07-29 10:12 ` [PATCH net 15/20] can: rcar_canfd: change the initializing flow for clocks and resets Marc Kleine-Budde
2026-07-29 10:12 ` [PATCH net 16/20] can: softing: fw_parse(): validate firmware record spans Marc Kleine-Budde
2026-07-29 10:12 ` Marc Kleine-Budde [this message]
2026-07-29 10:12 ` [PATCH net 18/20] can: gs_usb: gs_usb_receive_bulk_callback(): resubmit URB on skb allocation failure Marc Kleine-Budde
2026-07-29 10:12 ` [PATCH net 19/20] can: etas_es58x: es58x_read_bulk_callback(): fix RX buffer leak on URB resubmit failure Marc Kleine-Budde
2026-07-29 10:13 ` [PATCH net 20/20] can: ems_usb: validate CPC message lengths Marc Kleine-Budde
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=20260729102802.505168-18-mkl@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=davem@davemloft.net \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=lucas.alves@lumal21.com.br \
--cc=netdev@vger.kernel.org \
--cc=stable@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox