netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] bnx2x: fix pci device refcount leak in bnx2x_vf_is_pcie_pending()
@ 2022-11-17 12:33 Yang Yingliang
  2022-11-19  2:52 ` Jakub Kicinski
  0 siblings, 1 reply; 2+ messages in thread
From: Yang Yingliang @ 2022-11-17 12:33 UTC (permalink / raw)
  To: netdev; +Cc: aelior, skalluru, manishc, davem

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(). Call pci_dev_put() before returning from
bnx2x_vf_is_pcie_pending() to avoid refcount leak.

Fixes: b56e9670ffa4 ("bnx2x: Prepare device and initialize VF database")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
index 11d15cd03600..cd5108b38542 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
@@ -802,8 +802,11 @@ static u8 bnx2x_vf_is_pcie_pending(struct bnx2x *bp, u8 abs_vfid)
 		return false;
 
 	dev = pci_get_domain_bus_and_slot(vf->domain, vf->bus, vf->devfn);
-	if (dev)
-		return bnx2x_is_pcie_pending(dev);
+	if (dev) {
+		bool pending = bnx2x_is_pcie_pending(dev);
+		pci_dev_put(dev);
+		return pending;
+	}
 	return false;
 }
 
-- 
2.25.1


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

* Re: [PATCH net] bnx2x: fix pci device refcount leak in bnx2x_vf_is_pcie_pending()
  2022-11-17 12:33 [PATCH net] bnx2x: fix pci device refcount leak in bnx2x_vf_is_pcie_pending() Yang Yingliang
@ 2022-11-19  2:52 ` Jakub Kicinski
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2022-11-19  2:52 UTC (permalink / raw)
  To: Yang Yingliang; +Cc: netdev, aelior, skalluru, manishc, Joe Perches

On Thu, 17 Nov 2022 20:33:01 +0800 Yang Yingliang wrote:
> diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
> index 11d15cd03600..cd5108b38542 100644
> --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
> +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
> @@ -802,8 +802,11 @@ static u8 bnx2x_vf_is_pcie_pending(struct bnx2x *bp, u8 abs_vfid)
>  		return false;
>  
>  	dev = pci_get_domain_bus_and_slot(vf->domain, vf->bus, vf->devfn);
> -	if (dev)
> -		return bnx2x_is_pcie_pending(dev);
> +	if (dev) {
> +		bool pending = bnx2x_is_pcie_pending(dev);
> +		pci_dev_put(dev);
> +		return pending;
> +	}
>  	return false;

Success path should be unindented:

	dev = pci_get..
	if (!dev)
		return false;
	pending = bnxt2x_is_...
	pci_dev_put(dev);

	return pending;

Please use get_maintainers on the formatted patch file to find all 
the people to CC.

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

end of thread, other threads:[~2022-11-19  2:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-17 12:33 [PATCH net] bnx2x: fix pci device refcount leak in bnx2x_vf_is_pcie_pending() Yang Yingliang
2022-11-19  2:52 ` Jakub Kicinski

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).