Skip to contentSkip to conversation

RDMA/hfi1: Fix error return code in parse_platform_config()

PATCH Superseded Wang Yufen 2 participants 5 messages Nov 25, 2022 – Nov 26, 2022

Subsystems (3)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Wang Yufen

author
#0 lore raw

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.

Fixes 97167e813415 ("staging/rdma/hfi1: Tune for unknown channel if configuration file is absent")
---
 drivers/infiniband/hw/hfi1/firmware.c | 1 +
 1 file changed, 1 insertion(+)
drivers/infiniband/hw/hfi1/firmware.c +1 -0
index 1d77514..c179dfe 100644
@@ -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
author
#1 lore raw

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.

Fixes e711f968c49c ("IB/srp: replace custom implementation of hex2bin()")
Fixes 2a174df0c602 ("IB/srp: Use kstrtoull() instead of simple_strtoull()")
Fixes 19f313438c77 ("IB/srp: Add RDMA/CM support")
---
 drivers/infiniband/ulp/srp/ib_srp.c | 1 +
 1 file changed, 1 insertion(+)
drivers/infiniband/ulp/srp/ib_srp.c +1 -0
index 1075c2a..1bd3559 100644
@@ -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
#2 lore raw

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 -EINVAL at 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 -0
 	while ((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
author
#3 lore raw

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 -EINVAL at 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!

#4 lore raw
In reply to Wang Yufen
Quoted 2 lines · Wang Yufen

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 int parse_platform_config(struct hfi1_devdata *dd) · line 1794

Quoted 5 lines
drivers/infiniband/hw/hfi1/firmware.c +1 -0
 	while (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 add
bali_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