]> git.baikalelectronics.ru Git - kernel.git/commit
fix int_sqrt64() for very large numbers
authorFlorian La Roche <florian.laroche@googlemail.com>
Sat, 19 Jan 2019 15:14:50 +0000 (16:14 +0100)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 20 Jan 2019 18:20:18 +0000 (07:20 +1300)
commit1096e8a43b8fe577210ccc9fc6aa61f063b5c468
tree3af0a2fd574c28337083e5db0971fc4f1defe492
parent1eaf4d789add7e79a29fd520addb715b173e39e4
fix int_sqrt64() for very large numbers

If an input number x for int_sqrt64() has the highest bit set, then
fls64(x) is 64.  (1UL << 64) is an overflow and breaks the algorithm.

Subtracting 1 is a better guess for the initial value of m anyway and
that's what also done in int_sqrt() implicitly [*].

[*] Note how int_sqrt() uses __fls() with two underscores, which already
    returns the proper raw bit number.

    In contrast, int_sqrt64() used fls64(), and that returns bit numbers
    illogically starting at 1, because of error handling for the "no
    bits set" case. Will points out that he bug probably is due to a
    copy-and-paste error from the regular int_sqrt() case.

Signed-off-by: Florian La Roche <Florian.LaRoche@googlemail.com>
Acked-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
lib/int_sqrt.c