log2: make order_base_2() behave correctly on const input value zero 92/220292/1
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Thu, 2 Feb 2017 18:05:26 +0000 (18:05 +0000)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Mon, 16 Dec 2019 09:53:30 +0000 (18:53 +0900)
commit5211ba925db18269f233c57fa6c520a9409e7dad
treefd7c24daa29abc81db745a7d35795cf6323d7ae6
parent2d34a601cda508b11cdcbd1d2ccdc40d38bee716
log2: make order_base_2() behave correctly on const input value zero

commit 29905b52fad0854351f57bab867647e4982285bf upstream.

The function order_base_2() is defined (according to the comment block)
as returning zero on input zero, but subsequently passes the input into
roundup_pow_of_two(), which is explicitly undefined for input zero.

This has gone unnoticed until now, but optimization passes in GCC 7 may
produce constant folded function instances where a constant value of
zero is passed into order_base_2(), resulting in link errors against the
deliberately undefined '____ilog2_NaN'.

So update order_base_2() to adhere to its own documented interface.

[ See

     http://marc.info/?l=linux-kernel&m=147672952517795&w=2

  and follow-up discussion for more background. The gcc "optimization
  pass" is really just broken, but now the GCC trunk problem seems to
  have escaped out of just specially built daily images, so we need to
  work around it in mainline.    - Linus ]

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[sw0312.kim: cherry-pick stable linux-3.18.y commit 9fc9f9a8df55 for gcc 9 build]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I0e7956187e41545bbe9ece88dedef91436c876e9
include/linux/log2.h