]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: send: return -ENAMETOOLONG when attempting a path that is too long
authorFilipe Manana <fdmanana@suse.com>
Wed, 5 Feb 2025 13:09:25 +0000 (13:09 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 4 Jun 2025 12:37:56 +0000 (14:37 +0200)
[ Upstream commit a77749b3e21813566cea050bbb3414ae74562eba ]

When attempting to build a too long path we are currently returning
-ENOMEM, which is very odd and misleading. So update fs_path_ensure_buf()
to return -ENAMETOOLONG instead. Also, while at it, move the WARN_ON()
into the if statement's expression, as it makes it clear what is being
tested and also has the effect of adding 'unlikely' to the statement,
which allows the compiler to generate better code as this condition is
never expected to happen.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/send.c

index 577980b33aeb700441d1879c338e8ebf77c1f31f..a46076788bd7e6fb49b55e14b23ef06ddd23d5e2 100644 (file)
@@ -400,10 +400,8 @@ static int fs_path_ensure_buf(struct fs_path *p, int len)
        if (p->buf_len >= len)
                return 0;
 
-       if (len > PATH_MAX) {
-               WARN_ON(1);
-               return -ENOMEM;
-       }
+       if (WARN_ON(len > PATH_MAX))
+               return -ENAMETOOLONG;
 
        path_len = p->end - p->start;
        old_buf_len = p->buf_len;