[RFC PATCH 09/13] klist.h: Fix parentheses around macro parameter use

From: Mathieu Desnoyers
Date: Thu May 04 2023 - 16:52:19 EST


Add missing parentheses around "_name" parameter use in KLIST_INIT().
It keeps list macros consistent, and prevents unexpected operator
precedence situations, for example:

struct klist a[1] = { KLIST_INIT(*a, NULL, NULL) };

Where the "." operator within KLIST_INIT() is evaluated before the "*"
operator.

Add missing parentheses around macro parameter use in the following
patterns to ensure operator precedence behaves as expected:

- "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.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Tejun Heo <htejun@xxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
---
include/linux/klist.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/linux/klist.h b/include/linux/klist.h
index b0f238f20dbb..d7e0612ca4ff 100644
--- a/include/linux/klist.h
+++ b/include/linux/klist.h
@@ -23,10 +23,10 @@ struct klist {
} __attribute__ ((aligned (sizeof(void *))));

#define KLIST_INIT(_name, _get, _put) \
- { .k_lock = __SPIN_LOCK_UNLOCKED(_name.k_lock), \
- .k_list = LIST_HEAD_INIT(_name.k_list), \
- .get = _get, \
- .put = _put, }
+ { .k_lock = __SPIN_LOCK_UNLOCKED((_name).k_lock), \
+ .k_list = LIST_HEAD_INIT((_name).k_list), \
+ .get = (_get), \
+ .put = (_put), }

#define DEFINE_KLIST(_name, _get, _put) \
struct klist _name = KLIST_INIT(_name, _get, _put)
--
2.25.1