public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH -next] io_uring: Ensure mask is initialized in io_arm_poll_handler
@ 2020-03-02 23:01 Nathan Chancellor
  2020-03-02 23:12 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Nathan Chancellor @ 2020-03-02 23:01 UTC (permalink / raw)
  To: Jens Axboe; +Cc: io-uring, linux-kernel, clang-built-linux, Nathan Chancellor

Clang warns:

fs/io_uring.c:4178:6: warning: variable 'mask' is used uninitialized
whenever 'if' condition is false [-Wsometimes-uninitialized]
        if (def->pollin)
            ^~~~~~~~~~~
fs/io_uring.c:4182:2: note: uninitialized use occurs here
        mask |= POLLERR | POLLPRI;
        ^~~~
fs/io_uring.c:4178:2: note: remove the 'if' if its condition is always
true
        if (def->pollin)
        ^~~~~~~~~~~~~~~~
fs/io_uring.c:4154:15: note: initialize the variable 'mask' to silence
this warning
        __poll_t mask, ret;
                     ^
                      = 0
1 warning generated.

io_op_defs has many definitions where pollin is not set so mask indeed
might be uninitialized. Initialize it to zero and change the next
assignment to |=, in case further masks are added in the future to avoid
missing changing the assignment then.

Fixes: d7718a9d25a6 ("io_uring: use poll driven retry for files that support it")
Link: https://github.com/ClangBuiltLinux/linux/issues/916
Signed-off-by: Nathan Chancellor <[email protected]>
---

I noticed that for-next has been force pushed; if you want to squash
this into the commit that it fixes (or fix it in a different way), feel
free.

 fs/io_uring.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 8cdd3870cd4e..70e4624af3c2 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -3738,8 +3738,9 @@ static bool io_arm_poll_handler(struct io_kiocb *req)
 	req->apoll = apoll;
 	INIT_HLIST_NODE(&req->hash_node);
 
+	mask = 0;
 	if (def->pollin)
-		mask = POLLIN | POLLRDNORM;
+		mask |= POLLIN | POLLRDNORM;
 	if (def->pollout)
 		mask |= POLLOUT | POLLWRNORM;
 	mask |= POLLERR | POLLPRI;
-- 
2.25.1


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

* Re: [PATCH -next] io_uring: Ensure mask is initialized in io_arm_poll_handler
  2020-03-02 23:01 [PATCH -next] io_uring: Ensure mask is initialized in io_arm_poll_handler Nathan Chancellor
@ 2020-03-02 23:12 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2020-03-02 23:12 UTC (permalink / raw)
  To: Nathan Chancellor; +Cc: io-uring, linux-kernel, clang-built-linux

On 3/2/20 4:01 PM, Nathan Chancellor wrote:
> Clang warns:
> 
> fs/io_uring.c:4178:6: warning: variable 'mask' is used uninitialized
> whenever 'if' condition is false [-Wsometimes-uninitialized]
>         if (def->pollin)
>             ^~~~~~~~~~~
> fs/io_uring.c:4182:2: note: uninitialized use occurs here
>         mask |= POLLERR | POLLPRI;
>         ^~~~
> fs/io_uring.c:4178:2: note: remove the 'if' if its condition is always
> true
>         if (def->pollin)
>         ^~~~~~~~~~~~~~~~
> fs/io_uring.c:4154:15: note: initialize the variable 'mask' to silence
> this warning
>         __poll_t mask, ret;
>                      ^
>                       = 0
> 1 warning generated.
> 
> io_op_defs has many definitions where pollin is not set so mask indeed
> might be uninitialized. Initialize it to zero and change the next
> assignment to |=, in case further masks are added in the future to avoid
> missing changing the assignment then.
> 
> Fixes: d7718a9d25a6 ("io_uring: use poll driven retry for files that support it")
> Link: https://github.com/ClangBuiltLinux/linux/issues/916
> Signed-off-by: Nathan Chancellor <[email protected]>
> ---
> 
> I noticed that for-next has been force pushed; if you want to squash
> this into the commit that it fixes (or fix it in a different way), feel
> free.

Great thanks, applied. I wonder why gcc doesn't warn about that...

-- 
Jens Axboe


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

end of thread, other threads:[~2020-03-02 23:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-02 23:01 [PATCH -next] io_uring: Ensure mask is initialized in io_arm_poll_handler Nathan Chancellor
2020-03-02 23:12 ` Jens Axboe

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