On Wed, Aug 09, 2017 at 01:33:09PM -0700, Andrew Morton wrote:
> On Wed, 9 Aug 2017 11:28:56 +0800 kbuild test robot <l...@intel.com> wrote:
> 
> > [auto build test WARNING on linus/master]
> > [also build test WARNING on v4.13-rc4 next-20170808]
> > [if your patch is applied to the wrong git tree, please drop us a note to 
> > help improve the system]
> > 
> > url:    
> > https://github.com/0day-ci/linux/commits/Yury-Norov/lib-make-bitmap_parselist-thread-safe-and-much-faster/20170809-105307
> > config: i386-randconfig-x000-201732 (attached as .config)
> > compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
> > reproduce:
> >         # save the attached .config to linux build tree
> >         make ARCH=i386 
> > 
> > All warnings (new ones prefixed by >>):
> > 
> > >> lib/test_bitmap.c:180:17: warning: large integer implicitly truncated to 
> > >> unsigned type [-Woverflow]
> >         0xfffffffe, 0x3333333311111111, 0xffffffff77777777};
> >                     ^~~~~~~~~~~~~~~~~~
 
Ahh... I didn't take 32-bit arches into account...

> I assume that a simple convertion to unsigned long long will fix that,
> but I'll await Yuri's input (and testing).

The conversion to unsigned long long will work only for little endian
32-bit arches. We trapped into it once:
https://patchwork.kernel.org/patch/9260919+/

It should be the compile-time analogue of bitmap_from_u64()

The patch is attached and seems working to me. But I need some time
for testing...

Yury

>From be0e663b804daff0d0512e72cf94b5143270bd29 Mon Sep 17 00:00:00 2001
From: Yury Norov <yno...@caviumnetworks.com>
Date: Thu, 10 Aug 2017 01:25:46 +0300
Subject: [PATCH] bitmap: introduce BITMAP_FROM_U64() and use it in test for
 bitmap_parselist()

The macro is the compile-time analogue of bitmap_from_u64() with the
same purpose: convert the 64-bit number to the properly ordered pair
of 32-bit parts to be suitable for filling the bitmap.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 include/linux/bitmap.h |  6 ++++++
 lib/test_bitmap.c      | 23 +++++++++++++++++++----
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 5797ca6fdfe2..bdc487e47de1 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -378,6 +378,12 @@ static inline void bitmap_from_u64(unsigned long *dst, u64 
mask)
                dst[1] = mask >> 32;
 }
 
+#if __BITS_PER_LONG == 64
+#define BITMAP_FROM_U64(n) (n)
+#else
+#define BITMAP_FROM_U64(n) ((n) & ULONG_MAX), ((unsigned long long) (n) >> 32)
+#endif
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* __LINUX_BITMAP_H */
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index 5b80dd94e4d1..65b8fcc41fd0 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -175,10 +175,25 @@ struct test_bitmap_parselist{
        const int flags;
 };
 
-static const unsigned long exp[] = {1, 2, 0x0000ffff, 0xffff0000, 0x55555555,
-                               0xaaaaaaaa, 0x11111111, 0x22222222, 0xffffffff,
-                               0xfffffffe, 0x3333333311111111, 
0xffffffff77777777};
-static const unsigned long exp2[] = {0x3333333311111111, 0xffffffff77777777};
+static const unsigned long exp[] __initconst = {
+       BITMAP_FROM_U64(1),
+       BITMAP_FROM_U64(2),
+       BITMAP_FROM_U64(0x0000ffff),
+       BITMAP_FROM_U64(0xffff0000),
+       BITMAP_FROM_U64(0x55555555),
+       BITMAP_FROM_U64(0xaaaaaaaa),
+       BITMAP_FROM_U64(0x11111111),
+       BITMAP_FROM_U64(0x22222222),
+       BITMAP_FROM_U64(0xffffffff),
+       BITMAP_FROM_U64(0xfffffffe),
+       BITMAP_FROM_U64(0x3333333311111111),
+       BITMAP_FROM_U64(0xffffffff77777777)
+};
+
+static const unsigned long exp2[] __initconst = {
+       BITMAP_FROM_U64(0x3333333311111111),
+       BITMAP_FROM_U64(0xffffffff77777777)
+};
 
 static const struct test_bitmap_parselist parselist_tests[] __initconst = {
        {0, "0",                        &exp[0], 8, 0},
-- 
2.11.0

Reply via email to