mm-commits.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [merged] log2-make-order_base_2-behave-correctly-on-const-input-value-zero.patch removed from -mm tree
@ 2017-02-03 20:05 akpm
  0 siblings, 0 replies; only message in thread
From: akpm @ 2017-02-03 20:05 UTC (permalink / raw)
  To: ard.biesheuvel, gregory.clement, james.greenhalgh, labbott,
	markus, mingo, peterz, sboyd, will.deacon, mm-commits


The patch titled
     Subject: log2: make order_base_2() behave correctly on const input value zero
has been removed from the -mm tree.  Its filename was
     log2-make-order_base_2-behave-correctly-on-const-input-value-zero.patch

This patch was dropped because it was merged into mainline or a subsystem tree

------------------------------------------------------
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: log2: make order_base_2() behave correctly on const input value zero

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.

Link: http://lkml.kernel.org/r/1486058726-7262-1-git-send-email-ard.biesheuvel@linaro.org
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Laura Abbott <labbott@fedoraproject.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Stephen Boyd <sboyd@codeaurora.org>
Cc: Gregory CLEMENT <gregory.clement@free-electrons.com>
Cc: James Greenlaigh <james.greenhalgh@arm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Markus Trippelsdorf <markus@trippelsdorf.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 include/linux/log2.h |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff -puN include/linux/log2.h~log2-make-order_base_2-behave-correctly-on-const-input-value-zero include/linux/log2.h
--- a/include/linux/log2.h~log2-make-order_base_2-behave-correctly-on-const-input-value-zero
+++ a/include/linux/log2.h
@@ -203,6 +203,17 @@ unsigned long __rounddown_pow_of_two(uns
  *  ... and so on.
  */
 
-#define order_base_2(n) ilog2(roundup_pow_of_two(n))
+static inline __attribute_const__
+int __order_base_2(unsigned long n)
+{
+	return n > 1 ? ilog2(n - 1) + 1 : 0;
+}
 
+#define order_base_2(n)				\
+(						\
+	__builtin_constant_p(n) ? (		\
+		((n) == 0 || (n) == 1) ? 0 :	\
+		ilog2((n) - 1) + 1) :		\
+	__order_base_2(n)			\
+)
 #endif /* _LINUX_LOG2_H */
_

Patches currently in -mm which might be from ard.biesheuvel@linaro.org are



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-02-03 20:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-03 20:05 [merged] log2-make-order_base_2-behave-correctly-on-const-input-value-zero.patch removed from -mm tree akpm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).