From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
"Paul E. McKenney" <paulmck@kernel.org>,
Frederic Weisbecker <frederic@kernel.org>,
Neeraj Upadhyay <quic_neeraju@quicinc.com>,
Joel Fernandes <joel@joelfernandes.org>,
Josh Triplett <josh@joshtriplett.org>,
Boqun Feng <boqun.feng@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>,
Lai Jiangshan <jiangshanlai@gmail.com>,
Zqiang <qiang1.zhang@intel.com>,
rcu@vger.kernel.org
Subject: [RFC PATCH 02/13] rculist.h: Fix parentheses around macro pointer parameter use
Date: Thu, 4 May 2023 16:05:16 -0400 [thread overview]
Message-ID: <20230504200527.1935944-3-mathieu.desnoyers@efficios.com> (raw)
In-Reply-To: <20230504200527.1935944-1-mathieu.desnoyers@efficios.com>
Add missing parentheses around use of macro argument "pos" in those
patterns to ensure operator precedence behaves as expected:
- typeof(*pos)
- pos->member
This corrects the following usage pattern where operator precedence is
unexpected:
LIST_HEAD(testlist);
struct test {
struct list_head node;
int a;
};
// pos->member issue
void f(void)
{
struct test *t1;
struct test **t2 = &t1;
list_for_each_entry_rcu((*t2), &testlist, node) { /* works */
//...
}
list_for_each_entry_rcu(*t2, &testlist, node) { /* broken */
//...
}
}
The typeof(*pos) lack of parentheses around "pos" is not an issue per se
in the specific macros modified here because "pos" 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: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Frederic Weisbecker <frederic@kernel.org>
Cc: Neeraj Upadhyay <quic_neeraju@quicinc.com>
Cc: Joel Fernandes <joel@joelfernandes.org>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: Zqiang <qiang1.zhang@intel.com>
Cc: rcu@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
include/linux/rculist.h | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/include/linux/rculist.h b/include/linux/rculist.h
index d29740be4833..d27aeff5447d 100644
--- a/include/linux/rculist.h
+++ b/include/linux/rculist.h
@@ -388,9 +388,9 @@ static inline void list_splice_tail_init_rcu(struct list_head *list,
*/
#define list_for_each_entry_rcu(pos, head, member, cond...) \
for (__list_check_rcu(dummy, ## cond, 0), \
- pos = list_entry_rcu((head)->next, typeof(*pos), member); \
- &pos->member != (head); \
- pos = list_entry_rcu(pos->member.next, typeof(*pos), member))
+ pos = list_entry_rcu((head)->next, typeof(*(pos)), member);\
+ &(pos)->member != (head); \
+ pos = list_entry_rcu((pos)->member.next, typeof(*(pos)), member))
/**
* list_for_each_entry_srcu - iterate over rcu list of given type
@@ -407,9 +407,9 @@ static inline void list_splice_tail_init_rcu(struct list_head *list,
*/
#define list_for_each_entry_srcu(pos, head, member, cond) \
for (__list_check_srcu(cond), \
- pos = list_entry_rcu((head)->next, typeof(*pos), member); \
- &pos->member != (head); \
- pos = list_entry_rcu(pos->member.next, typeof(*pos), member))
+ pos = list_entry_rcu((head)->next, typeof(*(pos)), member);\
+ &(pos)->member != (head); \
+ pos = list_entry_rcu((pos)->member.next, typeof(*(pos)), member))
/**
* list_entry_lockless - get the struct for this entry
@@ -441,9 +441,9 @@ static inline void list_splice_tail_init_rcu(struct list_head *list,
* but never deleted.
*/
#define list_for_each_entry_lockless(pos, head, member) \
- for (pos = list_entry_lockless((head)->next, typeof(*pos), member); \
- &pos->member != (head); \
- pos = list_entry_lockless(pos->member.next, typeof(*pos), member))
+ for (pos = list_entry_lockless((head)->next, typeof(*(pos)), member); \
+ &(pos)->member != (head); \
+ pos = list_entry_lockless((pos)->member.next, typeof(*(pos)), member))
/**
* list_for_each_entry_continue_rcu - continue iteration over list of given type
@@ -464,9 +464,9 @@ static inline void list_splice_tail_init_rcu(struct list_head *list,
* position.
*/
#define list_for_each_entry_continue_rcu(pos, head, member) \
- for (pos = list_entry_rcu(pos->member.next, typeof(*pos), member); \
- &pos->member != (head); \
- pos = list_entry_rcu(pos->member.next, typeof(*pos), member))
+ for (pos = list_entry_rcu((pos)->member.next, typeof(*(pos)), member); \
+ &(pos)->member != (head); \
+ pos = list_entry_rcu((pos)->member.next, typeof(*(pos)), member))
/**
* list_for_each_entry_from_rcu - iterate over a list from current point
@@ -486,8 +486,8 @@ static inline void list_splice_tail_init_rcu(struct list_head *list,
* after the given position.
*/
#define list_for_each_entry_from_rcu(pos, head, member) \
- for (; &(pos)->member != (head); \
- pos = list_entry_rcu(pos->member.next, typeof(*(pos)), member))
+ for (; &(pos)->member != (head); \
+ pos = list_entry_rcu((pos)->member.next, typeof(*(pos)), member))
/**
* hlist_del_rcu - deletes entry from hash list without re-initialization
--
2.25.1
next prev parent reply other threads:[~2023-05-04 20:32 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-04 20:05 [RFC PATCH 00/13] Fix parentheses around macro parameter use in headers Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 01/13] rcu: rcupdate.h: Fix parentheses around macro parameter use Mathieu Desnoyers
2023-05-04 20:05 ` Mathieu Desnoyers [this message]
2023-05-04 20:05 ` [RFC PATCH 03/13] rculist_nulls.h: Add parentheses around macro pointer " Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 04/13] rculist_bl.h: Fix " Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 05/13] list.h: " Mathieu Desnoyers
2023-05-08 12:16 ` Andy Shevchenko
2023-05-08 13:46 ` Mathieu Desnoyers
2023-05-12 11:02 ` Andy Shevchenko
2023-05-12 14:32 ` Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 06/13] list_nulls.h: " Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 07/13] list_bl.h: " Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 08/13] llist.h: " Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 09/13] klist.h: Fix parentheses around macro " Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 10/13] resource_ext.h: Remove useless parentheses around macro parameters Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 11/13] netdevice.h: Fix parentheses around macro parameter use Mathieu Desnoyers
2023-05-05 18:44 ` Jakub Kicinski
2023-05-05 18:54 ` Mathieu Desnoyers
2023-05-04 20:05 ` [RFC PATCH 12/13] blk-mq.h: " Mathieu Desnoyers
2023-05-05 13:56 ` Mathieu Desnoyers
2023-05-05 18:40 ` Linus Torvalds
2023-05-05 18:49 ` Mathieu Desnoyers
2023-05-05 19:54 ` Linus Torvalds
2023-05-05 20:08 ` Mathieu Desnoyers
2023-05-05 20:22 ` Linus Torvalds
2023-05-05 20:28 ` Mathieu Desnoyers
2023-05-08 14:28 ` Mathieu Desnoyers
2023-05-06 15:45 ` David Laight
2023-05-04 20:05 ` [RFC PATCH 13/13] bio.h: " Mathieu Desnoyers
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=20230504200527.1935944-3-mathieu.desnoyers@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=akpm@linux-foundation.org \
--cc=boqun.feng@gmail.com \
--cc=frederic@kernel.org \
--cc=jiangshanlai@gmail.com \
--cc=joel@joelfernandes.org \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=qiang1.zhang@intel.com \
--cc=quic_neeraju@quicinc.com \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®