From: Bart Van Assche Date: Mon, 19 Mar 2018 00:36:33 +0000 (-0700) Subject: bcache: Fix a compiler warning in bcache_device_init() X-Git-Tag: v4.17-rc1~113^2~76 X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=5f2b18ec8e1643410a2369f06888951cdedea0bf;p=linux.git bcache: Fix a compiler warning in bcache_device_init() Avoid that building with W=1 triggers the following compiler warning: drivers/md/bcache/super.c:776:20: warning: comparison is always false due to limited range of data type [-Wtype-limits] d->nr_stripes > SIZE_MAX / sizeof(atomic_t)) { ^ Reviewed-by: Coly Li Reviewed-by: Michael Lyle Signed-off-by: Bart Van Assche Signed-off-by: Jens Axboe --- diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index 06f4b4833755..a21694788619 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -778,6 +778,8 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size, sector_t sectors) { struct request_queue *q; + const size_t max_stripes = min_t(size_t, INT_MAX, + SIZE_MAX / sizeof(atomic_t)); size_t n; int idx; @@ -786,9 +788,7 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size, d->nr_stripes = DIV_ROUND_UP_ULL(sectors, d->stripe_size); - if (!d->nr_stripes || - d->nr_stripes > INT_MAX || - d->nr_stripes > SIZE_MAX / sizeof(atomic_t)) { + if (!d->nr_stripes || d->nr_stripes > max_stripes) { pr_err("nr_stripes too large or invalid: %u (start sector beyond end of disk?)", (unsigned)d->nr_stripes); return -ENOMEM;