Re: [PATCH] libbpf: Fix is_pow_of_2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 06/22/2022 07:03 AM, Zvi Effron wrote:
On Sun, Jun 19, 2022 at 12:13 PM Pavel Machek <pavel@xxxxxx> wrote:

Hi!

From: Yuze Chi <chiyuze@xxxxxxxxxx>

+++ b/tools/lib/bpf/libbpf.c
@@ -4956,7 +4956,7 @@ static void bpf_map__destroy(struct bpf_map *map);

static bool is_pow_of_2(size_t x)
{
- return x && (x & (x - 1));
+ return x && !(x & (x - 1));
}

I'm pretty sure we have this test in macro in includes somewhere... should we use
that instead?

I went looking for a macro that provided this check and could not find one. I

arch/microblaze/mm/pgtable.c

#define is_power_of_2(x)	((x) != 0 && (((x) & ((x) - 1)) == 0))

did find the inlined static function is_power_of_2 in log2.h, though, that we
could use.

Here is a patch, but it seems that this is not worth the extra pain.

https://lore.kernel.org/bpf/8e5291b7-bd89-6fea-bfb7-954cacdb8523@xxxxxxxxxxxxx/

Thanks,
Tiezhu




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux