[dm-devel] [PATCH 5/6] dm-switch: Remove unnecessary condition in conditional

Mikulas Patocka mpatocka at redhat.com
Tue Oct 27 23:03:39 UTC 2015



On Wed, 28 Oct 2015, Tomohiro Kusumi wrote:

> It's always (sctx->nr_regions == nr_regions) considering
> the assignment right before this conditional, and this
> function is only used by .ctr.

The variable sctx->nr_regions has type unsigned long and the variable 
nr_regions has type sector_t.

Thus the variables may be different when overflow happens.

It could be changed to "if (nr_regions >= ULONG_MAX)".

Mikulas

> Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro at gmail.com>
> ---
>  drivers/md/dm-switch.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/md/dm-switch.c b/drivers/md/dm-switch.c
> index 50fca46..372ec34 100644
> --- a/drivers/md/dm-switch.c
> +++ b/drivers/md/dm-switch.c
> @@ -100,7 +100,7 @@ static int alloc_region_table(struct dm_target *ti, unsigned nr_paths)
>  		nr_regions++;
>  
>  	sctx->nr_regions = nr_regions;
> -	if (sctx->nr_regions != nr_regions || sctx->nr_regions >= ULONG_MAX) {
> +	if (sctx->nr_regions >= ULONG_MAX) {
>  		ti->error = "Region table too large";
>  		return -EINVAL;
>  	}
> -- 
> 1.7.1
> 




More information about the dm-devel mailing list