Skip to contentSkip to conversation

io_uring: warning about unused-but-set parameter

RFC PATCH Superseded Arnd Bergmann 3 participants 5 messages Sep 20, 2021 – Sep 21, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 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")
---
 fs/io_uring.c | 1 +
 1 file changed, 1 insertion(+)
fs/io_uring.c +1 -0
index 63b0425d6a32..36fbc7f06f5e 100644
@@ -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);
Signature · 1 line
2.29.2
#1 lore raw
Quoted 10 lines · Arnd Bergmann

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)
| ~~~~~~^~~~~~

Quoted 6 lines

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.

Please don't. These warning are utterly stupid and should not be enabled. For anything that is a "method" of sorts (that is assigned to a function pointer), unused argument are perfectly normal.

#2 lore raw
Quoted 19 lines · Christoph Hellwig
Quoted 10 lines · Arnd Bergmann

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)
| ~~~~~~^~~~~~

Quoted 6 lines

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.

Quoted 3 lines

Please don't. These warning are utterly stupid and should not be enabled. For anything that is a "method" of sorts (that is assigned to a function pointer), unused argument are perfectly normal.

I'm not suggesting to enable -Wunused-parameter, which would be complete madness of crouse, only -Wunused-but-set-parameter, which is already part of W=1 and has the potential of catching actual bugs such as

int f(int val)

{
      if (val = 1)
            return 0;

       return -1;
}

Arnd

maintainer
#4 lore raw
In reply to Arnd Bergmann
Quoted 10 lines · Arnd Bergmann

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)
| ~~~~~~^~~~~~

Quoted 6 lines

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.

Signature · 1 line
Jens Axboe
#3 lore raw
In reply to Arnd Bergmann
Quoted 3 lines · Arnd Bergmann

complete madness of crouse, only -Wunused-but-set-parameter, which is already part of W=1 and has the potential of catching actual bugs such as

Well, i you care about that just remove the

	locked = NULL;

which is pretty weird anyway.