Skip to content

Commit b93fb44

Browse files
Yang Yinglianganguy11
authored andcommitted
ixgbe: fix pci device refcount leak
As the comment of pci_get_domain_bus_and_slot() says, it returns a PCI device with refcount incremented, when finish using it, the caller must decrement the reference count by calling pci_dev_put(). In ixgbe_get_first_secondary_devfn() and ixgbe_x550em_a_has_mii(), pci_dev_put() is called to avoid leak. Fixes: 8fa10ef ("ixgbe: register a mdiobus") Signed-off-by: Yang Yingliang <[email protected]> Tested-by: Gurucharan G <[email protected]> (A Contingent worker at Intel) Signed-off-by: Tony Nguyen <[email protected]>
1 parent 53da7ae commit b93fb44

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -855,9 +855,11 @@ static struct pci_dev *ixgbe_get_first_secondary_devfn(unsigned int devfn)
855855
rp_pdev = pci_get_domain_bus_and_slot(0, 0, devfn);
856856
if (rp_pdev && rp_pdev->subordinate) {
857857
bus = rp_pdev->subordinate->number;
858+
pci_dev_put(rp_pdev);
858859
return pci_get_domain_bus_and_slot(0, bus, 0);
859860
}
860861

862+
pci_dev_put(rp_pdev);
861863
return NULL;
862864
}
863865

@@ -874,6 +876,7 @@ static bool ixgbe_x550em_a_has_mii(struct ixgbe_hw *hw)
874876
struct ixgbe_adapter *adapter = hw->back;
875877
struct pci_dev *pdev = adapter->pdev;
876878
struct pci_dev *func0_pdev;
879+
bool has_mii = false;
877880

878881
/* For the C3000 family of SoCs (x550em_a) the internal ixgbe devices
879882
* are always downstream of root ports @ 0000:00:16.0 & 0000:00:17.0
@@ -884,15 +887,16 @@ static bool ixgbe_x550em_a_has_mii(struct ixgbe_hw *hw)
884887
func0_pdev = ixgbe_get_first_secondary_devfn(PCI_DEVFN(0x16, 0));
885888
if (func0_pdev) {
886889
if (func0_pdev == pdev)
887-
return true;
888-
else
889-
return false;
890+
has_mii = true;
891+
goto out;
890892
}
891893
func0_pdev = ixgbe_get_first_secondary_devfn(PCI_DEVFN(0x17, 0));
892894
if (func0_pdev == pdev)
893-
return true;
895+
has_mii = true;
894896

895-
return false;
897+
out:
898+
pci_dev_put(func0_pdev);
899+
return has_mii;
896900
}
897901

898902
/**

0 commit comments

Comments
 (0)