Skip to content

Commit d8f3f58

Browse files
committed
rcu: Update rcu_access_pointer() header for rcu_dereference_protected()
The rcu_access_pointer() docbook header correctly notes that it may be used during post-grace-period teardown. However, it is usually better to use rcu_dereference_protected() for this purpose. This commit therefore calls out this preferred usage. Reported-by: Maxim Mikityanskiy <maximmi@nvidia.com> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
1 parent 089254f commit d8f3f58

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

include/linux/rcupdate.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,13 +496,21 @@ do { \
496496
* against NULL. Although rcu_access_pointer() may also be used in cases
497497
* where update-side locks prevent the value of the pointer from changing,
498498
* you should instead use rcu_dereference_protected() for this use case.
499+
* Within an RCU read-side critical section, there is little reason to
500+
* use rcu_access_pointer().
501+
*
502+
* It is usually best to test the rcu_access_pointer() return value
503+
* directly in order to avoid accidental dereferences being introduced
504+
* by later inattentive changes. In other words, assigning the
505+
* rcu_access_pointer() return value to a local variable results in an
506+
* accident waiting to happen.
499507
*
500508
* It is also permissible to use rcu_access_pointer() when read-side
501-
* access to the pointer was removed at least one grace period ago, as
502-
* is the case in the context of the RCU callback that is freeing up
503-
* the data, or after a synchronize_rcu() returns. This can be useful
504-
* when tearing down multi-linked structures after a grace period
505-
* has elapsed.
509+
* access to the pointer was removed at least one grace period ago, as is
510+
* the case in the context of the RCU callback that is freeing up the data,
511+
* or after a synchronize_rcu() returns. This can be useful when tearing
512+
* down multi-linked structures after a grace period has elapsed. However,
513+
* rcu_dereference_protected() is normally preferred for this use case.
506514
*/
507515
#define rcu_access_pointer(p) __rcu_access_pointer((p), __UNIQUE_ID(rcu), __rcu)
508516

0 commit comments

Comments
 (0)