Re: more potential janitor work: simplifying test for power of 2

Robert P. J. Day
2026-04-02T13:20:06Z

On Thu, 2 Apr 2026, Linus Probert wrote:

... snip ...

> I was asking and appreciate the suggestions. If you have more stuff
> knocking about I'm certain it will be appreciated by some of us
> neophytes.

IMHO, i'll repeat that simplifying code that manually determines the
length of an array could be simplified based on
include/linux/array_size.h:

/**
* ARRAY_SIZE - get the number of elements in array @arr
* @arr: array to be sized
*/
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))

/**
* ARRAY_END - get a pointer to one past the last element in array @arr
* @arr: array
*/
#define ARRAY_END(arr) (&(arr)[ARRAY_SIZE(arr)])

there's *tons* of that all over the place.

rday