public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH] io_uring: fix xa_alloc_cycle() error return value check
@ 2021-08-20 20:57 Jens Axboe
  2021-08-20 21:01 ` Jens Axboe
  0 siblings, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2021-08-20 20:57 UTC (permalink / raw)
  To: io-uring; +Cc: Matthew Wilcox

We currently check for ret != 0 to indicate error, but '1' is a valid
return and just indicates that the allocation succeeded with a wrap.
Correct the check to be for < 0, like it was before the xarray
conversion.

Cc: [email protected]
Fixes: 61cf93700fe6 ("io_uring: Convert personality_idr to XArray")
Signed-off-by: Jens Axboe <[email protected]>

---

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 979941bcd15a..60851908ed6f 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -9843,7 +9843,7 @@ static int io_register_personality(struct io_ring_ctx *ctx)
 
 	ret = xa_alloc_cyclic(&ctx->personalities, &id, (void *)creds,
 			XA_LIMIT(0, USHRT_MAX), &ctx->pers_next, GFP_KERNEL);
-	if (!ret)
+	if (ret < 0)
 		return id;
 	put_cred(creds);
 	return ret;

-- 
Jens Axboe


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

* Re: [PATCH] io_uring: fix xa_alloc_cycle() error return value check
  2021-08-20 20:57 [PATCH] io_uring: fix xa_alloc_cycle() error return value check Jens Axboe
@ 2021-08-20 21:01 ` Jens Axboe
  2021-08-20 21:49   ` Matthew Wilcox
  0 siblings, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2021-08-20 21:01 UTC (permalink / raw)
  To: io-uring; +Cc: Matthew Wilcox

On 8/20/21 2:57 PM, Jens Axboe wrote:
> We currently check for ret != 0 to indicate error, but '1' is a valid
> return and just indicates that the allocation succeeded with a wrap.
> Correct the check to be for < 0, like it was before the xarray
> conversion.
> 
> Cc: [email protected]
> Fixes: 61cf93700fe6 ("io_uring: Convert personality_idr to XArray")
> Signed-off-by: Jens Axboe <[email protected]>

Gah, included a debug patch, not the fix. Here's the right one.

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 979941bcd15a..a2e20a6fbfed 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -9843,10 +9843,11 @@ static int io_register_personality(struct io_ring_ctx *ctx)
 
 	ret = xa_alloc_cyclic(&ctx->personalities, &id, (void *)creds,
 			XA_LIMIT(0, USHRT_MAX), &ctx->pers_next, GFP_KERNEL);
-	if (!ret)
-		return id;
-	put_cred(creds);
-	return ret;
+	if (ret < 0) {
+		put_cred(creds);
+		return ret;
+	}
+	return id;
 }
 
 static int io_register_restrictions(struct io_ring_ctx *ctx, void __user *arg,

-- 
Jens Axboe


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

* Re: [PATCH] io_uring: fix xa_alloc_cycle() error return value check
  2021-08-20 21:01 ` Jens Axboe
@ 2021-08-20 21:49   ` Matthew Wilcox
  2021-08-20 22:05     ` Jens Axboe
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2021-08-20 21:49 UTC (permalink / raw)
  To: Jens Axboe; +Cc: io-uring

On Fri, Aug 20, 2021 at 03:01:20PM -0600, Jens Axboe wrote:
>  	ret = xa_alloc_cyclic(&ctx->personalities, &id, (void *)creds,
>  			XA_LIMIT(0, USHRT_MAX), &ctx->pers_next, GFP_KERNEL);
> -	if (!ret)
> -		return id;
> -	put_cred(creds);
> -	return ret;
> +	if (ret < 0) {
> +		put_cred(creds);
> +		return ret;
> +	}
> +	return id;
>  }

Wouldn't you rather:

	if (ret >= 0)
		return id;
	put_cred(creds);
	return ret;

?

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

* Re: [PATCH] io_uring: fix xa_alloc_cycle() error return value check
  2021-08-20 21:49   ` Matthew Wilcox
@ 2021-08-20 22:05     ` Jens Axboe
  0 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2021-08-20 22:05 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: io-uring

On 8/20/21 3:49 PM, Matthew Wilcox wrote:
> On Fri, Aug 20, 2021 at 03:01:20PM -0600, Jens Axboe wrote:
>>  	ret = xa_alloc_cyclic(&ctx->personalities, &id, (void *)creds,
>>  			XA_LIMIT(0, USHRT_MAX), &ctx->pers_next, GFP_KERNEL);
>> -	if (!ret)
>> -		return id;
>> -	put_cred(creds);
>> -	return ret;
>> +	if (ret < 0) {
>> +		put_cred(creds);
>> +		return ret;
>> +	}
>> +	return id;
>>  }
> 
> Wouldn't you rather:
> 
> 	if (ret >= 0)
> 		return id;
> 	put_cred(creds);
> 	return ret;

Don't really feel that strongly, I tend to like to do the error path
like that unless it's a hot path. But I can go either way, if someone
else feels strongly about it :-)

-- 
Jens Axboe


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

end of thread, other threads:[~2021-08-20 22:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-20 20:57 [PATCH] io_uring: fix xa_alloc_cycle() error return value check Jens Axboe
2021-08-20 21:01 ` Jens Axboe
2021-08-20 21:49   ` Matthew Wilcox
2021-08-20 22:05     ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox