diff mbox series

Lock page before checking for subpage in btrfs_subpage_start_writer_lock()

Message ID xzakhkmqeav3ffk52ywudw6mx3l5ewwdrlyetnu55kht744gvl@awcq4gf4mee5 (mailing list archive)
State New, archived
Headers show
Series Lock page before checking for subpage in btrfs_subpage_start_writer_lock() | expand

Commit Message

Goldwyn Rodrigues Sept. 9, 2024, 11:26 p.m. UTC
btrfs_subpage_start_writer_lock() locks the folio before
returning. The function checks the condition if it needs to process
subpage and then locks and returns 0.

Instead, first lock the folio and then check for subpage. This avoids
calling folio_lock() before returning.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
diff mbox series

Patch

diff --git a/fs/btrfs/subpage.c b/fs/btrfs/subpage.c
index ca7d2aedfa8d..1b501db14db0 100644
--- a/fs/btrfs/subpage.c
+++ b/fs/btrfs/subpage.c
@@ -361,11 +361,11 @@  static bool btrfs_subpage_end_and_test_writer(const struct btrfs_fs_info *fs_inf
 int btrfs_folio_start_writer_lock(const struct btrfs_fs_info *fs_info,
 				  struct folio *folio, u64 start, u32 len)
 {
-	if (unlikely(!fs_info) || !btrfs_is_subpage(fs_info, folio->mapping)) {
-		folio_lock(folio);
-		return 0;
-	}
 	folio_lock(folio);
+
+	if (unlikely(!fs_info) || !btrfs_is_subpage(fs_info, folio->mapping))
+		return 0;
+
 	if (!folio_test_private(folio) || !folio_get_private(folio)) {
 		folio_unlock(folio);
 		return -EAGAIN;