From: David Howells <dhowells@redhat.com>
To: torvalds@linux-foundation.org, akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, David Howells <dhowells@redhat.com>,
"Robert P. J. Day" <rpjday@crashcourse.ca>,
stable@kernel.org
Subject: [PATCH] Fix order_base_2(0) [ver #2]
Date: Thu, 15 Dec 2011 12:55:38 +0000 [thread overview]
Message-ID: <20111215125538.2838.41548.stgit@warthog.procyon.org.uk> (raw)
The order_base_2() function is either wrongly documented or wrongly
implemented. In the preceding comment, it says that:
ob2(0) = 0
but this is not valid as roundup_pow_of_two()'s documentation asserts that:
* - the result is undefined when n == 0
Remove the bit of comment that says order_base_2(0) returns 0.
Add comments to order_base_2() and other functions in the same header file to
indicate that the result is undefined if n <= 0. Note that it is possible to
give ilog2() a negative number if passing a constant value and this will result
in a compilation failure (it'll try and reference ____ilog2_NaN because n < 1).
Also, whilst we're at it, stick brackets around the body of order_base_2().
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Robert P. J. Day <rpjday@crashcourse.ca>
cc: stable@kernel.org
---
include/linux/log2.h | 12 +++++++-----
1 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/include/linux/log2.h b/include/linux/log2.h
index fd7ff3d..358620d 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -81,6 +81,8 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
* the massive ternary operator construction
*
* selects the appropriately-sized optimised version depending on sizeof(n)
+ *
+ * The result is undefined if n <= 0.
*/
#define ilog2(n) \
( \
@@ -162,7 +164,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
* @n - parameter
*
* round the given value up to the nearest power of two
- * - the result is undefined when n == 0
+ * - the result is undefined when n <= 0
* - this can be used to initialise global variables from constant data
*/
#define roundup_pow_of_two(n) \
@@ -179,7 +181,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
* @n - parameter
*
* round the given value down to the nearest power of two
- * - the result is undefined when n == 0
+ * - the result is undefined when n <= 0
* - this can be used to initialise global variables from constant data
*/
#define rounddown_pow_of_two(n) \
@@ -194,15 +196,15 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
* @n: parameter
*
* The first few values calculated by this routine:
- * ob2(0) = 0
* ob2(1) = 0
* ob2(2) = 1
* ob2(3) = 2
* ob2(4) = 2
* ob2(5) = 3
* ... and so on.
+ *
+ * The result is undefined if n <= 0.
*/
-
-#define order_base_2(n) ilog2(roundup_pow_of_two(n))
+#define order_base_2(n) (ilog2(roundup_pow_of_two(n)))
#endif /* _LINUX_LOG2_H */
reply other threads:[~2011-12-15 12:55 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111215125538.2838.41548.stgit@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rpjday@crashcourse.ca \
--cc=stable@kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®