]> www.infradead.org Git - users/willy/xarray.git/commitdiff
locking/qspinlock: Always evaluate lockevent* non-event parameter once
authorWaiman Long <longman@redhat.com>
Tue, 19 Mar 2024 00:50:04 +0000 (20:50 -0400)
committerIngo Molnar <mingo@kernel.org>
Thu, 21 Mar 2024 19:45:17 +0000 (20:45 +0100)
The 'inc' parameter of lockevent_add() and the cond parameter of
lockevent_cond_inc() are only evaluated when CONFIG_LOCK_EVENT_COUNTS
is on. That can cause problem if those parameters are expressions
with side effect like a "++". Fix this by evaluating those non-event
parameters once even if CONFIG_LOCK_EVENT_COUNTS is off. This will also
eliminate the need of the __maybe_unused attribute to the wait_early
local variable in pv_wait_node().

Suggested-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20240319005004.1692705-1-longman@redhat.com
kernel/locking/lock_events.h
kernel/locking/qspinlock_paravirt.h

index a6016b91803d25bbee80e4b05cc62cefb751031d..d2345e9c0190b747dcc52668e9ad99595051038a 100644 (file)
@@ -53,8 +53,8 @@ static inline void __lockevent_add(enum lock_events event, int inc)
 #else  /* CONFIG_LOCK_EVENT_COUNTS */
 
 #define lockevent_inc(ev)
-#define lockevent_add(ev, c)
-#define lockevent_cond_inc(ev, c)
+#define lockevent_add(ev, c)           do { (void)(c); } while (0)
+#define lockevent_cond_inc(ev, c)      do { (void)(c); } while (0)
 
 #endif /* CONFIG_LOCK_EVENT_COUNTS */
 
index ae2b12f68b908016ee52c7bff64bf281122dc083..169950fe1aad996b11e3eb7033d8f5c3fb2d14e6 100644 (file)
@@ -294,7 +294,7 @@ static void pv_wait_node(struct mcs_spinlock *node, struct mcs_spinlock *prev)
 {
        struct pv_node *pn = (struct pv_node *)node;
        struct pv_node *pp = (struct pv_node *)prev;
-       bool __maybe_unused wait_early;
+       bool wait_early;
        int loop;
 
        for (;;) {