netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net resend] ixgbe: fix pci device refcount leak
@ 2022-11-19  6:41 Yang Yingliang
  2022-11-22  4:47 ` Jakub Kicinski
  0 siblings, 1 reply; 4+ messages in thread
From: Yang Yingliang @ 2022-11-19  6:41 UTC (permalink / raw)
  To: netdev; +Cc: jesse.brandeburg, anthony.l.nguyen, davem, edumazet, kuba, pabeni

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.

Fixes: 8fa10ef01260 ("ixgbe: register a mdiobus")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
Cc all pepole in the maintainer list.
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c
index 24aa97f993ca..ed0d6a8f239c 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c
@@ -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;
 
-- 
2.25.1


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

* Re: [PATCH net resend] ixgbe: fix pci device refcount leak
  2022-11-19  6:41 [PATCH net resend] ixgbe: fix pci device refcount leak Yang Yingliang
@ 2022-11-22  4:47 ` Jakub Kicinski
  0 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2022-11-22  4:47 UTC (permalink / raw)
  To: Yang Yingliang
  Cc: netdev, jesse.brandeburg, anthony.l.nguyen, davem, edumazet, pabeni

On Sat, 19 Nov 2022 14:41:55 +0800 Yang Yingliang wrote:
> 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.
> 
> Fixes: 8fa10ef01260 ("ixgbe: register a mdiobus")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
> Cc all pepole in the maintainer list.

still missing the intel-wired-lan list

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

* Re: [PATCH net resend] ixgbe: fix pci device refcount leak
  2022-11-22  6:08 Yang Yingliang
@ 2022-11-28 21:28 ` Tony Nguyen
  0 siblings, 0 replies; 4+ messages in thread
From: Tony Nguyen @ 2022-11-28 21:28 UTC (permalink / raw)
  To: Yang Yingliang, netdev, intel-wired-lan
  Cc: jesse.brandeburg, davem, edumazet, kuba, pabeni, stephend,
	jeffrey.t.kirsher, andrew, f.fainelli

On 11/21/2022 10:08 PM, Yang Yingliang wrote:
> 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.
> 
> Fixes: 8fa10ef01260 ("ixgbe: register a mdiobus")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---

<snip>

> @@ -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;

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

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

* [PATCH net resend] ixgbe: fix pci device refcount leak
@ 2022-11-22  6:08 Yang Yingliang
  2022-11-28 21:28 ` Tony Nguyen
  0 siblings, 1 reply; 4+ messages in thread
From: Yang Yingliang @ 2022-11-22  6:08 UTC (permalink / raw)
  To: netdev, intel-wired-lan
  Cc: jesse.brandeburg, anthony.l.nguyen, davem, edumazet, kuba,
	pabeni, stephend, jeffrey.t.kirsher, andrew, f.fainelli

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.

Fixes: 8fa10ef01260 ("ixgbe: register a mdiobus")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
Cc all pepole in the maintainer list.
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c
index 24aa97f993ca..ed0d6a8f239c 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c
@@ -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;
 
-- 
2.25.1


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

end of thread, other threads:[~2022-11-28 21:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-19  6:41 [PATCH net resend] ixgbe: fix pci device refcount leak Yang Yingliang
2022-11-22  4:47 ` Jakub Kicinski
2022-11-22  6:08 Yang Yingliang
2022-11-28 21:28 ` Tony Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).