linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kemeng Shi <shikemeng@huaweicloud.com>
To: viro@zeniv.linux.org.uk, brauner@kernel.org, dhowells@redhat.com
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] pipe: remove pipe_full check with wrong head in pipe_write
Date: Fri, 29 Sep 2023 00:17:51 +0800	[thread overview]
Message-ID: <20230928161752.142268-2-shikemeng@huaweicloud.com> (raw)
In-Reply-To: <20230928161752.142268-1-shikemeng@huaweicloud.com>

In pipe_write we have:
	head = pipe->head;
	if (!pipe_full(head, pipe->tail, pipe->max_usage))
		pipe->head = head + 1;
		/* write data to buffer at head */

	/* supposed to check if pipe is full after write */
	if (!pipe_full(head, pipe->tail, pipe->max_usage))
		continue

The second pipe_full expects head after write but head before write is
used. Luckily, we will call pipe_full with correct reloaded pipe->head
in new loop cycle and stop writing correctly. Remove wrong pipe_full
check and simply continue to first pipe_full check after write done to
avoid unnecessary check.

Fixes: a194dfe6e6f6 ("pipe: Rearrange sequence in pipe_write() to preallocate slot")
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 fs/pipe.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/pipe.c b/fs/pipe.c
index 2d88f73f585a..b19875720ff1 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -542,10 +542,9 @@ 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.30.0


  reply	other threads:[~2023-09-28  8:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-28 16:17 [PATCH 0/2] Two cleanups to pipe Kemeng Shi
2023-09-28 16:17 ` Kemeng Shi [this message]
2023-09-28 16:17 ` [PATCH 2/2] pipe: avoid repeat check of pipe->readers with pipe lock held Kemeng Shi
  -- strict thread matches above, loose matches on Subject: below --
2023-10-08  9:47 [PATCH 0/2] Two cleanups to pipe Kemeng Shi
2023-10-08  9:48 ` [PATCH 1/2] pipe: remove pipe_full check with wrong head in pipe_write Kemeng Shi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230928161752.142268-2-shikemeng@huaweicloud.com \
    --to=shikemeng@huaweicloud.com \
    --cc=brauner@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).