Linux CAN drivers development
 help / color / mirror / Atom feed
* [PATCH] can: sja1000: drop RX frame when skb allocation fails
@ 2026-09-03  9:54 Yun Lu
  2026-09-03 10:04 ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: Yun Lu @ 2026-09-03  9:54 UTC (permalink / raw)
  To: mkl, mailhol, m.tretter, pkshih, tmuehlbacher, socketcan
  Cc: enelsonmoore, davem, wg, linux-can

From: Yun Lu <luyun@kylinos.cn>

When alloc_can_skb() fails, sja1000_rx() returns without reading
the frame and without releasing the receive buffer (CMD_RRB), so
SR_RBS stays set. The interrupt handler's inner RX loop

	while (status & SR_RBS) {
		sja1000_rx(dev);
		status = priv->read_reg(priv, SJA1000_SR);
		/* check for absent controller */
		if (status == 0xFF && sja1000_is_absent(priv))
			goto out;
	}

has no iteration limit, so under sustained memory pressure every
retry fails the same way and the loop never exits, livelocking the
CPU in hard IRQ context until the hard lockup detector fires.

Release the receive buffer and count the drop instead, as other
CAN drivers do on allocation failure, so the interrupt handler
always makes progress.

Fixes: 429da1cc841b ("can: Driver for the SJA1000 CAN controller")
Signed-off-by: Yun Lu <luyun@kylinos.cn>
---
 drivers/net/can/sja1000/sja1000.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/sja1000/sja1000.c b/drivers/net/can/sja1000/sja1000.c
index 3cdb583ee3e5..da107feb22af 100644
--- a/drivers/net/can/sja1000/sja1000.c
+++ b/drivers/net/can/sja1000/sja1000.c
@@ -348,8 +348,12 @@ static void sja1000_rx(struct net_device *dev)
 
 	/* create zero'ed CAN frame buffer */
 	skb = alloc_can_skb(dev, &cf);
-	if (skb == NULL)
+	if (!skb) {
+		/* drop the frame to guarantee forward progress of the ISR */
+		sja1000_write_cmdreg(priv, CMD_RRB);
+		stats->rx_dropped++;
 		return;
+	}
 
 	fi = priv->read_reg(priv, SJA1000_FI);
 
-- 
2.43.0


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

end of thread, other threads:[~2026-09-04  8:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-03  9:54 [PATCH] can: sja1000: drop RX frame when skb allocation fails Yun Lu
2026-09-03 10:04 ` sashiko-bot
2026-09-04  8:04   ` luyun

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