Re: fix int_sqrt() for very large numbers

From: Linus Torvalds
Date: Sun Jan 20 2019 - 00:11:37 EST


On Sun, Jan 20, 2019 at 5:03 PM Florian La Roche
<florian.laroche@xxxxxxxxxxxxxx> wrote:
>
> The real bug is that we compute 1 to 64 for bit 0 to bit 63, whereas
> the algorithm expects 0 to 63 for the value of m.

Florian, you seem to be in denial.

__fls() returns 0-63. Your patch is *wrong* for the __fls() use,
because when you subtract 1, you get -1 to 62, and the -1 now
introduces the very undefined behavior you claim your patch fixes.

So your patch fixes one real case (int_sqrt64(), that has one user
that doesn't care) but it *BREAKS* the other case that is actually
much more widely used (int_sqrt()).

See what Will and I are complainig about?

Linus