All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] octeontx2-af: Fix reference count issue in rvu_sdp_init()
@ 2022-11-14 13:28 Xiongfeng Wang
  2022-11-15 21:44 ` Saeed Mahameed
  0 siblings, 1 reply; 2+ messages in thread
From: Xiongfeng Wang @ 2022-11-14 13:28 UTC (permalink / raw)
  To: sgoutham, lcherian, gakula, jerinj, hkelam, sbhatta, davem, radhac
  Cc: netdev, yangyingliang, wangxiongfeng2

pci_get_device() will decrease the reference count for the *from*
parameter. So we don't need to call put_device() to decrease the
reference. Let's remove the put_device() in the loop and only decrease
the reference count of the returned 'pdev' for the last loop because it
will not be passed to pci_get_device() as input parameter. Also add
pci_dev_put() for the error path.

Fixes: fe1939bb2340 ("octeontx2-af: Add SDP interface support")
Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
---
 drivers/net/ethernet/marvell/octeontx2/af/rvu_sdp.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_sdp.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_sdp.c
index b04fb226f708..283d1c90e083 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_sdp.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_sdp.c
@@ -62,15 +62,19 @@ int rvu_sdp_init(struct rvu *rvu)
 		pfvf->sdp_info = devm_kzalloc(rvu->dev,
 					      sizeof(struct sdp_node_info),
 					      GFP_KERNEL);
-		if (!pfvf->sdp_info)
+		if (!pfvf->sdp_info) {
+			pci_dev_put(pdev);
 			return -ENOMEM;
+		}
 
 		dev_info(rvu->dev, "SDP PF number:%d\n", sdp_pf_num[i]);
 
-		put_device(&pdev->dev);
 		i++;
 	}
 
+	if (pdev)
+		pci_dev_put(pdev);
+
 	return 0;
 }
 
-- 
2.20.1


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

* Re: [PATCH] octeontx2-af: Fix reference count issue in rvu_sdp_init()
  2022-11-14 13:28 [PATCH] octeontx2-af: Fix reference count issue in rvu_sdp_init() Xiongfeng Wang
@ 2022-11-15 21:44 ` Saeed Mahameed
  0 siblings, 0 replies; 2+ messages in thread
From: Saeed Mahameed @ 2022-11-15 21:44 UTC (permalink / raw)
  To: Xiongfeng Wang
  Cc: sgoutham, lcherian, gakula, jerinj, hkelam, sbhatta, davem,
	radhac, netdev, yangyingliang

On 14 Nov 21:28, Xiongfeng Wang wrote:
>pci_get_device() will decrease the reference count for the *from*
>parameter. So we don't need to call put_device() to decrease the
>reference. Let's remove the put_device() in the loop and only decrease
>the reference count of the returned 'pdev' for the last loop because it
>will not be passed to pci_get_device() as input parameter. Also add
>pci_dev_put() for the error path.
>
>Fixes: fe1939bb2340 ("octeontx2-af: Add SDP interface support")
>Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
>---

Reviewed-by: Saeed Mahameed <saeed@kernel.org>


> drivers/net/ethernet/marvell/octeontx2/af/rvu_sdp.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_sdp.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_sdp.c
>index b04fb226f708..283d1c90e083 100644
>--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_sdp.c
>+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_sdp.c
>@@ -62,15 +62,19 @@ int rvu_sdp_init(struct rvu *rvu)
> 		pfvf->sdp_info = devm_kzalloc(rvu->dev,
> 					      sizeof(struct sdp_node_info),
> 					      GFP_KERNEL);
>-		if (!pfvf->sdp_info)
>+		if (!pfvf->sdp_info) {
>+			pci_dev_put(pdev);
> 			return -ENOMEM;
>+		}
>
> 		dev_info(rvu->dev, "SDP PF number:%d\n", sdp_pf_num[i]);
>
>-		put_device(&pdev->dev);
> 		i++;
> 	}
>
>+	if (pdev)
>+		pci_dev_put(pdev);
>+

you can drop the if(pdev), already checked inside pci_dev_put();


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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-14 13:28 [PATCH] octeontx2-af: Fix reference count issue in rvu_sdp_init() Xiongfeng Wang
2022-11-15 21:44 ` Saeed Mahameed

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.