]> git.hungrycats.org Git - btrfs-progs/commitdiff
btrfs-progs: fix assigning negative errno
authorDavid Sterba <dsterba@suse.com>
Thu, 23 Jul 2026 09:52:47 +0000 (11:52 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 3 Aug 2026 10:59:15 +0000 (12:59 +0200)
As we use negative errno in many places, there were two conversion that
assigned a negative value there, which is wrong.

Note that in many other places we do 'errno = ret' but that's for
pthread_* or posix_memalign() functions that return errno directly.

Signed-off-by: David Sterba <dsterba@suse.com>
cmds/subvolume.c
image/common.c

index 7aeeba6d94289cb4246dc29f03ce561c5e356880..7f8a414166eb6db716a9f42cb681fec3a53115cb 100644 (file)
@@ -178,7 +178,7 @@ static int create_one_subvolume(const char *dst, struct btrfs_util_qgroup_inheri
                        } else if (ret <= 0) {
                                if (ret == 0)
                                        ret = -EEXIST;
-                               errno = ret ;
+                               errno = -ret ;
                                error("failed to check directory %s before creation: %m", p);
                                goto out;
                        }
index 8c7a8efe2c8f7bdb4e440aa6d4829ecc91833b6d..e6396394bd08e5c37f8a6ee70ac5d09c64672c0f 100644 (file)
@@ -218,12 +218,10 @@ int update_disk_super_on_device(struct btrfs_fs_info *info,
 
        ret = pwrite(fp, &disk_super, BTRFS_SUPER_INFO_SIZE, BTRFS_SUPER_INFO_OFFSET);
        if (ret != BTRFS_SUPER_INFO_SIZE) {
-               if (ret < 0) {
-                       errno = ret;
+               if (ret < 0)
                        error("cannot write superblock: %m");
-               } else {
+               else
                        error("cannot write superblock");
-               }
                ret = -EIO;
                goto out;
        }