From aad9ae4550755edc020b5c511a8b54f0104b2f47 Mon Sep 17 00:00:00 2001 From: Tomohiro Kusumi Date: Thu, 29 Oct 2015 03:54:21 +0900 Subject: dm switch: simplify conditional in alloc_region_table() 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. Changed the conditional to "if (nr_regions >= ULONG_MAX)". Also move the assignment of nr_regions after sector_div() and the sanity check which looks more sane. Signed-off-by: Tomohiro Kusumi Reviewed-by: Mikulas Patocka Signed-off-by: Mike Snitzer diff --git a/drivers/md/dm-switch.c b/drivers/md/dm-switch.c index b128575..871c18f 100644 --- a/drivers/md/dm-switch.c +++ b/drivers/md/dm-switch.c @@ -99,11 +99,11 @@ static int alloc_region_table(struct dm_target *ti, unsigned nr_paths) if (sector_div(nr_regions, sctx->region_size)) nr_regions++; - sctx->nr_regions = nr_regions; - if (sctx->nr_regions != nr_regions || sctx->nr_regions >= ULONG_MAX) { + if (nr_regions >= ULONG_MAX) { ti->error = "Region table too large"; return -EINVAL; } + sctx->nr_regions = nr_regions; nr_slots = nr_regions; if (sector_div(nr_slots, sctx->region_entries_per_slot)) -- cgit v0.10.2