Re: [PATCH v1 1/2] lib/test_bitmap: Correct test data offsets for 32-bit
From: Yury Norov
Date: Wed Jan 08 2020 - 14:24:42 EST
On Wed, Jan 08, 2020 at 08:46:10PM +0200, Andy Shevchenko wrote:
> On 32-bit platform the size of long is only 32 bits which makes wrong offset
> in the array of 64 bit size.
>
> Calculate offset based on BITS_PER_LONG.
>
> Fixes: 30544ed5de43 ("lib/bitmap: introduce bitmap_replace() helper")
> Reported-by: Guenter Roeck <linux@xxxxxxxxxxxx>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
> ---
> lib/test_bitmap.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
> index 5cb35a734462..af522577a76e 100644
> --- a/lib/test_bitmap.c
> +++ b/lib/test_bitmap.c
> @@ -275,22 +275,23 @@ static void __init test_copy(void)
> static void __init test_replace(void)
> {
> unsigned int nbits = 64;
> + unsigned int step = DIV_ROUND_UP(nbits, BITS_PER_LONG);
Step is already defined in this file:
#define step (sizeof(u64) / sizeof(unsigned long))
to avoid the same problem in other test cases. Introducing another variant of
it looks messy.
> DECLARE_BITMAP(bmap, 1024);
>
> bitmap_zero(bmap, 1024);
> - bitmap_replace(bmap, &exp2[0], &exp2[1], exp2_to_exp3_mask, nbits);
> + bitmap_replace(bmap, &exp2[0 * step], &exp2[1 * step], exp2_to_exp3_mask, nbits);
> expect_eq_bitmap(bmap, exp3_0_1, nbits);
If nbits is always 64, why don't you pass 64 directly?
Yury
> bitmap_zero(bmap, 1024);
> - bitmap_replace(bmap, &exp2[1], &exp2[0], exp2_to_exp3_mask, nbits);
> + bitmap_replace(bmap, &exp2[1 * step], &exp2[0 * step], exp2_to_exp3_mask, nbits);
> expect_eq_bitmap(bmap, exp3_1_0, nbits);
>
> bitmap_fill(bmap, 1024);
> - bitmap_replace(bmap, &exp2[0], &exp2[1], exp2_to_exp3_mask, nbits);
> + bitmap_replace(bmap, &exp2[0 * step], &exp2[1 * step], exp2_to_exp3_mask, nbits);
> expect_eq_bitmap(bmap, exp3_0_1, nbits);
>
> bitmap_fill(bmap, 1024);
> - bitmap_replace(bmap, &exp2[1], &exp2[0], exp2_to_exp3_mask, nbits);
> + bitmap_replace(bmap, &exp2[1 * step], &exp2[0 * step], exp2_to_exp3_mask, nbits);
> expect_eq_bitmap(bmap, exp3_1_0, nbits);
> }
>
> --
> 2.24.1