[RFC,07/13] list_bl.h: Fix parentheses around macro pointer parameter use
Commit Message
Add missing parentheses around use of macro argument "tpos" in those
patterns to ensure operator precedence behaves as expected:
- typeof(*tpos)
- pos->next
- "x = y" is changed for "x = (y)", because "y" can be an expression
containing a comma if it is the result of the expansion of a macro such
as #define eval(...) __VA_ARGS__, which would cause unexpected operator
precedence. This use-case is far-fetched, but we have to choose one
way or the other (with or without parentheses) for consistency.
- x && y is changed for (x) && (y).
The typeof(*tpos) lack of parentheses around "tpos" is not an issue per se
in the specific macros modified here because "tpos" is used as an lvalue,
which should prevent use of any operator causing issue. Still add the
extra parentheses for consistency.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Nick Piggin <npiggin@kernel.dk>
---
include/linux/list_bl.h | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
@@ -168,9 +168,9 @@ static inline bool hlist_bl_is_locked(struct hlist_bl_head *b)
*/
#define hlist_bl_for_each_entry(tpos, pos, head, member) \
for (pos = hlist_bl_first(head); \
- pos && \
- ({ tpos = hlist_bl_entry(pos, typeof(*tpos), member); 1;}); \
- pos = pos->next)
+ (pos) && \
+ ({ tpos = hlist_bl_entry(pos, typeof(*(tpos)), member); 1;}); \
+ pos = (pos)->next)
/**
* hlist_bl_for_each_entry_safe - iterate over list of given type safe against removal of list entry
@@ -182,8 +182,8 @@ static inline bool hlist_bl_is_locked(struct hlist_bl_head *b)
*/
#define hlist_bl_for_each_entry_safe(tpos, pos, n, head, member) \
for (pos = hlist_bl_first(head); \
- pos && ({ n = pos->next; 1; }) && \
- ({ tpos = hlist_bl_entry(pos, typeof(*tpos), member); 1;}); \
- pos = n)
+ (pos) && ({ n = (pos)->next; 1; }) && \
+ ({ tpos = hlist_bl_entry(pos, typeof(*(tpos)), member); 1;}); \
+ pos = (n))
#endif