OSDN Git Service

can: mcp251xfd: mcp251xfd_handle_tefif(): fix TEF vs. TX race condition
authorMarc Kleine-Budde <mkl@pengutronix.de>
Tue, 5 Jan 2021 21:41:37 +0000 (22:41 +0100)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Thu, 7 Jan 2021 10:02:09 +0000 (11:02 +0100)
commit6086f02a18aeae795a61a3fc6566920891ea3b52
tree04f48e96a19969683435af85fc4115bb33c850b5
parentaee2b3ccc8a63d1cd7da6a8a153d1f3712d40826
can: mcp251xfd: mcp251xfd_handle_tefif(): fix TEF vs. TX race condition

The mcp251xfd driver uses a TX FIFO for sending CAN frames and a TX Event FIFO
(TEF) for completed TX-requests.

The TEF event handling in the mcp251xfd_handle_tefif() function has a race
condition. It first increments the tx-ring's tail counter to signal that
there's room in the TX and TEF FIFO, then it increments the TEF FIFO in
hardware.

A running mcp251xfd_start_xmit() on a different CPU might not stop the txqueue
(as the tx-ring still shows free space). The next mcp251xfd_start_xmit() will
push a message into the chip and the TX complete event might overflow the TEF
FIFO.

This patch changes the order to fix the problem.

Fixes: 68c0c1c7f966 ("can: mcp251xfd: tef-path: reduce number of SPI core requests to set UINC bit")
Link: https://lore.kernel.org/r/20210105214138.3150886-2-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c