Skip to content

Commit ba08220

Browse files
kudureranganathbrauner
authored andcommitted
fs/pipe: Use pipe_buf() helper to retrieve pipe buffer
Use pipe_buf() helper to retrieve the pipe buffer throughout the file replacing the open-coded the logic. Suggested-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com> Link: https://lore.kernel.org/r/20250307052919.34542-4-kprateek.nayak@amd.com Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 5474760 commit ba08220

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

fs/pipe.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
274274
/* Read ->head with a barrier vs post_one_notification() */
275275
unsigned int head = smp_load_acquire(&pipe->head);
276276
unsigned int tail = pipe->tail;
277-
unsigned int mask = pipe->ring_size - 1;
278277

279278
#ifdef CONFIG_WATCH_QUEUE
280279
if (pipe->note_loss) {
@@ -301,7 +300,7 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
301300
#endif
302301

303302
if (!pipe_empty(head, tail)) {
304-
struct pipe_buffer *buf = &pipe->bufs[tail & mask];
303+
struct pipe_buffer *buf = pipe_buf(pipe, tail);
305304
size_t chars = buf->len;
306305
size_t written;
307306
int error;
@@ -471,8 +470,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
471470
was_empty = pipe_empty(head, pipe->tail);
472471
chars = total_len & (PAGE_SIZE-1);
473472
if (chars && !was_empty) {
474-
unsigned int mask = pipe->ring_size - 1;
475-
struct pipe_buffer *buf = &pipe->bufs[(head - 1) & mask];
473+
struct pipe_buffer *buf = pipe_buf(pipe, head - 1);
476474
int offset = buf->offset + buf->len;
477475

478476
if ((buf->flags & PIPE_BUF_FLAG_CAN_MERGE) &&
@@ -503,7 +501,6 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
503501

504502
head = pipe->head;
505503
if (!pipe_full(head, pipe->tail, pipe->max_usage)) {
506-
unsigned int mask = pipe->ring_size - 1;
507504
struct pipe_buffer *buf;
508505
struct page *page = pipe->tmp_page;
509506
int copied;
@@ -525,7 +522,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
525522
pipe->head = head + 1;
526523

527524
/* Insert it into the buffer array */
528-
buf = &pipe->bufs[head & mask];
525+
buf = pipe_buf(pipe, head);
529526
buf->page = page;
530527
buf->ops = &anon_pipe_buf_ops;
531528
buf->offset = 0;

0 commit comments

Comments
 (0)