Netdev List
 help / color / mirror / Atom feed
From: Yun Lu <luyun_611@163.com>
To: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com
Cc: netdev@vger.kernel.org
Subject: [PATCH 02/13] 8139cp: handle cp_init_rings() failure in cp_tx_timeout()
Date: Fri, 17 Jul 2026 18:37:24 +0800	[thread overview]
Message-ID: <20260717103724.13971-3-luyun_611@163.com> (raw)
In-Reply-To: <20260717103724.13971-1-luyun_611@163.com>

From: Yun Lu <luyun@kylinos.cn>

cp_tx_timeout() ignores the return value of cp_init_rings(). If the
RX buffer refill fails there, cp_clean_rings() has already dropped
all rx_skb entries, yet the driver restarts the hardware and
schedules NAPI unconditionally. cp_rx_poll() then dereferences a
NULL rx_skb slot and hits BUG_ON(!skb), crashing the kernel; the RX
ring also stays empty until the next close/open cycle.

On refill failure, keep the queue stopped and leave the device down
until the next open instead of restarting into a guaranteed BUG.

Fixes: 9030c0d24dbb ("8139cp: implement the missing dev->tx_timeout")
Signed-off-by: Yun Lu <luyun@kylinos.cn>
---
 drivers/net/ethernet/realtek/8139cp.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/realtek/8139cp.c b/drivers/net/ethernet/realtek/8139cp.c
index 03929bb0bd79..968bc0a2086e 100644
--- a/drivers/net/ethernet/realtek/8139cp.c
+++ b/drivers/net/ethernet/realtek/8139cp.c
@@ -1273,7 +1273,13 @@ static void cp_tx_timeout(struct net_device *dev, unsigned int txqueue)
 
 	cp_stop_hw(cp);
 	cp_clean_rings(cp);
-	cp_init_rings(cp);
+	if (cp_init_rings(cp)) {
+		netif_err(cp, tx_err, dev,
+			  "Failed to allocate RX buffers, not restarting\n");
+		netif_stop_queue(dev);
+		spin_unlock_irqrestore(&cp->lock, flags);
+		return;
+	}
 	cp_start_hw(cp);
 	__cp_set_rx_mode(dev);
 	cpw16_f(IntrMask, cp_norx_intr_mask);
-- 
2.25.1


      parent reply	other threads:[~2026-07-17 10:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17 10:37 [PATCH net 0/2] 8139cp: fix two TX error handling bugs Yun Lu
2026-07-17 10:37 ` [PATCH 01/13] 8139cp: fix DMA mapping unwind on TX frag map failure Yun Lu
2026-07-22  7:37   ` luyun
2026-07-22 19:43     ` Jakub Kicinski
2026-07-23  1:57       ` luyun
2026-07-23 13:32         ` Jakub Kicinski
2026-07-17 10:37 ` Yun Lu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260717103724.13971-3-luyun_611@163.com \
    --to=luyun_611@163.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox