]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
kernel/watch_queue: Use pipe_buf() to retrieve the pipe buffer
authorK Prateek Nayak <kprateek.nayak@amd.com>
Fri, 7 Mar 2025 05:29:17 +0000 (05:29 +0000)
committerChristian Brauner <brauner@kernel.org>
Mon, 10 Mar 2025 07:55:05 +0000 (08:55 +0100)
Use pipe_buf() helper to retrieve the pipe buffer in
post_one_notification() 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-3-kprateek.nayak@amd.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
kernel/watch_queue.c

index 5267adeaa403456ba80473e6a9584fdddfe1b939..605129eb61a19920e058af0ade3884387b518908 100644 (file)
@@ -101,12 +101,11 @@ static bool post_one_notification(struct watch_queue *wqueue,
        struct pipe_inode_info *pipe = wqueue->pipe;
        struct pipe_buffer *buf;
        struct page *page;
-       unsigned int head, tail, mask, note, offset, len;
+       unsigned int head, tail, note, offset, len;
        bool done = false;
 
        spin_lock_irq(&pipe->rd_wait.lock);
 
-       mask = pipe->ring_size - 1;
        head = pipe->head;
        tail = pipe->tail;
        if (pipe_full(head, tail, pipe->ring_size))
@@ -124,7 +123,7 @@ static bool post_one_notification(struct watch_queue *wqueue,
        memcpy(p + offset, n, len);
        kunmap_atomic(p);
 
-       buf = &pipe->bufs[head & mask];
+       buf = pipe_buf(pipe, head);
        buf->page = page;
        buf->private = (unsigned long)wqueue;
        buf->ops = &watch_queue_pipe_buf_ops;
@@ -147,7 +146,7 @@ out:
        return done;
 
 lost:
-       buf = &pipe->bufs[(head - 1) & mask];
+       buf = pipe_buf(pipe, head - 1);
        buf->flags |= PIPE_BUF_FLAG_LOSS;
        goto out;
 }