[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Y1Fp3oiUvmm8K1Ab@yury-laptop>
Date: Thu, 20 Oct 2022 08:31:42 -0700
From: Yury Norov <yury.norov@...il.com>
To: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc: Alexander Lobakin <alexandr.lobakin@...el.com>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Rasmus Villemoes <linux@...musvillemoes.dk>,
Michal Swiatkowski <michal.swiatkowski@...ux.intel.com>,
Maciej Fijalkowski <maciej.fijalkowski@...el.com>,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 net-next 2/6] bitmap: add a couple more helpers to
work with arrays of u32s
On Thu, Oct 20, 2022 at 04:18:08PM +0300, Andy Shevchenko wrote:
> On Wed, Oct 19, 2022 at 05:21:01PM -0700, Yury Norov wrote:
> > On Tue, Oct 18, 2022 at 04:00:23PM +0200, Alexander Lobakin wrote:
>
> ...
>
> > > +static inline size_t bitmap_arr32_size(size_t nbits)
> > > +{
> > > + return array_size(BITS_TO_U32(nbits), sizeof(u32));
> >
> > To me this looks simpler: round_up(nbits, 32) / BITS_PER_BYTE.
> > Can you check which generates better code?
>
> It's not only about better code, but also about overflow protection, which your
> proposal is missing.
Can you explain how this may overflow?
#define __round_mask(x, y) ((__typeof__(x))((y)-1))
#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
Thanks,
Yury
Powered by blists - more mailing lists