2021-09-20 20:36:44

by Arnd Bergmann

[permalink] [raw]
Subject: [PATCH] [RFC] io_uring: warning about unused-but-set parameter

From: Arnd Bergmann <[email protected]>

When enabling -Wunused warnings by building with W=1, I get an
instance of the -Wunused-but-set-parameter warning in the io_uring code:

fs/io_uring.c: In function 'io_queue_async_work':
fs/io_uring.c:1445:61: error: parameter 'locked' set but not used [-Werror=unused-but-set-parameter]
1445 | static void io_queue_async_work(struct io_kiocb *req, bool *locked)
| ~~~~~~^~~~~~

There are very few warnings of this type, so it would be nice to enable
this by default and fix all the existing instances. I was almost
done, but this was added recently as a precaution to prevent code
from using the parameter, which could be done by either removing
the initialization, or by adding a (fake) use of the variable, which
I do here with the cast to void.

Fixes: f237c30a5610 ("io_uring: batch task work locking")
Signed-off-by: Arnd Bergmann <[email protected]>
---
fs/io_uring.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 63b0425d6a32..36fbc7f06f5e 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1450,6 +1450,7 @@ static void io_queue_async_work(struct io_kiocb *req, bool *locked)

/* must not take the lock, NULL it as a precaution */
locked = NULL;
+ (void)locked;

BUG_ON(!tctx);
BUG_ON(!tctx->io_wq);
--
2.29.2


2021-09-21 04:00:54

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH] [RFC] io_uring: warning about unused-but-set parameter

On 9/20/21 6:13 AM, Arnd Bergmann wrote:
> From: Arnd Bergmann <[email protected]>
>
> When enabling -Wunused warnings by building with W=1, I get an
> instance of the -Wunused-but-set-parameter warning in the io_uring code:
>
> fs/io_uring.c: In function 'io_queue_async_work':
> fs/io_uring.c:1445:61: error: parameter 'locked' set but not used [-Werror=unused-but-set-parameter]
> 1445 | static void io_queue_async_work(struct io_kiocb *req, bool *locked)
> | ~~~~~~^~~~~~
>
> There are very few warnings of this type, so it would be nice to enable
> this by default and fix all the existing instances. I was almost
> done, but this was added recently as a precaution to prevent code
> from using the parameter, which could be done by either removing
> the initialization, or by adding a (fake) use of the variable, which
> I do here with the cast to void.

I would just rename the argument here 'dont_use' or something like that,
that should be enough of a signal for future cases that it should need
extra consideration.

--
Jens Axboe