From: Wentao Liang <vulab@iscas.ac.cn>
To: andrew+netdev@lunn.ch
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
linux-kernel@vger.kernel.org, mchan@broadcom.com,
netdev@vger.kernel.org, pabeni@redhat.com,
pavan.chebbi@broadcom.com, Wentao Liang <vulab@iscas.ac.cn>,
stable@vger.kernel.org
Subject: [PATCH] tg3: Fix peer device double put in tg3_find_peer()
Date: Thu, 17 Sep 2026 10:51:04 +0000 [thread overview]
Message-ID: <20260917105104.2147646-1-vulab@iscas.ac.cn> (raw)
pci_get_slot() returns a device with its reference count incremented.
When the loop ends on tp->pdev (which happens when the adapter sits at
PCI function 7 and no other function is present) that reference has
already been dropped inside the loop, but the trailing pci_dev_put()
drops it a second time, underflowing the refcount of tp->pdev.
Treat a loop end on tp->pdev as single-port mode, just like the
existing !peer case.
Fixes: 16fe9d74f14e ("[TG3]: Fix 5704 single-port mode")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
drivers/net/ethernet/broadcom/tg3.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index 73a4b569b03e..57669a22c036 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -16122,9 +16122,10 @@ static struct pci_dev *tg3_find_peer(struct tg3 *tp)
pci_dev_put(peer);
}
/* 5704 can be configured in single-port mode, set peer to
- * tp->pdev in that case.
+ * tp->pdev in that case. The loop can also end on tp->pdev
+ * itself, whose reference was already dropped above.
*/
- if (!peer) {
+ if (!peer || peer == tp->pdev) {
peer = tp->pdev;
return peer;
}
--
2.34.1
next reply other threads:[~2026-09-17 10:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 10:51 Wentao Liang [this message]
2026-09-20 9:25 ` [PATCH] tg3: Fix peer device double put in tg3_find_peer() Simon Horman
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=20260917105104.2147646-1-vulab@iscas.ac.cn \
--to=vulab@iscas.ac.cn \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mchan@broadcom.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pavan.chebbi@broadcom.com \
--cc=stable@vger.kernel.org \
/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