Re: intel-iommu: Add for_each_iommu() and for_each_active_iommu()macros

From: David Woodhouse
Date: Mon Apr 06 2009 - 23:29:59 EST


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@xxxxxxxxx>
Acked-by: Steven Rostedt <rostedt@xxxxxxxxxxx>

---
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@xxxxxxxxx Intel Corporation

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/