Linux CAN drivers development
 help / color / mirror / Atom feed
* [PATCH RFC] can: m_can: m_can_tx_work_queue(): fix tx_skb race condition
@ 2021-05-05 11:43 Marc Kleine-Budde
  2021-05-05 12:06 ` Torin Cooper-Bennun
  0 siblings, 1 reply; 5+ messages in thread
From: Marc Kleine-Budde @ 2021-05-05 11:43 UTC (permalink / raw)
  To: linux-can; +Cc: Marc Kleine-Budde

The m_can_start_xmit() function checks if the cdev->tx_skb is NULL and
returns with NETDEV_TX_BUSY in case tx_sbk is not NULL.

There is a race condition in the m_can_tx_work_queue(), where first
the skb is send to the driver and then the case tx_sbk is set to NULL.
A TX complete IRQ might come in between and wake the queue, which
results in tx_skb not being cleared yet.

Fixes: f524f829b75a ("can: m_can: Create a m_can platform framework")
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
Hello,

compile time tested only.

Marc

 drivers/net/can/m_can/m_can.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 2fa10bc0befe..bba2a449ac70 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -1544,6 +1544,8 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev)
 	int i;
 	int putidx;
 
+	cdev->tx_skb = NULL;
+
 	/* Generate ID field for TX buffer Element */
 	/* Common to all supported M_CAN versions */
 	if (cf->can_id & CAN_EFF_FLAG) {
@@ -1660,7 +1662,6 @@ static void m_can_tx_work_queue(struct work_struct *ws)
 						   tx_work);
 
 	m_can_tx_handler(cdev);
-	cdev->tx_skb = NULL;
 }
 
 static netdev_tx_t m_can_start_xmit(struct sk_buff *skb,
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-05-05 12:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-05 11:43 [PATCH RFC] can: m_can: m_can_tx_work_queue(): fix tx_skb race condition Marc Kleine-Budde
2021-05-05 12:06 ` Torin Cooper-Bennun
2021-05-05 12:35   ` Marc Kleine-Budde
2021-05-05 12:46     ` Torin Cooper-Bennun
2021-05-05 12:50       ` Marc Kleine-Budde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox