[dm-devel] [PATCH] dm raid: fix parse_raid_params() variable range issue
Mikulas Patocka
mpatocka at redhat.com
Mon Mar 19 20:24:52 UTC 2018
But on 32-bit architectures, INT_MAX is equivalent to LONG_MAX, so it
won't shut up the warning.
The question is - why should it depend on architecture at all? If 32-bit
values are enough, use int (and just delete the comparison with INT_MAX),
if you need 64-bit values, use long long or int64_t.
Mikulas
On Mon, 19 Mar 2018, Heinz Mauelshagen wrote:
> parse_raid_parames() compared variable "int value" with INT_MAX to
> prevent overflow of mddev variables set.
>
> Change type to "long value".
>
> Signed-off-by: Heinz Mauelshagen <heinzm at redhat.com>
> ---
> drivers/md/dm-raid.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
> index 335ebd46a986..7ffa1839b206 100644
> --- a/drivers/md/dm-raid.c
> +++ b/drivers/md/dm-raid.c
> @@ -1141,7 +1141,7 @@ static int validate_raid_redundancy(struct raid_set *rs)
> static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as,
> unsigned int num_raid_params)
> {
> - int value, raid10_format = ALGORITHM_RAID10_DEFAULT;
> + long value, raid10_format = ALGORITHM_RAID10_DEFAULT;
> unsigned int raid10_copies = 2;
> unsigned int i, write_mostly = 0;
> unsigned int region_size = 0;
> @@ -1153,7 +1153,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as,
> arg = dm_shift_arg(as);
> num_raid_params--; /* Account for chunk_size argument */
>
> - if (kstrtoint(arg, 10, &value) < 0) {
> + if (kstrtol(arg, 10, &value) < 0) {
> rs->ti->error = "Bad numerical argument given for chunk_size";
> return -EINVAL;
> }
> @@ -1315,7 +1315,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as,
> /*
> * Parameters with number values from here on.
> */
> - if (kstrtoint(arg, 10, &value) < 0) {
> + if (kstrtol(arg, 10, &value) < 0) {
> rs->ti->error = "Bad numerical argument given in raid params";
> return -EINVAL;
> }
> --
> 2.14.3
>
> --
> dm-devel mailing list
> dm-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/dm-devel
>
More information about the dm-devel
mailing list