* [PATCH -next] IB/srpt: Fix passing zero to 'PTR_ERR'
@ 2021-03-24 14:09 YueHaibing
2021-03-24 14:19 ` Leon Romanovsky
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: YueHaibing @ 2021-03-24 14:09 UTC (permalink / raw)
To: bvanassche, dledford, jgg
Cc: linux-rdma, target-devel, linux-kernel, YueHaibing
Fix smatch warning:
drivers/infiniband/ulp/srpt/ib_srpt.c:2341 srpt_cm_req_recv() warn: passing zero to 'PTR_ERR'
Use PTR_ERR_OR_ZERO instead of PTR_ERR
Fixes: 847462de3a0a ("IB/srpt: Fix srpt_cm_req_recv() error path (1/2)")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
drivers/infiniband/ulp/srpt/ib_srpt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
index 6be60aa5ffe2..3ff24b5048ac 100644
--- a/drivers/infiniband/ulp/srpt/ib_srpt.c
+++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
@@ -2338,7 +2338,7 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
if (IS_ERR_OR_NULL(ch->sess)) {
WARN_ON_ONCE(ch->sess == NULL);
- ret = PTR_ERR(ch->sess);
+ ret = PTR_ERR_OR_ZERO(ch->sess);
ch->sess = NULL;
pr_info("Rejected login for initiator %s: ret = %d.\n",
ch->sess_name, ret);
--
2.22.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH -next] IB/srpt: Fix passing zero to 'PTR_ERR'
2021-03-24 14:09 [PATCH -next] IB/srpt: Fix passing zero to 'PTR_ERR' YueHaibing
@ 2021-03-24 14:19 ` Leon Romanovsky
2021-04-01 18:14 ` Jason Gunthorpe
2021-04-01 19:13 ` Bart Van Assche
2 siblings, 0 replies; 4+ messages in thread
From: Leon Romanovsky @ 2021-03-24 14:19 UTC (permalink / raw)
To: YueHaibing
Cc: bvanassche, dledford, jgg, linux-rdma, target-devel, linux-kernel
On Wed, Mar 24, 2021 at 10:09:39PM +0800, YueHaibing wrote:
> Fix smatch warning:
>
> drivers/infiniband/ulp/srpt/ib_srpt.c:2341 srpt_cm_req_recv() warn: passing zero to 'PTR_ERR'
>
> Use PTR_ERR_OR_ZERO instead of PTR_ERR
>
> Fixes: 847462de3a0a ("IB/srpt: Fix srpt_cm_req_recv() error path (1/2)")
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
> drivers/infiniband/ulp/srpt/ib_srpt.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
> index 6be60aa5ffe2..3ff24b5048ac 100644
> --- a/drivers/infiniband/ulp/srpt/ib_srpt.c
> +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
> @@ -2338,7 +2338,7 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
>
> if (IS_ERR_OR_NULL(ch->sess)) {
> WARN_ON_ONCE(ch->sess == NULL);
> - ret = PTR_ERR(ch->sess);
> + ret = PTR_ERR_OR_ZERO(ch->sess);
It is crazy, in first line, we checked ch->sess and allowed it to be NULL,
later caused to kernel panic and set ret to success.
> ch->sess = NULL;
> pr_info("Rejected login for initiator %s: ret = %d.\n",
> ch->sess_name, ret);
> --
> 2.22.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH -next] IB/srpt: Fix passing zero to 'PTR_ERR'
2021-03-24 14:09 [PATCH -next] IB/srpt: Fix passing zero to 'PTR_ERR' YueHaibing
2021-03-24 14:19 ` Leon Romanovsky
@ 2021-04-01 18:14 ` Jason Gunthorpe
2021-04-01 19:13 ` Bart Van Assche
2 siblings, 0 replies; 4+ messages in thread
From: Jason Gunthorpe @ 2021-04-01 18:14 UTC (permalink / raw)
To: YueHaibing; +Cc: bvanassche, dledford, linux-rdma, target-devel, linux-kernel
On Wed, Mar 24, 2021 at 10:09:39PM +0800, YueHaibing wrote:
> Fix smatch warning:
>
> drivers/infiniband/ulp/srpt/ib_srpt.c:2341 srpt_cm_req_recv() warn: passing zero to 'PTR_ERR'
>
> Use PTR_ERR_OR_ZERO instead of PTR_ERR
>
> Fixes: 847462de3a0a ("IB/srpt: Fix srpt_cm_req_recv() error path (1/2)")
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> drivers/infiniband/ulp/srpt/ib_srpt.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
> index 6be60aa5ffe2..3ff24b5048ac 100644
> +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
> @@ -2338,7 +2338,7 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
>
> if (IS_ERR_OR_NULL(ch->sess)) {
> WARN_ON_ONCE(ch->sess == NULL);
> - ret = PTR_ERR(ch->sess);
> + ret = PTR_ERR_OR_ZERO(ch->sess);
This whole flow is a mess, if someone fixes properly then fine, but
I'm not convinced returning 0 here is correct either.
Jason
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH -next] IB/srpt: Fix passing zero to 'PTR_ERR'
2021-03-24 14:09 [PATCH -next] IB/srpt: Fix passing zero to 'PTR_ERR' YueHaibing
2021-03-24 14:19 ` Leon Romanovsky
2021-04-01 18:14 ` Jason Gunthorpe
@ 2021-04-01 19:13 ` Bart Van Assche
2 siblings, 0 replies; 4+ messages in thread
From: Bart Van Assche @ 2021-04-01 19:13 UTC (permalink / raw)
To: YueHaibing, dledford, jgg; +Cc: linux-rdma, target-devel, linux-kernel
On 3/24/21 7:09 AM, YueHaibing wrote:
> Fix smatch warning:
>
> drivers/infiniband/ulp/srpt/ib_srpt.c:2341 srpt_cm_req_recv() warn: passing zero to 'PTR_ERR'
>
> Use PTR_ERR_OR_ZERO instead of PTR_ERR
>
> Fixes: 847462de3a0a ("IB/srpt: Fix srpt_cm_req_recv() error path (1/2)")
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
> drivers/infiniband/ulp/srpt/ib_srpt.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
> index 6be60aa5ffe2..3ff24b5048ac 100644
> --- a/drivers/infiniband/ulp/srpt/ib_srpt.c
> +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
> @@ -2338,7 +2338,7 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
>
> if (IS_ERR_OR_NULL(ch->sess)) {
> WARN_ON_ONCE(ch->sess == NULL);
> - ret = PTR_ERR(ch->sess);
> + ret = PTR_ERR_OR_ZERO(ch->sess);
> ch->sess = NULL;
> pr_info("Rejected login for initiator %s: ret = %d.\n",
> ch->sess_name, ret);
(just noticed this patch)
target_setup_session() should either return a valid session pointer or
an ERR_PTR() but not NULL. Changing IS_ERR_OR_NULL() into IS_ERR() and
removing the WARN_ON_ONCE(ch->sess == NULL) may be a better solution.
Thanks,
Bart.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-04-01 19:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-24 14:09 [PATCH -next] IB/srpt: Fix passing zero to 'PTR_ERR' YueHaibing
2021-03-24 14:19 ` Leon Romanovsky
2021-04-01 18:14 ` Jason Gunthorpe
2021-04-01 19:13 ` Bart Van Assche
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).