dm switch: simplify conditional in alloc_region_table()
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Wed, 28 Oct 2015 18:54:21 +0000 (03:54 +0900)
committerMike Snitzer <snitzer@redhat.com>
Sat, 31 Oct 2015 23:06:06 +0000 (19:06 -0400)
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 <kusumi.tomohiro@gmail.com>
Reviewed-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
drivers/md/dm-switch.c

index b1285753a5d44b87dd4dd4d8b1a60ea6403783bb..871c18fe000dfae2ef016ad64a5d8c4e0fc04e66 100644 (file)
@@ -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))