Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aad9ae45 authored by Tomohiro Kusumi's avatar Tomohiro Kusumi Committed by Mike Snitzer
Browse files

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: default avatarTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Reviewed-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
parent f49e869a
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -99,11 +99,11 @@ static int alloc_region_table(struct dm_target *ti, unsigned nr_paths)
	if (sector_div(nr_regions, sctx->region_size))
	if (sector_div(nr_regions, sctx->region_size))
		nr_regions++;
		nr_regions++;


	sctx->nr_regions = nr_regions;
	if (nr_regions >= ULONG_MAX) {
	if (sctx->nr_regions != nr_regions || sctx->nr_regions >= ULONG_MAX) {
		ti->error = "Region table too large";
		ti->error = "Region table too large";
		return -EINVAL;
		return -EINVAL;
	}
	}
	sctx->nr_regions = nr_regions;


	nr_slots = nr_regions;
	nr_slots = nr_regions;
	if (sector_div(nr_slots, sctx->region_entries_per_slot))
	if (sector_div(nr_slots, sctx->region_entries_per_slot))