* Re: [PATCH] dm-raid: fix bug when round up region_size
@ 2014-09-30 11:00 heinzm
2014-09-30 12:30 ` NeilBrown
0 siblings, 1 reply; 2+ messages in thread
From: heinzm @ 2014-09-30 11:00 UTC (permalink / raw)
To: dm-devel; +Cc: Heinz Mauelshagen
From: Heinz Mauelshagen <heinzm@redhat.com>
Liong,
thanks for the catch.
Introduced minor modification utilizing the is_power_of_2() inline.
---
If region_size is not supplied by userspace and the device is very
large, there is a bug in current code preventing region_size from being
correctly set.
Signed-off-by: Lidong Zhong <lzhong@suse.com>
Acked-by: Heinz Mauelshagen <heinzm@redhat.com>
Tested-by: Heinz Mauelshagen <heinzm@redhat.com>
---
drivers/md/dm-raid.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
index 4880b69..264aef4 100644
--- a/drivers/md/dm-raid.c
+++ b/drivers/md/dm-raid.c
@@ -325,8 +325,10 @@ static int validate_region_size(struct raid_set *rs, unsigned long region_size)
*/
if (min_region_size > (1 << 13)) {
/* If not a power of 2, make it the next power of 2 */
- if (min_region_size & (min_region_size - 1))
- region_size = 1 << fls(region_size);
+ if (is_power_of_2(min_region_size))
+ region_size = min_region_size;
+ else
+ region_size = 1 << fls(min_region_size);
DMINFO("Choosing default region size of %lu sectors",
region_size);
} else {
--
1.9.3
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] dm-raid: fix bug when round up region_size
2014-09-30 11:00 [PATCH] dm-raid: fix bug when round up region_size heinzm
@ 2014-09-30 12:30 ` NeilBrown
0 siblings, 0 replies; 2+ messages in thread
From: NeilBrown @ 2014-09-30 12:30 UTC (permalink / raw)
To: heinzm; +Cc: dm-devel
[-- Attachment #1.1: Type: text/plain, Size: 1556 bytes --]
On Tue, 30 Sep 2014 13:00:36 +0200 heinzm@redhat.com wrote:
> From: Heinz Mauelshagen <heinzm@redhat.com>
>
> Liong,
> thanks for the catch.
> Introduced minor modification utilizing the is_power_of_2() inline.
>
> ---
>
> If region_size is not supplied by userspace and the device is very
> large, there is a bug in current code preventing region_size from being
> correctly set.
>
>
> Signed-off-by: Lidong Zhong <lzhong@suse.com>
> Acked-by: Heinz Mauelshagen <heinzm@redhat.com>
> Tested-by: Heinz Mauelshagen <heinzm@redhat.com>
>
> ---
> drivers/md/dm-raid.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
> index 4880b69..264aef4 100644
> --- a/drivers/md/dm-raid.c
> +++ b/drivers/md/dm-raid.c
> @@ -325,8 +325,10 @@ static int validate_region_size(struct raid_set *rs, unsigned long region_size)
> */
> if (min_region_size > (1 << 13)) {
> /* If not a power of 2, make it the next power of 2 */
> - if (min_region_size & (min_region_size - 1))
> - region_size = 1 << fls(region_size);
> + if (is_power_of_2(min_region_size))
> + region_size = min_region_size;
> + else
> + region_size = 1 << fls(min_region_size);
> DMINFO("Choosing default region size of %lu sectors",
> region_size);
> } else {
If you really wanted to optimize, you could just do
region_size = roundup_pow_of_two(min_region_size);
there is all sorts of cool stuff in log2.h !!
NeilBrown
[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 828 bytes --]
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-09-30 12:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-30 11:00 [PATCH] dm-raid: fix bug when round up region_size heinzm
2014-09-30 12:30 ` NeilBrown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox