mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] include/log2.h: Fix rounddown_pow_of_two(1)
@ 2011-11-16 19:56 Andrei Warkentin
  2011-11-16 22:51 ` Rolf Eike Beer
  2011-11-17 23:05 ` Andrew Morton
  0 siblings, 2 replies; 8+ messages in thread
From: Andrei Warkentin @ 2011-11-16 19:56 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrei Warkentin, Rolf Eike Beer, opensuse-kernel

1 is a power of two, therefore rounddown_pow_of_two(1) should return 1. It does
in case the argument is a variable but in case it's a constant it behaves
wrong and returns 0. Probably nobody ever did it so this was never noticed,
however net/drivers/vmxnet3 with latest GCC does and breaks on unicpu systems.

This is similar to Rolf's patch to roundup_pow_of_two(1).

Cc: Rolf Eike Beer <eike-kernel@sf-tec.de>
Cc: opensuse-kernel@opensuse.org
Reviewed-by: Jesper Juhl <jj@chaosbits.net>
Signed-off-by: Andrei Warkentin <andreiw@vmware.com>
---
 include/linux/log2.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/include/linux/log2.h b/include/linux/log2.h
index 25b8086..ccda848 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -185,7 +185,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
 #define rounddown_pow_of_two(n)			\
 (						\
 	__builtin_constant_p(n) ? (		\
-		(n == 1) ? 0 :			\
+		(n == 1) ? 1 :			\
 		(1UL << ilog2(n))) :		\
 	__rounddown_pow_of_two(n)		\
  )
-- 
1.7.4.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-11-22 23:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-16 19:56 [PATCH] include/log2.h: Fix rounddown_pow_of_two(1) Andrei Warkentin
2011-11-16 22:51 ` Rolf Eike Beer
2011-11-17 23:05 ` Andrew Morton
2011-11-17 23:19   ` [opensuse-kernel] " Cristian Rodríguez
2011-11-17 23:32     ` Andrew Morton
2011-11-18 18:46   ` Andrei Warkentin
2011-11-19  9:26   ` Marco Stornelli
2011-11-22 23:34   ` Guennadi Liakhovetski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome