Skip to content

Commit

Permalink
locking/qspinlock: Always evaluate lockevent* non-event parameter once
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Waiman Long <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
Reviewed-by: Boqun Feng <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
Waiman-Long authored and Ingo Molnar committed Mar 21, 2024
1 parent 4ae3dc8 commit 3774b28
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions kernel/locking/lock_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
2 changes: 1 addition & 1 deletion kernel/locking/qspinlock_paravirt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 (;;) {
Expand Down

0 comments on commit 3774b28

Please sign in to comment.