Re: [PATCH] um: remove uses of variable length arrays

From: Geert Uytterhoeven
Date: Wed Mar 13 2019 - 06:11:23 EST


Hi Bartosz,

On Wed, Mar 13, 2019 at 10:50 AM Bartosz Golaszewski <brgl@xxxxxxxx> wrote:
> År., 13 mar 2019 o 10:45 Anton Ivanov
> <anton.ivanov@xxxxxxxxxxxxxxxxxx> napisaÅ(a):
> > PID can be more than 5 digits nowdays.
>
> Do we have a macro in the kernel that yields the minimum size of an
> array to fit a number? I can't find it. I vagely remember seeing
> something like this in systemd tree. If it doesn't exist in the kernel
> then maybe we should copy it over.

1 + const_ilog2(n) / log2(10) = 1 + const_ilog2(n) / 3.321928

Using fixed point calculations, that can be approximated as

1 + 19728 * const_ilog2(n) >> 16
1 + 77 * const_ilog2(n) >> 8

(the factors might be one off)

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds