mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] tg3: Fix peer device double put in tg3_find_peer()
@ 2026-09-17 10:51 Wentao Liang
  2026-09-20  9:25 ` Simon Horman
  0 siblings, 1 reply; 2+ messages in thread
From: Wentao Liang @ 2026-09-17 10:51 UTC (permalink / raw)
  To: andrew+netdev
  Cc: davem, edumazet, kuba, linux-kernel, mchan, netdev, pabeni,
	pavan.chebbi, Wentao Liang, stable

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


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

* Re: [PATCH] tg3: Fix peer device double put in tg3_find_peer()
  2026-09-17 10:51 [PATCH] tg3: Fix peer device double put in tg3_find_peer() Wentao Liang
@ 2026-09-20  9:25 ` Simon Horman
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2026-09-20  9:25 UTC (permalink / raw)
  To: Wentao Liang
  Cc: andrew+netdev, davem, edumazet, kuba, linux-kernel, mchan,
	netdev, pabeni, pavan.chebbi, stable

On Thu, Sep 17, 2026 at 10:51:04AM +0000, Wentao Liang wrote:
> 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>

Hi,

I agree with your analysis of the logic.
But I wonder if it can occur in practice:
can such a device actually be presented to the Kernel?

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

end of thread, other threads:[~2026-09-20  9:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-17 10:51 [PATCH] tg3: Fix peer device double put in tg3_find_peer() Wentao Liang
2026-09-20  9:25 ` Simon Horman

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

all inboxes | Powered by JetHome®