diff mbox series

[2/2] RDMA/srp: Fix error return code in srp_parse_options()

Message ID 1669377831-41386-2-git-send-email-wangyufen@huawei.com (mailing list archive)
State Superseded
Headers show
Series [1/2] RDMA/hfi1: Fix error return code in parse_platform_config() | expand

Commit Message

wangyufen Nov. 25, 2022, 12:03 p.m. UTC
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")
Signed-off-by: Wang Yufen <wangyufen@huawei.com>
---
 drivers/infiniband/ulp/srp/ib_srp.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Andy Shevchenko Nov. 25, 2022, 2:37 p.m. UTC | #1
On Fri, Nov 25, 2022 at 08:03:51PM +0800, Wang Yufen wrote:
> In the previous while loop, "ret" may be assigned zero. Therefore,
> "ret" needs to be assigned -EINVAL at the beginning of each loop.

...

>  	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...
wangyufen Nov. 26, 2022, 1:23 a.m. UTC | #2
在 2022/11/25 22:37, Andy Shevchenko 写道:
> On Fri, Nov 25, 2022 at 08:03:51PM +0800, Wang Yufen wrote:
>> In the previous while loop, "ret" may be assigned zero. Therefore,
>> "ret" needs to be assigned -EINVAL at the beginning of each loop.
> 
> ...
> 
>>   	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...
>
I got it. Will change in v2.
Thanks!
diff mbox series

Patch

diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index 1075c2a..1bd3559 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -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;