@@ -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;
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>