ixgbe: fix pci device refcount leak
Subsystems (3)
PATCH RESEND 1/1 ixgbe: fix pci device refcount leak
As comment of pci_get_domain_bus_and_slot() says, it returns a pci device with refcount increment, 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.
---
Cc all pepole in the maintainer list.
--- drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c +4 -0
@@ -855,9 +855,11 @@ static struct pci_dev *ixgbe_get_first_secondary_devfn(unsigned int devfn) rp_pdev =pci_get_domain_bus_and_slot (0 ,0 , devfn);if (rp_pdev && rp_pdev->subordinate) { bus = rp_pdev->subordinate->number; +pci_dev_put (rp_pdev);return pci_get_domain_bus_and_slot (0 , bus,0 ); } +pci_dev_put (rp_pdev);return NULL ; }
@@ -882,6 +884,7 @@ static bool ixgbe_x550em_a_has_mii(struct ixgbe_hw *hw)* of those two root ports */ func0_pdev =ixgbe_get_first_secondary_devfn (PCI_DEVFN (0x16 ,0 )); +pci_dev_put (func0_pdev);if (func0_pdev) {if (func0_pdev == pdev)return true;
@@ -889,6 +892,7 @@ static bool ixgbe_x550em_a_has_mii(struct ixgbe_hw *hw)return false; } func0_pdev =ixgbe_get_first_secondary_devfn (PCI_DEVFN (0x17 ,0 )); +pci_dev_put (func0_pdev);if (func0_pdev == pdev)return true;
Signature · 1 line
2.25.1
Tony Nguyen
maintainerQuoted 11 lines · Yang Yingliang
As comment of
pci_get_domain_bus_and_slot()says, it returns a pci device with refcount increment, when finish using it, the caller must decrement the reference count by callingpci_dev_put().In
ixgbe_get_first_secondary_devfn()andixgbe_x550em_a_has_mii(),pci_dev_put()is called to avoid leak.Fixes 8fa10ef01260 ("ixgbe: register a mdiobus")Signed-off-by Yang Yingliang <[email protected]>---
<snip>
Quoted 9 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c +1
-0@@ -882,6 +884,7 @@ static bool ixgbe_x550em_a_has_mii(struct ixgbe_hw *hw)* of those two root ports */ func0_pdev =ixgbe_get_first_secondary_devfn (PCI_DEVFN (0x16 ,0 )); +pci_dev_put (func0_pdev);if (func0_pdev) {if (func0_pdev == pdev)return true;
drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c static bool ixgbe_x550em_a_has_mii(struct ixgbe_hw *hw) · line 897
Quoted 6 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c +1
-0@@ -889,6 +892,7 @@ static bool ixgbe_x550em_a_has_mii(struct ixgbe_hw *hw)return false; } func0_pdev =ixgbe_get_first_secondary_devfn (PCI_DEVFN (0x17 ,0 )); +pci_dev_put (func0_pdev);if (func0_pdev == pdev)return true;
It would probably be better to defer these puts until after the checks and values are set. I'd think some local vars and gotos may be cleaner than placing puts before all the returns.
Thanks,
Tony