btrfs: return real error from __filemap_get_folio() calls
authorFilipe Manana <fdmanana@suse.com>
Sat, 10 May 2025 12:59:54 +0000 (13:59 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 15 May 2025 12:30:57 +0000 (14:30 +0200)
We have a few places that always assume a -ENOMEM error happened in case a
call to __filemap_get_folio() returns an error, which is just too much of
an assumption and even if it would be the case at some point in time, it's
not future proof and there's nothing in the documentation that guarantees
that only ERR_PTR(-ENOMEM) can be returned with the flags we are passing
to it.

So use the exact error returned by __filemap_get_folio() instead.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/free-space-cache.c
fs/btrfs/inode.c
fs/btrfs/reflink.c

index 18496ebdee9d3fad305b4dc1557b2b51dbd53368..4b34ea1f01c2a929ce1ad3ffa02019a2cd4dc9fb 100644 (file)
@@ -457,7 +457,7 @@ static int io_ctl_prepare_pages(struct btrfs_io_ctl *io_ctl, bool uptodate)
                                            mask);
                if (IS_ERR(folio)) {
                        io_ctl_drop_pages(io_ctl);
-                       return -ENOMEM;
+                       return PTR_ERR(folio);
                }
 
                ret = set_folio_extent_mapped(folio);
index b189371c142fa13f195fb38682596784e7359bdc..c0c778243bf124cc49714534e6d29aca8782ed63 100644 (file)
@@ -4937,7 +4937,7 @@ again:
                        btrfs_delalloc_release_space(inode, data_reserved,
                                                     block_start, blocksize, true);
                btrfs_delalloc_release_extents(inode, blocksize);
-               ret = -ENOMEM;
+               ret = PTR_ERR(folio);
                goto out;
        }
 
index 42c268dba11deeb0f022aa0f3f33d6112801cce6..62161beca5590359bf916386cbff5a298074a9ee 100644 (file)
@@ -87,7 +87,7 @@ static int copy_inline_to_page(struct btrfs_inode *inode,
                                        FGP_LOCK | FGP_ACCESSED | FGP_CREAT,
                                        btrfs_alloc_write_mask(mapping));
        if (IS_ERR(folio)) {
-               ret = -ENOMEM;
+               ret = PTR_ERR(folio);
                goto out_unlock;
        }