public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH 1/1] io_uring: cleanup files_update looping
@ 2021-01-26 12:14 Pavel Begunkov
  2021-01-26 13:34 ` Pavel Begunkov
  0 siblings, 1 reply; 2+ messages in thread
From: Pavel Begunkov @ 2021-01-26 12:14 UTC (permalink / raw)
  To: Jens Axboe, io-uring

Replace a while with a simple for loop, that looks way more natural, and
enables us to use "contiune" as indexes are no more updated by hand in
the end of the loop.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 fs/io_uring.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index f77821626a92..36e4dd55e98b 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -7666,9 +7666,8 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
 	if (!ref_node)
 		return -ENOMEM;
 
-	done = 0;
 	fds = u64_to_user_ptr(up->fds);
-	while (nr_args) {
+	for (done = 0; done < nr_args; done++) {
 		struct fixed_file_table *table;
 		unsigned index;
 
@@ -7677,7 +7676,7 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
 			err = -EFAULT;
 			break;
 		}
-		i = array_index_nospec(up->offset, ctx->nr_user_files);
+		i = array_index_nospec(up->offset + done, ctx->nr_user_files);
 		table = &ctx->file_data->table[i >> IORING_FILE_TABLE_SHIFT];
 		index = i & IORING_FILE_TABLE_MASK;
 		if (table->files[index]) {
@@ -7715,9 +7714,6 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
 				break;
 			}
 		}
-		nr_args--;
-		done++;
-		up->offset++;
 	}
 
 	if (needs_switch) {
-- 
2.24.0


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

* Re: [PATCH 1/1] io_uring: cleanup files_update looping
  2021-01-26 12:14 [PATCH 1/1] io_uring: cleanup files_update looping Pavel Begunkov
@ 2021-01-26 13:34 ` Pavel Begunkov
  0 siblings, 0 replies; 2+ messages in thread
From: Pavel Begunkov @ 2021-01-26 13:34 UTC (permalink / raw)
  To: Jens Axboe, io-uring

On 26/01/2021 12:14, Pavel Begunkov wrote:
> Replace a while with a simple for loop, that looks way more natural, and
> enables us to use "contiune" as indexes are no more updated by hand in
> the end of the loop.

needs a rebase, I'll resend

> 
> Signed-off-by: Pavel Begunkov <[email protected]>
> ---
>  fs/io_uring.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index f77821626a92..36e4dd55e98b 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -7666,9 +7666,8 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
>  	if (!ref_node)
>  		return -ENOMEM;
>  
> -	done = 0;
>  	fds = u64_to_user_ptr(up->fds);
> -	while (nr_args) {
> +	for (done = 0; done < nr_args; done++) {
>  		struct fixed_file_table *table;
>  		unsigned index;
>  
> @@ -7677,7 +7676,7 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
>  			err = -EFAULT;
>  			break;
>  		}
> -		i = array_index_nospec(up->offset, ctx->nr_user_files);
> +		i = array_index_nospec(up->offset + done, ctx->nr_user_files);
>  		table = &ctx->file_data->table[i >> IORING_FILE_TABLE_SHIFT];
>  		index = i & IORING_FILE_TABLE_MASK;
>  		if (table->files[index]) {
> @@ -7715,9 +7714,6 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
>  				break;
>  			}
>  		}
> -		nr_args--;
> -		done++;
> -		up->offset++;
>  	}
>  
>  	if (needs_switch) {
> 

-- 
Pavel Begunkov

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

end of thread, other threads:[~2021-01-26 13:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-26 12:14 [PATCH 1/1] io_uring: cleanup files_update looping Pavel Begunkov
2021-01-26 13:34 ` Pavel Begunkov

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