Skip to contentSkip to conversation

io_uring: Remove logically dead code in io_splice

PATCH In review Gustavo A. R. Silva 3 participants 5 messages May 4, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io_uring: Remove logically dead code in io_splice

In case force_nonblock happens to be true, the function returns at:

2779 if (force_nonblock)
2780 return -EAGAIN;

before reaching this line of code. So, the null check on force_nonblock at 2785, is never actually being executed.

Addresses-Coverity-ID: 1492838 ("Logically dead code")

Fixes 2fb3e82284fc ("io_uring: punt splice async because of inode mutex")
---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/io_uring.c +1 -1
index e5dfbbd2aa34..4b1efb062f7f 100644
@@ -2782,7 +2782,7 @@ static int io_splice(struct io_kiocb *req, bool force_nonblock)
 	poff_in = (sp->off_in == -1) ? NULL : &sp->off_in;
 	poff_out = (sp->off_out == -1) ? NULL : &sp->off_out;
 	ret = do_splice(in, poff_in, out, poff_out, sp->len, flags);
-	if (force_nonblock && ret == -EAGAIN)
+	if (ret == -EAGAIN)
 		return -EAGAIN;
 
 	io_put_file(req, in, (sp->flags & SPLICE_F_FD_IN_FIXED));
Signature · 1 line
2.26.0
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Gustavo A. R. Silva

In case force_nonblock happens to be true, the function returns at:

2779 if (force_nonblock)
2780 return -EAGAIN;

before reaching this line of code. So, the null check on force_nonblock at 2785, is never actually being executed.

Addresses-Coverity-ID: 1492838 ("Logically dead code")

Fixes 2fb3e82284fc ("io_uring: punt splice async because of inode mutex")

It's not a bug, so 'Fixes' tag is IMHO misleading. Anyway,

Quoted 19 lines
---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/io_uring.c +1 -1
index e5dfbbd2aa34..4b1efb062f7f 100644
@@ -2782,7 +2782,7 @@ static int io_splice(struct io_kiocb *req, bool force_nonblock)
 	poff_in = (sp->off_in == -1) ? NULL : &sp->off_in;
 	poff_out = (sp->off_out == -1) ? NULL : &sp->off_out;
 	ret = do_splice(in, poff_in, out, poff_out, sp->len, flags);
-	if (force_nonblock && ret == -EAGAIN)
+	if (ret == -EAGAIN)
 		return -EAGAIN;
 
 	io_put_file(req, in, (sp->flags & SPLICE_F_FD_IN_FIXED));
Signature · 1 line
Pavel Begunkov
maintainer
#2 lore raw
In reply to Gustavo A. R. Silva
Quoted 21 lines · Gustavo A. R. Silva

In case force_nonblock happens to be true, the function returns at:

2779 if (force_nonblock)
2780 return -EAGAIN;

before reaching this line of code. So, the null check on force_nonblock at 2785, is never actually being executed.

Addresses-Coverity-ID: 1492838 ("Logically dead code")

Fixes 2fb3e82284fc ("io_uring: punt splice async because of inode mutex")
---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/io_uring.c +0 -0
index e5dfbbd2aa34..4b1efb062f7f 100644

fs/io_uring.c static int io_splice(struct io_kiocb *req, bool force_nonblock) · line 2786

Quoted 6 lines
fs/io_uring.c +1 -1
@@ -2782,7 +2782,7 @@ static int io_splice(struct io_kiocb *req, bool force_nonblock)
 	poff_in = (sp->off_in == -1) ? NULL : &sp->off_in;
 	poff_out = (sp->off_out == -1) ? NULL : &sp->off_out;
 	ret = do_splice(in, poff_in, out, poff_out, sp->len, flags);
-	if (force_nonblock && ret == -EAGAIN)
+	if (ret == -EAGAIN)
 		return -EAGAIN;

This isn't right, it should just remove the two lines completely. But also see:

https://lore.kernel.org/io-uring/[email protected]/T/#u

Signature · 1 line
Jens Axboe
#3 lore raw
Quoted 17 lines · Jens Axboe
Quoted 16 lines · Gustavo A. R. Silva

In case force_nonblock happens to be true, the function returns at:

2779 if (force_nonblock)
2780 return -EAGAIN;

before reaching this line of code. So, the null check on force_nonblock at 2785, is never actually being executed.

Addresses-Coverity-ID: 1492838 ("Logically dead code")

Fixes 2fb3e82284fc ("io_uring: punt splice async because of inode mutex")
---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines

fs/io_uring.c static int io_splice(struct io_kiocb *req, bool force_nonblock) · line 2786

Quoted 11 lines
fs/io_uring.c +1 -1
index e5dfbbd2aa34..4b1efb062f7f 100644
@@ -2782,7 +2782,7 @@ static int io_splice(struct io_kiocb *req, bool force_nonblock)
 	poff_in = (sp->off_in == -1) ? NULL : &sp->off_in;
 	poff_out = (sp->off_out == -1) ? NULL : &sp->off_out;
 	ret = do_splice(in, poff_in, out, poff_out, sp->len, flags);
-	if (force_nonblock && ret == -EAGAIN)
+	if (ret == -EAGAIN)
 		return -EAGAIN;

This isn't right, it should just remove the two lines completely. But also see:

Oh, right, it will ignore O_NONBLOCK and be resubmitted, as going through io_wq_submit_work(). I need to be more attentive.

Quoted 3 lines

https://lore.kernel.org/io-uring/[email protected]/T/#u

Signature · 1 line
Pavel Begunkov
#4 lore raw
In reply to Jens Axboe
Quoted 15 lines · Jens Axboe

fs/io_uring.c static int io_splice(struct io_kiocb *req, bool force_nonblock) · line 2786

Quoted 11 lines
fs/io_uring.c +1 -1
index e5dfbbd2aa34..4b1efb062f7f 100644
@@ -2782,7 +2782,7 @@ static int io_splice(struct io_kiocb *req, bool force_nonblock)
 	poff_in = (sp->off_in == -1) ? NULL : &sp->off_in;
 	poff_out = (sp->off_out == -1) ? NULL : &sp->off_out;
 	ret = do_splice(in, poff_in, out, poff_out, sp->len, flags);
-	if (force_nonblock && ret == -EAGAIN)
+	if (ret == -EAGAIN)
 		return -EAGAIN;

This isn't right, it should just remove the two lines completely. But also see:

Quoted 2 lines

https://lore.kernel.org/io-uring/[email protected]/T/#u

Oh, I see now. Thanks for the feedback.

--
Gustavo