IB/srpt: Fix passing zero to 'PTR_ERR'
Subsystems (3)
PATCH 1/1 IB/srpt: Fix passing zero to 'PTR_ERR'
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
--- drivers/infiniband/ulp/srpt/ib_srpt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/ulp/srpt/ib_srpt.c +1 -1
@@ -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);
Signature · 1 line
2.17.1
Jason Gunthorpe
maintainerQuoted 15 lines · YueHaibing
Fix smatch warning:
drivers/infiniband/ulp/srpt/ib_srpt.c:2341srpt_cm_req_recv()warn: passing zero to 'PTR_ERR'Use
PTR_ERR_OR_ZEROinstead ofPTR_ERRFixes 847462de3a0a ("IB/srpt: Fix srpt_cm_req_recv() error path (1/2)")Signed-off-by YueHaibing <[email protected]>drivers/infiniband/ulp/srpt/ib_srpt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/infiniband/ulp/srpt/ib_srpt.c +1
-0+++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
drivers/infiniband/ulp/srpt/ib_srpt.c static int srpt_cm_req_recv(struct srpt_device *const sdev, · line 2344
Quoted 8 lines
drivers/infiniband/ulp/srpt/ib_srpt.c +1
-1@@ -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?
drivers/infiniband/ulp/srpt/ib_srpt.c +6 -4
@@ -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 ;
Bart Van Assche
maintainerQuoted 32 lines · Jason Gunthorpe
I think it should be like this, Bart?
drivers/infiniband/ulp/srpt/ib_srpt.c +3
-3@@ -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,
drivers/infiniband/ulp/srpt/ib_srpt.c static int srpt_cm_req_recv(struct srpt_device *const sdev, · line 2343
Quoted 10 lines
drivers/infiniband/ulp/srpt/ib_srpt.c +3
-1@@ -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.
Jason Gunthorpe
maintainerQuoted 42 lines · Bart Van Assche
Quoted 28 lines · Jason Gunthorpe
I think it should be like this, Bart?
drivers/infiniband/ulp/srpt/ib_srpt.c +4
-3+++ 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,drivers/infiniband/ulp/srpt/ib_srpt.c static int srpt_cm_req_recv(struct srpt_device *const sdev, · line 2343
Quoted 10 lines
drivers/infiniband/ulp/srpt/ib_srpt.c +3
-1@@ -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,
Quoted 6 lines
The
ib_srptdriver accepts three different formats for the initiator ACL. Up to two of the threetarget_setup_session()calls will fail if the fifth argument oftarget_setup_session()does not use the format of the initiator ID in configfs. If the first or the secondtarget_setup_session()call fails it is essential that latertarget_setup_session()calls happen. Hence theIS_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
Quoted 50 lines · Jason Gunthorpe
Quoted 42 lines · Bart Van Assche
Quoted 28 lines · Jason Gunthorpe
I think it should be like this, Bart?
drivers/infiniband/ulp/srpt/ib_srpt.c +4
-3+++ 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,drivers/infiniband/ulp/srpt/ib_srpt.c static int srpt_cm_req_recv(struct srpt_device *const sdev, · line 2343
Quoted 10 lines
drivers/infiniband/ulp/srpt/ib_srpt.c +3
-1@@ -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,
Quoted 6 lines
The
ib_srptdriver accepts three different formats for the initiator ACL. Up to two of the threetarget_setup_session()calls will fail if the fifth argument oftarget_setup_session()does not use the format of the initiator ID in configfs. If the first or the secondtarget_setup_session()call fails it is essential that latertarget_setup_session()calls happen. Hence theIS_ERR_OR_NULL(ch->sess)checks in the above loops.
Quoted 4 lines
IS_ERR_OR_NULLis 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 noterr_ptr
Any fix plan?
Quoted 4 lines
Jason
.