Skip to content

Commit d465492

Browse files
paulmckrcuurezki
authored andcommitted
srcu: Guarantee non-negative return value from srcu_read_lock()
For almost 20 years, the int return value from srcu_read_lock() has been always either zero or one. This commit therefore documents the fact that it will be non-negative, and does the same for the underlying __srcu_read_lock(). [ paulmck: Apply Andrii Nakryiko feedback. ] Signed-off-by: Paul E. McKenney <paulmck@kernel.org> Acked-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
1 parent fac04ef commit d465492

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

include/linux/srcu.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,14 @@ static inline int srcu_read_lock_held(const struct srcu_struct *ssp)
232232
* a mutex that is held elsewhere while calling synchronize_srcu() or
233233
* synchronize_srcu_expedited().
234234
*
235-
* The return value from srcu_read_lock() must be passed unaltered
236-
* to the matching srcu_read_unlock(). Note that srcu_read_lock() and
237-
* the matching srcu_read_unlock() must occur in the same context, for
238-
* example, it is illegal to invoke srcu_read_unlock() in an irq handler
239-
* if the matching srcu_read_lock() was invoked in process context. Or,
240-
* for that matter to invoke srcu_read_unlock() from one task and the
241-
* matching srcu_read_lock() from another.
235+
* The return value from srcu_read_lock() is guaranteed to be
236+
* non-negative. This value must be passed unaltered to the matching
237+
* srcu_read_unlock(). Note that srcu_read_lock() and the matching
238+
* srcu_read_unlock() must occur in the same context, for example, it is
239+
* illegal to invoke srcu_read_unlock() in an irq handler if the matching
240+
* srcu_read_lock() was invoked in process context. Or, for that matter to
241+
* invoke srcu_read_unlock() from one task and the matching srcu_read_lock()
242+
* from another.
242243
*/
243244
static inline int srcu_read_lock(struct srcu_struct *ssp) __acquires(ssp)
244245
{

kernel/rcu/srcutree.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,8 @@ EXPORT_SYMBOL_GPL(__srcu_check_read_flavor);
738738
/*
739739
* Counts the new reader in the appropriate per-CPU element of the
740740
* srcu_struct.
741-
* Returns an index that must be passed to the matching srcu_read_unlock().
741+
* Returns a guaranteed non-negative index that must be passed to the
742+
* matching __srcu_read_unlock().
742743
*/
743744
int __srcu_read_lock(struct srcu_struct *ssp)
744745
{

0 commit comments

Comments
 (0)