RDMA/hfi1: Fix error return code in parse_platform_config()
Subsystems (3)
PATCH 1/2 RDMA/hfi1: Fix error return code in parse_platform_config()
In the previous while loop, "ret" may be assigned zero. Therefore, "ret" needs to be assigned -EINVAL at the beginning of each loop.
--- drivers/infiniband/hw/hfi1/firmware.c | 1 + 1 file changed, 1 insertion(+)
drivers/infiniband/hw/hfi1/firmware.c +1 -0
@@ -1788,6 +1788,7 @@ int parse_platform_config(struct hfi1_devdata *dd)* being used. */ while (ptr < (u32 *)(dd->platform_config.data + file_length)) { + ret = -EINVAL ; header1 = *ptr; header2 = *(ptr +1 );if (header1 != ~header2) {
Signature · 1 line
1.8.3.1
PATCH 2/2 RDMA/srp: Fix error return code in srp_parse_options()
In the previous while loop, "ret" may be assigned zero. Therefore, "ret" needs to be assigned -EINVAL at the beginning of each loop.
--- drivers/infiniband/ulp/srp/ib_srp.c | 1 + 1 file changed, 1 insertion(+)
drivers/infiniband/ulp/srp/ib_srp.c +1 -0
@@ -3352,6 +3352,7 @@ static int srp_parse_options(struct net *net, const char *buf, sep_opt = options;while ((p =strsep (&sep_opt,",\n" )) !=NULL ) { + ret = -EINVAL ;if (!*p)continue ;
Signature · 1 line
1.8.3.1
Re: [PATCH 2/2] RDMA/srp: Fix error return code in srp_parse_options()
Quoted 2 lines · Wang Yufen
In the previous while loop, "ret" may be assigned zero. Therefore, "ret" needs to be assigned
-EINVALat the beginning of each loop.
...
drivers/infiniband/ulp/srp/ib_srp.c static int srp_parse_options(struct net *net, const char *buf, · line 3357
Quoted 4 lines
drivers/infiniband/ulp/srp/ib_srp.c +1
-0while ((p =strsep (&sep_opt,",\n" )) !=NULL ) { + ret = -EINVAL ;if (!*p)continue ;
Better option is to investigate each case separately and gather all of them into a single fix.
For example, this
case SRP_OPT_MAX_IT_IU_SIZE:
if (match_int(args, &token) || token < 0) {
pr_warn("bad maximum initiator to target IU size '%s'\n", p);
goto out;
}
target->max_it_iu_size = token;
break;can be rewritten as
case SRP_OPT_MAX_IT_IU_SIZE:
ret = match_int(args, &token);
if (ret)
goto out;
if (token < 0) {
pr_warn("bad maximum initiator to target IU size '%s'\n", p);
ret = -EINVAL;
goto out;
}
target->max_it_iu_size = token;
break;and so on...
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 2/2] RDMA/srp: Fix error return code in srp_parse_options()
Quoted 38 lines · Andy Shevchenko
Quoted 2 lines · Wang Yufen
In the previous while loop, "ret" may be assigned zero. Therefore, "ret" needs to be assigned
-EINVALat the beginning of each loop....
drivers/infiniband/ulp/srp/ib_srp.c static int srp_parse_options(struct net *net, const char *buf, · line 3357
Quoted 4 lines
while ((p = strsep(&sep_opt, ",\n")) != NULL) {drivers/infiniband/ulp/srp/ib_srp.c +1
-0+ ret = -EINVAL ;if (!*p)continue ;Better option is to investigate each case separately and gather all of them into a single fix.
For example, this
case SRP_OPT_MAX_IT_IU_SIZE: if (match_int(args, &token) || token < 0) { pr_warn("bad maximum initiator to target IU size '%s'\n", p); goto out; } target->max_it_iu_size = token; break;can be rewritten as
case SRP_OPT_MAX_IT_IU_SIZE: ret = match_int(args, &token); if (ret) goto out; if (token < 0) { pr_warn("bad maximum initiator to target IU size '%s'\n", p); ret = -EINVAL; goto out; } target->max_it_iu_size = token; break;
Quoted 2 lines
and so on...
I got it. Will change in v2.
Thanks!
Quoted 2 lines · Wang Yufen
In the previous while loop, "ret" may be assigned zero. Therefore, "ret" needs to be assigned
-EINVALat the beginning of each loop.
...
drivers/infiniband/hw/hfi1/firmware.c int parse_platform_config(struct hfi1_devdata *dd) · line 1794
Quoted 5 lines
drivers/infiniband/hw/hfi1/firmware.c +1
-0while (ptr < (u32 *)(dd->platform_config.data + file_length)) { + ret = -EINVAL ; header1 = *ptr; header2 = *(ptr +1 );if (header1 != ~header2) {
You may do it differently and simplify even existing code, i.e.
// The following two lines to addbali_with_einval:
ret = -EINVAL; bail: memset(pcfgcache, 0, sizeof(struct platform_config_cache)); return ret;
Then you convert all goto bail; to goto bail_with_einval; where it's appropriate. And dropping some duplicative ret = -EINVAL; lines above.
Signature · 2 lines
With Best Regards, Andy Shevchenko