srcu: Prevent cleanup_srcu_struct() from freeing non-dynamic ->sda
authorPaul E. McKenney <paulmck@kernel.org>
Thu, 27 Jan 2022 21:20:49 +0000 (13:20 -0800)
committerPaul E. McKenney <paulmck@kernel.org>
Thu, 24 Feb 2022 17:50:10 +0000 (09:50 -0800)
commit20c3e1d6fde8b6e47aac96bbe514d62b25709385
tree553218d139f176d21aa127a06de2ac6d56cd0c6b
parentb54e31f75e69c508b04bab3417c8a750ef2e7a27
srcu: Prevent cleanup_srcu_struct() from freeing non-dynamic ->sda

When an srcu_struct structure is created (but not in a kernel module)
by DEFINE_SRCU() and friends, the per-CPU srcu_data structure is
statically allocated.  In all other cases, that structure is obtained
from alloc_percpu(), in which case cleanup_srcu_struct() must invoke
free_percpu() on the resulting ->sda pointer in the srcu_struct pointer.

Which it does.

Except that it also invokes free_percpu() on the ->sda pointer
referencing the statically allocated per-CPU srcu_data structures.
Which free_percpu() is surprisingly OK with.

This commit nevertheless stops cleanup_srcu_struct() from freeing
statically allocated per-CPU srcu_data structures.

Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
include/linux/srcutree.h
kernel/rcu/srcutree.c