Linux EXT4 FS development
 help / color / mirror / Atom feed
From: Agatha Isabelle Moreira <code@agatha.dev>
To: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org,
	 linux-kernel@vger.kernel.org,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	 Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
	shuo chen <1289151713@qq.com>,
	 linux-kernel-mentees@lists.linux.dev, shuah@kernel.org,
	patch-reply@agatha.dev
Subject: [PATCH 1/2] fs: buffer: use clear_and_wake_up_bit() in unlock_buffer()
Date: Wed, 20 May 2026 16:58:16 -0300	[thread overview]
Message-ID: <ag4SD-mkmn5IbuN7@guidai> (raw)
In-Reply-To: <ag4PEP52c8rxrYPc@guidai>

Use `clear_and_wake_up_bit()` in `unlock_buffer()`, since the helper was
introduced in 'commit 8236b0ae31c83 ("bdi: wake up concurrent
wb_shutdown() callers.")' as a generic way of doing the same sequence of
operations:
       	clear_bit_unlock();
	smp_mb__after_atomic();
	wake_up_bit();

The helper was implemented to avoid bugs caused by forgetting to call
`wake_up_bit()` after `clear_bit_unlock()`.

Since `unlock_buffer()` predates git and was last modified in
'commit 4e857c58efeb9 ("arch: Mass conversion of smp_mb__*()")', years
before `clear_and_wake_up_bit()`, it still uses the open-coded sequence.

Replace the open-coded sequence with the helper to avoid duplicate code
and reduce code paths to maintain.

Suggested-by: shuo chen <1289151713@qq.com>
Link: https://lore.kernel.org/kernelnewbies/agzoqV835-co4kAN@guidai/T/#t
Signed-off-by: Agatha Isabelle Moreira <code@agatha.dev>
---
 fs/buffer.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index b0b3792b1496..4348b240bd97 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -74,9 +74,7 @@ EXPORT_SYMBOL(__lock_buffer);
 
 void unlock_buffer(struct buffer_head *bh)
 {
-	clear_bit_unlock(BH_Lock, &bh->b_state);
-	smp_mb__after_atomic();
-	wake_up_bit(&bh->b_state, BH_Lock);
+	clear_and_wake_up_bit(BH_Lock, &bh->b_state);
 }
 EXPORT_SYMBOL(unlock_buffer);
 
-- 
2.53.0


  reply	other threads:[~2026-05-20 20:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-20 19:45 [PATCH 0/2] fs: refactor code to use clear_and_wake_up_bit() Agatha Isabelle Moreira
2026-05-20 19:58 ` Agatha Isabelle Moreira [this message]
2026-05-20 20:05 ` [PATCH 2/2] fs: jbd2: use clear_and_wake_up_bit() in journal_end_buffer_io_sync() Agatha Isabelle Moreira
2026-05-22 13:14 ` [PATCH 0/2] fs: refactor code to use clear_and_wake_up_bit() Christian Brauner

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=ag4SD-mkmn5IbuN7@guidai \
    --to=code@agatha.dev \
    --cc=1289151713@qq.com \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel-mentees@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patch-reply@agatha.dev \
    --cc=shuah@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