diff mbox series

[net] bnx2x: fix pci device refcount leak in bnx2x_vf_is_pcie_pending()

Message ID 20221117123301.42916-1-yangyingliang@huawei.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net] bnx2x: fix pci device refcount leak in bnx2x_vf_is_pcie_pending() | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 24 this patch: 24
netdev/cc_maintainers fail 1 blamed authors not CCed: eilong@broadcom.com; 4 maintainers not CCed: eilong@broadcom.com pabeni@redhat.com edumazet@google.com kuba@kernel.org
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 22 this patch: 22
netdev/checkpatch warning WARNING: Missing a blank line after declarations
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Yang Yingliang Nov. 17, 2022, 12:33 p.m. UTC
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(-)

Comments

Jakub Kicinski Nov. 19, 2022, 2:52 a.m. UTC | #1
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.
diff mbox series

Patch

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