All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: torvalds@linux-foundation.org, Steven Rostedt <rostedt@goodmis.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, Ingo Molnar <mingo@elte.hu>
Subject: Re: intel-iommu: Add for_each_iommu() and for_each_active_iommu() macros
Date: Mon, 06 Apr 2009 20:29:40 -0700	[thread overview]
Message-ID: <1239074980.22733.303.camel@macbook.infradead.org> (raw)
In-Reply-To: <alpine.DEB.2.00.0904062127420.24008@gandalf.stny.rr.com>

The PROFILE_ALL_BRANCHES option causes us to define if() as a macro...
taking precisely one argument. This causes a build failure if the
condition is actually a comma expression -- 'if (a(), b)'.

This patch turns the if() macro into a varargs macro which copes with a
comma expression as its 'arguments'.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>

---
Some might argue that I shouldn't have been using if(a,b) in the first
place, but in my defence it _should_ have worked, and it was less ugly
than the original. I did this:

#define for_each_active_iommu(i, drhd)                                  \
        list_for_each_entry(drhd, &dmar_drhd_units, list)               \
                if (i=drhd->iommu, drhd->ignored) {} else

... instead of what I was originally given, which was (with the first
three macros added to list.h as a generic facility)...

#define list_first_entry_selected(pos, head, member, selector)		  \
	pos = list_entry((head)->next, typeof(*pos), member),		  \
	pos = ({while (!(selector) && (&pos->member != (head)))		  \
		pos = list_entry(pos->member.next, typeof(*pos), member); \
		pos; })
#define list_next_entry_selected(pos, head, member, selector)		  \
	pos = list_entry(pos->member.next, typeof(*pos), member),	  \
	pos = ({while (!(selector) && (&pos->member != (head)))		  \
		pos = list_entry(pos->member.next, typeof(*pos), member); \
		pos; })
#define list_for_each_entry_selected_do(pos, head, member, selector, to_do) \
	for (list_first_entry_selected(pos, head, member, selector),	    \
		({if (&pos->member != (head)) to_do});			    \
		prefetch(pos->member.next), &pos->member != (head);	    \
		list_next_entry_selected(pos, head, member, selector),	    \
		({if (&pos->member != (head)) to_do}))

#define for_each_active_iommu(i, drhd)					\
	list_for_each_entry_selected_do(drhd, &dmar_drhd_units, list,	\
				!drhd->ignored, {i = drhd->iommu; })

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 6faa7e5..c28d876 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -114,7 +114,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
  * "Define 'is'", Bill Clinton
  * "Define 'if'", Steven Rostedt
  */
-#define if(cond) if (__builtin_constant_p((cond)) ? !!(cond) :		\
+#define if(cond, ...) if (__builtin_constant_p((cond, ## __VA_ARGS__))	\
+			  ? !!(cond, ## __VA_ARGS__) :			\
 	({								\
 		int ______r;						\
 		static struct ftrace_branch_data			\
@@ -125,8 +126,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
 				.file = __FILE__,			\
 				.line = __LINE__,			\
 			};						\
-		______r = !!(cond);					\
-		______f.miss_hit[______r]++;					\
+		______r = !!(cond, ## __VA_ARGS__);			\
+		______f.miss_hit[______r]++;				\
 		______r;						\
 	}))
 #endif /* CONFIG_PROFILE_ALL_BRANCHES */

-- 
David Woodhouse                            Open Source Technology Centre
David.Woodhouse@intel.com                              Intel Corporation


  parent reply	other threads:[~2009-04-07  3:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200904062159.n36Lx1OJ001967@hera.kernel.org>
2009-04-07  0:59 ` intel-iommu: Add for_each_iommu() and for_each_active_iommu() macros Andrew Morton
2009-04-07  1:09   ` David Woodhouse
2009-04-07  1:19     ` David Woodhouse
2009-04-07  1:24       ` Andrew Morton
2009-04-07  1:29       ` Steven Rostedt
2009-04-07  2:58         ` David Woodhouse
2009-04-07  3:02           ` Steven Rostedt
2009-04-07  3:29         ` David Woodhouse [this message]
2009-04-08 11:00     ` Ingo Molnar
2009-04-09  0:42       ` David Woodhouse

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=1239074980.22733.303.camel@macbook.infradead.org \
    --to=dwmw2@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.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 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.