dm-switch: Remove unnecessary condition in conditional
PATCH v2 1/1 dm-switch: Remove unnecessary condition in conditional
Quoted 7 lines
2015-10-28 8:03 GMT+09:00 Mikulas Patocka:
Quoted 3 lines · Tomohiro Kusumi
It's always (
sctx->nr_regions==nr_regions) considering the assignment right before this conditional, and this function is only used by .ctr.
Quoted 6 lines
The variable
sctx->nr_regionshas type unsigned long and the variablenr_regionshas typesector_t.Thus the variables may be different when overflow happens.
It could be changed to "if (
nr_regions>=ULONG_MAX)".
Sorry about that.
Changed the conditional to "if (nr_regions >= ULONG_MAX)", and brought the assignment of nr_regions after sector_div() and the sanity check which looks more sane.
--- drivers/md/dm-switch.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/md/dm-switch.c +2 -2
@@ -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))
Signature · 1 line
1.7.1
Quoted 14 lines · Tomohiro Kusumi
Quoted 7 lines
2015-10-28 8:03 GMT+09:00 Mikulas Patocka:
Quoted 3 lines · Tomohiro Kusumi
It's always (
sctx->nr_regions==nr_regions) considering the assignment right before this conditional, and this function is only used by .ctr.Quoted 6 lines
The variable
sctx->nr_regionshas type unsigned long and the variablenr_regionshas typesector_t.Thus the variables may be different when overflow happens.
It could be changed to "if (
nr_regions>=ULONG_MAX)".
Quoted 7 lines
Sorry about that.
Changed the conditional to "if (nr_regions>=ULONG_MAX)", and brought the assignment ofnr_regionsaftersector_div()and the sanity check which looks more sane.Signed-off-by Tomohiro Kusumi <[email protected]>Reviewed-by Mikulas Patocka <[email protected]>
Quoted 25 lines
--- drivers/md/dm-switch.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)drivers/md/dm-switch.c +2
-2@@ -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))Signature · 1 line
1.7.1