diff options
author | Tomohiro Kusumi <kusumi.tomohiro@gmail.com> | 2015-10-29 03:54:21 +0900 |
---|---|---|
committer | Mike Snitzer <snitzer@redhat.com> | 2015-10-31 19:06:06 -0400 |
commit | aad9ae4550755edc020b5c511a8b54f0104b2f47 (patch) | |
tree | a94ce06ad5d8fe99c92a09c80ed60c7d8c8882a6 | |
parent | f49e869a61829b8ac6eb069b3824f738cd0146e6 (diff) | |
download | blackbird-op-linux-aad9ae4550755edc020b5c511a8b54f0104b2f47.tar.gz blackbird-op-linux-aad9ae4550755edc020b5c511a8b54f0104b2f47.zip |
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 <kusumi.tomohiro@gmail.com>
Reviewed-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
-rw-r--r-- | drivers/md/dm-switch.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/md/dm-switch.c b/drivers/md/dm-switch.c index b1285753a5d4..871c18fe000d 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)) |