Skip to content

Commit 80cd613

Browse files
jmberg-intelurezki
authored andcommitted
rcu: Mollify sparse with RCU guard
When using "guard(rcu)();" sparse will complain, because even though it now understands the cleanup attribute, it doesn't evaluate the calls from it at function exit, and thus doesn't count the context correctly. Given that there's a conditional in the resulting code: static inline void class_rcu_destructor(class_rcu_t *_T) { if (_T->lock) { rcu_read_unlock(); } } it seems that even trying to teach sparse to evalulate the cleanup attribute function it'd still be difficult to really make it understand the full context here. Suppress the sparse warning by just releasing the context in the acquisition part of the function, after all we know it's safe with the guard, that's the whole point of it. Signed-off-by: Johannes Berg <[email protected]> Reviewed-by: Boqun Feng <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]> Signed-off-by: Uladzislau Rezki (Sony) <[email protected]>
1 parent 10c9e40 commit 80cd613

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

include/linux/rcupdate.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,18 @@ rcu_head_after_call_rcu(struct rcu_head *rhp, rcu_callback_t f)
10901090
extern int rcu_expedited;
10911091
extern int rcu_normal;
10921092

1093-
DEFINE_LOCK_GUARD_0(rcu, rcu_read_lock(), rcu_read_unlock())
1093+
DEFINE_LOCK_GUARD_0(rcu,
1094+
do {
1095+
rcu_read_lock();
1096+
/*
1097+
* sparse doesn't call the cleanup function,
1098+
* so just release immediately and don't track
1099+
* the context. We don't need to anyway, since
1100+
* the whole point of the guard is to not need
1101+
* the explicit unlock.
1102+
*/
1103+
__release(RCU);
1104+
} while (0),
1105+
rcu_read_unlock())
10941106

10951107
#endif /* __LINUX_RCUPDATE_H */

0 commit comments

Comments
 (0)