Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752202AbdHJHae (ORCPT ); Thu, 10 Aug 2017 03:30:34 -0400 Received: from mail-ua0-f169.google.com ([209.85.217.169]:35568 "EHLO mail-ua0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751361AbdHJHad (ORCPT ); Thu, 10 Aug 2017 03:30:33 -0400 MIME-Version: 1.0 In-Reply-To: <20170809225231.ythrktk43gswfnjd@yury-thinkpad> References: <20170807225438.16161-2-ynorov@caviumnetworks.com> <201708091143.QqTgSaxI%fengguang.wu@intel.com> <20170809133309.746aafee5e22c9345debd671@linux-foundation.org> <20170809225231.ythrktk43gswfnjd@yury-thinkpad> From: Rasmus Villemoes Date: Thu, 10 Aug 2017 09:30:31 +0200 Message-ID: Subject: Re: [PATCH 2/2] lib: add test for bitmap_parselist() To: Yury Norov Cc: Andrew Morton , kbuild test robot , kbuild-all@01.org, Noam Camus , Matthew Wilcox , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1565 Lines: 39 > From be0e663b804daff0d0512e72cf94b5143270bd29 Mon Sep 17 00:00:00 2001 > From: Yury Norov > 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 > --- > 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 > + The 32 bit version probably needs to come in two flavours depending on little/big endian, no? Could you also throw in some casts so that the behaviour is consistent regardless of the type of the expression n, and so that both elements in the pair are guaranteed to have the same type (unsigned long, preferably, since that's what we're initializing). I.e., cast n to (u64), do arithmetic, cast result to (unsigned long).