mirror of
https://github.com/kdave/btrfs-progs
synced 2024-12-23 22:53:35 +00:00
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>
This commit is contained in:
parent
92847b5cd6
commit
c29fea4344
17
utils.c
17
utils.c
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user