Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

can: flexcan: flexcan_chip_freeze(): 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.

Fixes: ec15e27cc890 ("can: flexcan: enable RX FIFO after FRZ/HALT valid")
Link: https://lore.kernel.org/r/20210315231510.650593-1-angelo@kernel-space.org
Signed-off-by: Angelo Dureghello <angelo@kernel-space.org>
[mkl: use if instead of ? operator]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

authored by

Angelo Dureghello and committed by
Marc Kleine-Budde
47c5e474 59ec7b89

+7 -1
+7 -1
drivers/net/can/flexcan.c
··· 697 697 static int flexcan_chip_freeze(struct flexcan_priv *priv) 698 698 { 699 699 struct flexcan_regs __iomem *regs = priv->regs; 700 - unsigned int timeout = 1000 * 1000 * 10 / priv->can.bittiming.bitrate; 700 + unsigned int timeout; 701 + u32 bitrate = priv->can.bittiming.bitrate; 701 702 u32 reg; 703 + 704 + if (bitrate) 705 + timeout = 1000 * 1000 * 10 / bitrate; 706 + else 707 + timeout = FLEXCAN_TIMEOUT_US / 10; 702 708 703 709 reg = priv->read(&regs->mcr); 704 710 reg |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT;