All of lore.kernel.org
 help / color / mirror / Atom feed
From: akpm@linux-foundation.org
To: rdreier@cisco.com, rolandd@cisco.com, mm-commits@vger.kernel.org
Subject: [to-be-updated] kernelh-add-build_bug_on_not_power_of_2.patch removed from -mm tree
Date: Fri, 08 Jan 2010 13:11:53 -0800	[thread overview]
Message-ID: <201001082111.o08LBrSq014250@imap1.linux-foundation.org> (raw)


The patch titled
     kernel.h: add BUILD_BUG_ON_NOT_POWER_OF_2()
has been removed from the -mm tree.  Its filename was
     kernelh-add-build_bug_on_not_power_of_2.patch

This patch was dropped because an updated version will be merged

The current -mm tree may be found at http://userweb.kernel.org/~akpm/mmotm/

------------------------------------------------------
Subject: kernel.h: add BUILD_BUG_ON_NOT_POWER_OF_2()
From: Roland Dreier <rdreier@cisco.com>

When code relies on a constant being a power of 2:

	#define FOO	512	/* must be a power of 2 */

it would be nice to be able to do:

	BUILD_BUG_ON(!is_power_of_2(FOO));

However applying an inline function does not result in a compile-time
constant that can be used with BUILD_BUG_ON(), so trying that gives
results in:

	error: bit-field '<anonymous>' width not an integer constant

As suggested by akpm, rather than monkeying around with is_power_of_2()
and risking gcc warts about constant expressions, just create a macro
BUILD_BUG_ON_NOT_POWER_OF_2() to encapsulate this common requirement.

Signed-off-by: Roland Dreier <rolandd@cisco.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 include/linux/kernel.h |    4 ++++
 1 file changed, 4 insertions(+)

diff -puN include/linux/kernel.h~kernelh-add-build_bug_on_not_power_of_2 include/linux/kernel.h
--- a/include/linux/kernel.h~kernelh-add-build_bug_on_not_power_of_2
+++ a/include/linux/kernel.h
@@ -703,6 +703,10 @@ static inline void ftrace_dump(void) { }
 struct sysinfo;
 extern int do_sysinfo(struct sysinfo *info);
 
+/* Force a compilation error if expression is not a power of 2 */
+#define BUILD_BUG_ON_NOT_POWER_OF_2(n)			\
+	BUILD_BUG_ON(((n) != 0 && (((n) & ((n) - 1)) == 0)))
+
 /* Force a compilation error if condition is true, but also produce a
    result (of value 0 and type size_t), so the expression can be used
    e.g. in a structure initializer (or where-ever else comma expressions
_

Patches currently in -mm which might be from rdreier@cisco.com are

kfifo-use-void-pointers-for-user-buffers.patch
kfifo-sanitize-_user-error-handling.patch
kfifo-add-kfifo_out_peek.patch
kfifo-add-kfifo_initialized.patch
kfifo-document-everywhere-that-size-has-to-be-power-of-two.patch
kernelh-add-build_bug_on_not_power_of_2.patch
ecryptfs-another-lockdep-issue.patch


                 reply	other threads:[~2010-01-08 21:12 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=201001082111.o08LBrSq014250@imap1.linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mm-commits@vger.kernel.org \
    --cc=rdreier@cisco.com \
    --cc=rolandd@cisco.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.