tg3: Fix peer device double put in tg3_find_peer()
PATCH 1/1 tg3: Fix peer device double put in tg3_find_peer()
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.
--- drivers/net/ethernet/broadcom/tg3.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/broadcom/tg3.c +3 -2
@@ -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; }
Signature · 1 line
2.34.1
Simon Horman
reviewerQuoted 6 lines · Wentao Liang
pci_get_slot()returns a device with its reference count incremented. When the loop ends ontp->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 trailingpci_dev_put()drops it a second time, underflowing the refcount oftp->pdev.
Quoted 6 lines
Treat a loop end on
tp->pdevas single-port mode, just like the existing !peer case.Fixes 16fe9d74f14e ("[TG3]: Fix 5704 single-port mode")Signed-off-by Wentao Liang <[email protected]>
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?