Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH -next] RDMA/usnic: Fix passing zero to PTR_ERR in usnic_ib_pci_probe()
@ 2025-03-23  3:34 Yue Haibing
  2025-03-23  7:53 ` Zhu Yanjun
  2025-03-23 13:13 ` Jason Gunthorpe
  0 siblings, 2 replies; 3+ messages in thread
From: Yue Haibing @ 2025-03-23  3:34 UTC (permalink / raw)
  To: benve, neescoba, jgg, leon, liyuyu6, umalhi, roland
  Cc: linux-rdma, linux-kernel, yuehaibing

drivers/infiniband/hw/usnic/usnic_ib_main.c:590
 usnic_ib_pci_probe() warn: passing zero to 'PTR_ERR'

Use err code in usnic_err() to fix this.

Fixes: e3cf00d0a87f ("IB/usnic: Add Cisco VIC low-level hardware driver")
Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
---
 drivers/infiniband/hw/usnic/usnic_ib_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/hw/usnic/usnic_ib_main.c b/drivers/infiniband/hw/usnic/usnic_ib_main.c
index 4ddcd5860e0f..e40370f9ff25 100644
--- a/drivers/infiniband/hw/usnic/usnic_ib_main.c
+++ b/drivers/infiniband/hw/usnic/usnic_ib_main.c
@@ -587,9 +587,9 @@ static int usnic_ib_pci_probe(struct pci_dev *pdev,
 
 	pf = usnic_ib_discover_pf(vf->vnic);
 	if (IS_ERR_OR_NULL(pf)) {
-		usnic_err("Failed to discover pf of vnic %s with err%ld\n",
-				pci_name(pdev), PTR_ERR(pf));
 		err = pf ? PTR_ERR(pf) : -EFAULT;
+		usnic_err("Failed to discover pf of vnic %s with err%d\n",
+				pci_name(pdev), err);
 		goto out_clean_vnic;
 	}
 
-- 
2.34.1


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

* Re: [PATCH -next] RDMA/usnic: Fix passing zero to PTR_ERR in usnic_ib_pci_probe()
  2025-03-23  3:34 [PATCH -next] RDMA/usnic: Fix passing zero to PTR_ERR in usnic_ib_pci_probe() Yue Haibing
@ 2025-03-23  7:53 ` Zhu Yanjun
  2025-03-23 13:13 ` Jason Gunthorpe
  1 sibling, 0 replies; 3+ messages in thread
From: Zhu Yanjun @ 2025-03-23  7:53 UTC (permalink / raw)
  To: Yue Haibing, benve, neescoba, jgg, leon, liyuyu6, umalhi, roland
  Cc: linux-rdma, linux-kernel

在 2025/3/23 4:34, Yue Haibing 写道:
> drivers/infiniband/hw/usnic/usnic_ib_main.c:590
>   usnic_ib_pci_probe() warn: passing zero to 'PTR_ERR'
> 
> Use err code in usnic_err() to fix this.
> 
> Fixes: e3cf00d0a87f ("IB/usnic: Add Cisco VIC low-level hardware driver")
> Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
> ---
>   drivers/infiniband/hw/usnic/usnic_ib_main.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/usnic/usnic_ib_main.c b/drivers/infiniband/hw/usnic/usnic_ib_main.c
> index 4ddcd5860e0f..e40370f9ff25 100644
> --- a/drivers/infiniband/hw/usnic/usnic_ib_main.c
> +++ b/drivers/infiniband/hw/usnic/usnic_ib_main.c
> @@ -587,9 +587,9 @@ static int usnic_ib_pci_probe(struct pci_dev *pdev,
>   
>   	pf = usnic_ib_discover_pf(vf->vnic);
>   	if (IS_ERR_OR_NULL(pf)) {
> -		usnic_err("Failed to discover pf of vnic %s with err%ld\n",
> -				pci_name(pdev), PTR_ERR(pf));
>   		err = pf ? PTR_ERR(pf) : -EFAULT;

When pf is NULL, PTR_ERR(pf) will warn "passing zero to PTR_ERR". Thus, 
if pf is NULL, the err will be set to -EFAULT.

But from the current implementation of "static struct usnic_ib_dev 
*usnic_ib_discover_pf(struct usnic_vnic *vnic)", it seems that pf can 
not be set to NULL.

But this commit can prevent this warning when the implementation of 
usnic_ib_discover_pf will be changed in the future.

Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev>

Zhu Yanjun

> +		usnic_err("Failed to discover pf of vnic %s with err%d\n",
> +				pci_name(pdev), err);
>   		goto out_clean_vnic;
>   	}
>   


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

* Re: [PATCH -next] RDMA/usnic: Fix passing zero to PTR_ERR in usnic_ib_pci_probe()
  2025-03-23  3:34 [PATCH -next] RDMA/usnic: Fix passing zero to PTR_ERR in usnic_ib_pci_probe() Yue Haibing
  2025-03-23  7:53 ` Zhu Yanjun
@ 2025-03-23 13:13 ` Jason Gunthorpe
  1 sibling, 0 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2025-03-23 13:13 UTC (permalink / raw)
  To: Yue Haibing
  Cc: benve, neescoba, leon, liyuyu6, umalhi, roland, linux-rdma,
	linux-kernel

On Sun, Mar 23, 2025 at 11:34:14AM +0800, Yue Haibing wrote:
> drivers/infiniband/hw/usnic/usnic_ib_main.c:590
>  usnic_ib_pci_probe() warn: passing zero to 'PTR_ERR'
> 
> Use err code in usnic_err() to fix this.
> 
> Fixes: e3cf00d0a87f ("IB/usnic: Add Cisco VIC low-level hardware driver")
> Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
> ---
>  drivers/infiniband/hw/usnic/usnic_ib_main.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/usnic/usnic_ib_main.c b/drivers/infiniband/hw/usnic/usnic_ib_main.c
> index 4ddcd5860e0f..e40370f9ff25 100644
> --- a/drivers/infiniband/hw/usnic/usnic_ib_main.c
> +++ b/drivers/infiniband/hw/usnic/usnic_ib_main.c
> @@ -587,9 +587,9 @@ static int usnic_ib_pci_probe(struct pci_dev *pdev,
>  
>  	pf = usnic_ib_discover_pf(vf->vnic);
>  	if (IS_ERR_OR_NULL(pf)) {

usnic_ib_discover_pf() doesn't return NULL, just remove this test
instead.

You could also fix this:

	us_ibdev = usnic_ib_device_add(parent_pci);
	if (IS_ERR_OR_NULL(us_ibdev)) {
		us_ibdev = us_ibdev ? us_ibdev : ERR_PTR(-EFAULT);

So that device_add doesn't weirdly return NULL and EFAULT, probably
just return NULL on all failures.

Jason

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

end of thread, other threads:[~2025-03-23 13:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-23  3:34 [PATCH -next] RDMA/usnic: Fix passing zero to PTR_ERR in usnic_ib_pci_probe() Yue Haibing
2025-03-23  7:53 ` Zhu Yanjun
2025-03-23 13:13 ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox