lkml.org 
[lkml]   [2022]   [Jul]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 02/16] lib/bitmap: don't call bitmap_set() with len == 0
On Mon, Jul 18, 2022 at 12:28:30PM -0700, Yury Norov wrote:
> bitmap_parselist() format allows passing 0-length regions, but because
> len == 0 is not covered by small_const_nbits() macro, we have to call
> __bitmap_set() and do some prologue calculations just for nothing.

...

> static void bitmap_set_region(const struct region *r, unsigned long *bitmap)
> {
> - unsigned int start;
> + unsigned int start, len;
>
> - for (start = r->start; start <= r->end; start += r->group_len)
> - bitmap_set(bitmap, start, min(r->end - start + 1, r->off));
> + for (start = r->start; start <= r->end; start += r->group_len) {
> + len = min(r->end - start + 1, r->off);
> + if (len > 0)
> + bitmap_set(bitmap, start, len);

Maybe I'm missing something, but how small_const_nbits() can possible be useful
here? I mean in which cases the compiler would be able to prove that len is a
const with < sizeof(unsigned long) bits?

> + }
> }

--
With Best Regards,
Andy Shevchenko


\
 
 \ /
  Last update: 2022-07-18 23:08    [W:0.272 / U:0.076 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site