diff options
author | David Sterba <dsterba@suse.com> | 2016-11-07 15:38:24 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-11-09 13:47:35 +0100 |
commit | c29fea434440d3fe9f21ccf320ff375c65f6d8a0 (patch) | |
tree | 3ba1c26dbdd08316fae40d0824660c89bca97d84 /utils.c | |
parent | 92847b5cd68d601b5ebadb74d17985b6421960bc (diff) |
btrfs-progs: use correct type for device id iteration in get_fs_info
Coverity reports (CID 1374096) that there's return value overflow of
ret from get_device_info, but this most likely cannot happen. There's
another minor issue where we use int to iterate over devids.
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 17 |
1 files changed, 7 insertions, 10 deletions
@@ -3084,7 +3084,7 @@ int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args, int fd = -1; int ret = 0; int ndevs = 0; - int i = 0; + u64 last_devid = 0; int replacing = 0; struct btrfs_fs_devices *fs_devices_mnt = NULL; struct btrfs_ioctl_dev_info_args *di_args; @@ -3097,7 +3097,6 @@ int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args, if (is_block_device(path) == 1) { struct btrfs_super_block *disk_super; char buf[BTRFS_SUPER_INFO_SIZE]; - u64 devid; /* Ensure it's mounted, then set path to the mountpoint */ fd = open(path, O_RDONLY); @@ -3125,10 +3124,8 @@ int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args, ret = -EIO; goto out; } - devid = btrfs_stack_device_id(&disk_super->dev_item); - - fi_args->max_id = devid; - i = devid; + last_devid = btrfs_stack_device_id(&disk_super->dev_item); + fi_args->max_id = last_devid; memcpy(fi_args->fsid, fs_devices_mnt->fsid, BTRFS_FSID_SIZE); close(fd); @@ -3165,8 +3162,8 @@ int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args, fi_args->num_devices++; ndevs++; replacing = 1; - if (i == 0) - i++; + if (last_devid == 0) + last_devid++; } } @@ -3181,8 +3178,8 @@ int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args, if (replacing) memcpy(di_args, &tmp, sizeof(tmp)); - for (; i <= fi_args->max_id; ++i) { - ret = get_device_info(fd, i, &di_args[ndevs]); + for (; last_devid <= fi_args->max_id; last_devid++) { + ret = get_device_info(fd, last_devid, &di_args[ndevs]); if (ret == -ENODEV) continue; if (ret) |