Skip to contentSkip to conversation

can: flexcan: fix chip freeze for missing bitrate

PATCH In review Angelo Dureghello 2 participants 2 messages Mar 15, 2021 – Mar 16, 2021 CAN network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 can: flexcan: fix chip freeze for missing bitrate

For cases when flexcan is built-in, bitrate is still not set at registering. So flexcan_chip_freeze() generates:

[    1.860000] *** ZERO DIVIDE ***   FORMAT=4
[    1.860000] Current process id is 1
[    1.860000] BAD KERNEL TRAP: 00000000
[    1.860000] PC: [<402e70c8>] flexcan_chip_freeze+0x1a/0xa8

To allow chip freeze, using an hardcoded timeout when bitrate is still not set.

---
 drivers/net/can/flexcan.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/can/flexcan.c +5 -1
index 134c05757a3b..bb41ff3d2d1e 100644
@@ -697,9 +697,13 @@ static int flexcan_chip_disable(struct flexcan_priv *priv)
 static int flexcan_chip_freeze(struct flexcan_priv *priv)
 {
 	struct flexcan_regs __iomem *regs = priv->regs;
-	unsigned int timeout = 1000 * 1000 * 10 / priv->can.bittiming.bitrate;
+	unsigned int timeout;
+	u32 bitrate = priv->can.bittiming.bitrate;
 	u32 reg;
 
+	timeout = bitrate ? 1000 * 1000 * 10 / bitrate :
+			FLEXCAN_TIMEOUT_US / 10;
+
 	reg = priv->read(&regs->mcr);
 	reg |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT;
 	priv->write(reg, &regs->mcr);
Signature · 1 line
2.30.1
#1 lore raw
Quoted 8 lines · Angelo Dureghello

For cases when flexcan is built-in, bitrate is still not set at registering. So flexcan_chip_freeze() generates:

[    1.860000] *** ZERO DIVIDE ***   FORMAT=4
[    1.860000] Current process id is 1
[    1.860000] BAD KERNEL TRAP: 00000000
[    1.860000] PC: [<402e70c8>] flexcan_chip_freeze+0x1a/0xa8
Quoted 4 lines

To allow chip freeze, using an hardcoded timeout when bitrate is still not set.

Applied to linux-can/testing

Thanks,
Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |