Skip to contentSkip to conversation

fs/pipe.c: merge if statements with identical conditions

PATCH In review Rasmus Villemoes 3 participants 4 messages Mar 7, 2025 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/pipe.c: merge if statements with identical conditions

As 'head' is not updated after head+1 is assigned to pipe->head, the condition being tested here is exactly the same as in the big if statement just above. Merge the two bodies.

---
 fs/pipe.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
fs/pipe.c +1 -3
index 097400cce241..27385e3e5417 100644
@@ -547,10 +547,8 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
 
 			if (!iov_iter_count(from))
 				break;
-		}
-
-		if (!pipe_full(head, pipe->tail, pipe->max_usage))
 			continue;
+		}
 
 		/* Wait for buffer space to become available. */
 		if ((filp->f_flags & O_NONBLOCK) ||
Signature · 1 line
2.48.1
#1 lore raw
Quoted 15 lines · Rasmus Villemoes

As 'head' is not updated after head+1 is assigned to pipe->head, the condition being tested here is exactly the same as in the big if statement just above. Merge the two bodies.

---
 fs/pipe.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
fs/pipe.c +0 -0
index 097400cce241..27385e3e5417 100644
@@ -547,10 +547,8 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
 

fs/pipe.c pipe_write(struct kiocb *iocb, struct iov_iter *from) · line 554

Quoted 10 lines
fs/pipe.c +1 -3
 			if (!iov_iter_count(from))
 				break;
-		}
-
-		if (!pipe_full(head, pipe->tail, pipe->max_usage))
 			continue;
+		}
 
 		/* Wait for buffer space to become available. */
 		if ((filp->f_flags & O_NONBLOCK) ||

I already posted this :)

It is hanging out in the vfs trees (and -next), see
https://lore.kernel.org/linux-fsdevel/[email protected]/

#2 lore raw
Quoted 24 lines · Mateusz Guzik
Quoted 23 lines · Rasmus Villemoes

As 'head' is not updated after head+1 is assigned to pipe->head, the condition being tested here is exactly the same as in the big if statement just above. Merge the two bodies.

---
 fs/pipe.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
fs/pipe.c +1 -3
index 097400cce241..27385e3e5417 100644
@@ -547,10 +547,8 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
 
 			if (!iov_iter_count(from))
 				break;
-		}
-
-		if (!pipe_full(head, pipe->tail, pipe->max_usage))
 			continue;
+		}
 
Quoted 5 lines

fs/pipe.c pipe_write(struct kiocb *iocb, struct iov_iter *from) · line 554

Quoted 2 lines
fs/pipe.c +0 -0
 		/* Wait for buffer space to become available. */
 		if ((filp->f_flags & O_NONBLOCK) ||

I already posted this :)

Ah, never mind then, also for that other patch I just sent. Just stumbled on those while trying to proof-read the pipe code.

Rasmus

#3 lore raw
In reply to Rasmus Villemoes
Quoted 4 lines · Rasmus Villemoes

As 'head' is not updated after head+1 is assigned to pipe->head, the condition being tested here is exactly the same as in the big if statement just above. Merge the two bodies.

Yes.

But Mateusz has already sent the same patch, please see

	[PATCH 1/3] pipe: drop an always true check in anon_pipe_write()
	https://lore.kernel.org/all/[email protected]/

Oleg.

Quoted 24 lines
---
 fs/pipe.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
fs/pipe.c +1 -4
index 097400cce241..27385e3e5417 100644
@@ -547,10 +547,8 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
 
 			if (!iov_iter_count(from))
 				break;
-		}
-
-		if (!pipe_full(head, pipe->tail, pipe->max_usage))
 			continue;
+		}
 
 		/* Wait for buffer space to become available. */
 		if ((filp->f_flags & O_NONBLOCK) ||
--

2.48.1