target-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] IB/srpt: Fix passing zero to 'PTR_ERR'
@ 2020-11-12 14:54 YueHaibing
  2020-11-12 17:20 ` Jason Gunthorpe
  0 siblings, 1 reply; 5+ messages in thread
From: YueHaibing @ 2020-11-12 14:54 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.17.1

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

* Re: [PATCH] IB/srpt: Fix passing zero to 'PTR_ERR'
  2020-11-12 14:54 [PATCH] IB/srpt: Fix passing zero to 'PTR_ERR' YueHaibing
@ 2020-11-12 17:20 ` Jason Gunthorpe
  2020-11-12 18:25   ` Bart Van Assche
  0 siblings, 1 reply; 5+ messages in thread
From: Jason Gunthorpe @ 2020-11-12 17:20 UTC (permalink / raw)
  To: YueHaibing; +Cc: bvanassche, dledford, linux-rdma, target-devel, linux-kernel

On Thu, Nov 12, 2020 at 10:54:43PM +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);
>  		ch->sess = NULL;
>  		pr_info("Rejected login for initiator %s: ret = %d.\n",
>  			ch->sess_name, ret);

I think it should be like this, Bart?

diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
index 6017d525084a0c..80f9673956ced2 100644
--- a/drivers/infiniband/ulp/srpt/ib_srpt.c
+++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
@@ -2311,7 +2311,7 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
 
 	mutex_lock(&sport->port_guid_id.mutex);
 	list_for_each_entry(stpg, &sport->port_guid_id.tpg_list, entry) {
-		if (!IS_ERR_OR_NULL(ch->sess))
+		if (ch->sess)
 			break;
 		ch->sess = target_setup_session(&stpg->tpg, tag_num,
 						tag_size, TARGET_PROT_NORMAL,
@@ -2321,12 +2321,12 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
 
 	mutex_lock(&sport->port_gid_id.mutex);
 	list_for_each_entry(stpg, &sport->port_gid_id.tpg_list, entry) {
-		if (!IS_ERR_OR_NULL(ch->sess))
+		if (ch->sess)
 			break;
 		ch->sess = target_setup_session(&stpg->tpg, tag_num,
 					tag_size, TARGET_PROT_NORMAL, i_port_id,
 					ch, NULL);
-		if (!IS_ERR_OR_NULL(ch->sess))
+		if (ch->sess)
 			break;
 		/* Retry without leading "0x" */
 		ch->sess = target_setup_session(&stpg->tpg, tag_num,
@@ -2335,7 +2335,9 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
 	}
 	mutex_unlock(&sport->port_gid_id.mutex);
 
-	if (IS_ERR_OR_NULL(ch->sess)) {
+	if (!ch->sess)
+		ch->sess = ERR_PTR(-ENOENT);
+	if (IS_ERR(ch->sess)) {
 		WARN_ON_ONCE(ch->sess = NULL);
 		ret = PTR_ERR(ch->sess);
 		ch->sess = NULL;

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

* Re: [PATCH] IB/srpt: Fix passing zero to 'PTR_ERR'
  2020-11-12 17:20 ` Jason Gunthorpe
@ 2020-11-12 18:25   ` Bart Van Assche
  2020-11-12 18:30     ` Jason Gunthorpe
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Van Assche @ 2020-11-12 18:25 UTC (permalink / raw)
  To: Jason Gunthorpe, YueHaibing
  Cc: dledford, linux-rdma, target-devel, linux-kernel

On 11/12/20 9:20 AM, Jason Gunthorpe wrote:
> I think it should be like this, Bart?
> 
> diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
> index 6017d525084a0c..80f9673956ced2 100644
> --- a/drivers/infiniband/ulp/srpt/ib_srpt.c
> +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
> @@ -2311,7 +2311,7 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
>   
>   	mutex_lock(&sport->port_guid_id.mutex);
>   	list_for_each_entry(stpg, &sport->port_guid_id.tpg_list, entry) {
> -		if (!IS_ERR_OR_NULL(ch->sess))
> +		if (ch->sess)
>   			break;
>   		ch->sess = target_setup_session(&stpg->tpg, tag_num,
>   						tag_size, TARGET_PROT_NORMAL,
> @@ -2321,12 +2321,12 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
>   
>   	mutex_lock(&sport->port_gid_id.mutex);
>   	list_for_each_entry(stpg, &sport->port_gid_id.tpg_list, entry) {
> -		if (!IS_ERR_OR_NULL(ch->sess))
> +		if (ch->sess)
>   			break;
>   		ch->sess = target_setup_session(&stpg->tpg, tag_num,
>   					tag_size, TARGET_PROT_NORMAL, i_port_id,
>   					ch, NULL);
> -		if (!IS_ERR_OR_NULL(ch->sess))
> +		if (ch->sess)
>   			break;
>   		/* Retry without leading "0x" */
>   		ch->sess = target_setup_session(&stpg->tpg, tag_num,
> @@ -2335,7 +2335,9 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
>   	}
>   	mutex_unlock(&sport->port_gid_id.mutex);
>   
> -	if (IS_ERR_OR_NULL(ch->sess)) {
> +	if (!ch->sess)
> +		ch->sess = ERR_PTR(-ENOENT);
> +	if (IS_ERR(ch->sess)) {
>   		WARN_ON_ONCE(ch->sess = NULL);
>   		ret = PTR_ERR(ch->sess);
>   		ch->sess = NULL;
> 

Hi Jason,

The ib_srpt driver accepts three different formats for the initiator 
ACL. Up to two of the three target_setup_session() calls will fail if 
the fifth argument of target_setup_session() does not use the format of 
the initiator ID in configfs. If the first or the second 
target_setup_session() call fails it is essential that later 
target_setup_session() calls happen. Hence the IS_ERR_OR_NULL(ch->sess) 
checks in the above loops.

In other words, I like YueHaibing's patch better.

Thanks,

Bart.

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

* Re: [PATCH] IB/srpt: Fix passing zero to 'PTR_ERR'
  2020-11-12 18:25   ` Bart Van Assche
@ 2020-11-12 18:30     ` Jason Gunthorpe
  2021-05-14  7:54       ` YueHaibing
  0 siblings, 1 reply; 5+ messages in thread
From: Jason Gunthorpe @ 2020-11-12 18:30 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: YueHaibing, dledford, linux-rdma, target-devel, linux-kernel

On Thu, Nov 12, 2020 at 10:25:48AM -0800, Bart Van Assche wrote:
> On 11/12/20 9:20 AM, Jason Gunthorpe wrote:
> > I think it should be like this, Bart?
> > 
> > diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
> > index 6017d525084a0c..80f9673956ced2 100644
> > +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
> > @@ -2311,7 +2311,7 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
> >   	mutex_lock(&sport->port_guid_id.mutex);
> >   	list_for_each_entry(stpg, &sport->port_guid_id.tpg_list, entry) {
> > -		if (!IS_ERR_OR_NULL(ch->sess))
> > +		if (ch->sess)
> >   			break;
> >   		ch->sess = target_setup_session(&stpg->tpg, tag_num,
> >   						tag_size, TARGET_PROT_NORMAL,
> > @@ -2321,12 +2321,12 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
> >   	mutex_lock(&sport->port_gid_id.mutex);
> >   	list_for_each_entry(stpg, &sport->port_gid_id.tpg_list, entry) {
> > -		if (!IS_ERR_OR_NULL(ch->sess))
> > +		if (ch->sess)
> >   			break;
> >   		ch->sess = target_setup_session(&stpg->tpg, tag_num,
> >   					tag_size, TARGET_PROT_NORMAL, i_port_id,
> >   					ch, NULL);
> > -		if (!IS_ERR_OR_NULL(ch->sess))
> > +		if (ch->sess)
> >   			break;
> >   		/* Retry without leading "0x" */
> >   		ch->sess = target_setup_session(&stpg->tpg, tag_num,
> > @@ -2335,7 +2335,9 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
> >   	}
> >   	mutex_unlock(&sport->port_gid_id.mutex);
> > -	if (IS_ERR_OR_NULL(ch->sess)) {
> > +	if (!ch->sess)
> > +		ch->sess = ERR_PTR(-ENOENT);
> > +	if (IS_ERR(ch->sess)) {
> >   		WARN_ON_ONCE(ch->sess = NULL);
> >   		ret = PTR_ERR(ch->sess);
> >   		ch->sess = NULL;
> > 
> 
> Hi Jason,
> 
> The ib_srpt driver accepts three different formats for the initiator ACL. Up
> to two of the three target_setup_session() calls will fail if the fifth
> argument of target_setup_session() does not use the format of the initiator
> ID in configfs. If the first or the second target_setup_session() call fails
> it is essential that later target_setup_session() calls happen. Hence the
> IS_ERR_OR_NULL(ch->sess) checks in the above loops.

IS_ERR_OR_NULL is an abomination, it should not be used.

I see I didn't quite get it right, but that is still closer to sane,
probably target_setup_session() should return NULL not err_ptr

Jason

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

* Re: [PATCH] IB/srpt: Fix passing zero to 'PTR_ERR'
  2020-11-12 18:30     ` Jason Gunthorpe
@ 2021-05-14  7:54       ` YueHaibing
  0 siblings, 0 replies; 5+ messages in thread
From: YueHaibing @ 2021-05-14  7:54 UTC (permalink / raw)
  To: Jason Gunthorpe, Bart Van Assche
  Cc: dledford, linux-rdma, target-devel, linux-kernel

On 2020/11/13 2:30, Jason Gunthorpe wrote:
> On Thu, Nov 12, 2020 at 10:25:48AM -0800, Bart Van Assche wrote:
>> On 11/12/20 9:20 AM, Jason Gunthorpe wrote:
>>> I think it should be like this, Bart?
>>>
>>> diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
>>> index 6017d525084a0c..80f9673956ced2 100644
>>> +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
>>> @@ -2311,7 +2311,7 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
>>>   	mutex_lock(&sport->port_guid_id.mutex);
>>>   	list_for_each_entry(stpg, &sport->port_guid_id.tpg_list, entry) {
>>> -		if (!IS_ERR_OR_NULL(ch->sess))
>>> +		if (ch->sess)
>>>   			break;
>>>   		ch->sess = target_setup_session(&stpg->tpg, tag_num,
>>>   						tag_size, TARGET_PROT_NORMAL,
>>> @@ -2321,12 +2321,12 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
>>>   	mutex_lock(&sport->port_gid_id.mutex);
>>>   	list_for_each_entry(stpg, &sport->port_gid_id.tpg_list, entry) {
>>> -		if (!IS_ERR_OR_NULL(ch->sess))
>>> +		if (ch->sess)
>>>   			break;
>>>   		ch->sess = target_setup_session(&stpg->tpg, tag_num,
>>>   					tag_size, TARGET_PROT_NORMAL, i_port_id,
>>>   					ch, NULL);
>>> -		if (!IS_ERR_OR_NULL(ch->sess))
>>> +		if (ch->sess)
>>>   			break;
>>>   		/* Retry without leading "0x" */
>>>   		ch->sess = target_setup_session(&stpg->tpg, tag_num,
>>> @@ -2335,7 +2335,9 @@ static int srpt_cm_req_recv(struct srpt_device *const sdev,
>>>   	}
>>>   	mutex_unlock(&sport->port_gid_id.mutex);
>>> -	if (IS_ERR_OR_NULL(ch->sess)) {
>>> +	if (!ch->sess)
>>> +		ch->sess = ERR_PTR(-ENOENT);
>>> +	if (IS_ERR(ch->sess)) {
>>>   		WARN_ON_ONCE(ch->sess == NULL);
>>>   		ret = PTR_ERR(ch->sess);
>>>   		ch->sess = NULL;
>>>
>>
>> Hi Jason,
>>
>> The ib_srpt driver accepts three different formats for the initiator ACL. Up
>> to two of the three target_setup_session() calls will fail if the fifth
>> argument of target_setup_session() does not use the format of the initiator
>> ID in configfs. If the first or the second target_setup_session() call fails
>> it is essential that later target_setup_session() calls happen. Hence the
>> IS_ERR_OR_NULL(ch->sess) checks in the above loops.
> 
> IS_ERR_OR_NULL is an abomination, it should not be used.
> 
> I see I didn't quite get it right, but that is still closer to sane,
> probably target_setup_session() should return NULL not err_ptr

Any fix plan?

> 
> Jason
> .
> 

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

end of thread, other threads:[~2021-05-14  7:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-12 14:54 [PATCH] IB/srpt: Fix passing zero to 'PTR_ERR' YueHaibing
2020-11-12 17:20 ` Jason Gunthorpe
2020-11-12 18:25   ` Bart Van Assche
2020-11-12 18:30     ` Jason Gunthorpe
2021-05-14  7:54       ` YueHaibing

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