srcu: Fix error handling in init_srcu_struct_fields()
authorJoel Fernandes (Google) <joel@joelfernandes.org>
Sat, 29 Jul 2023 14:27:32 +0000 (14:27 +0000)
committerFrederic Weisbecker <frederic@kernel.org>
Wed, 13 Sep 2023 20:27:41 +0000 (22:27 +0200)
commitf0a31b26be1f725e3f56beed76486c1b034120b3
tree5f6e7c6e0c0f62597f6b3f7800969cce50afd901
parentff18cb816427c3738d5d3fd23b7939a813935e15
srcu: Fix error handling in init_srcu_struct_fields()

The current error handling in init_srcu_struct_fields() is a bit
inconsistent.  If init_srcu_struct_nodes() fails, the function either
returns -ENOMEM or 0 depending on whether ssp->sda_is_static is true or
false. This can make init_srcu_struct_fields() return 0 even if memory
allocation failed!

Simplify the error handling by always returning -ENOMEM if either
init_srcu_struct_nodes() or the per-CPU allocation fails. This makes the
control flow easier to follow and avoids the inconsistent return values.

Add goto labels to avoid duplicating the error cleanup code.

Link: https://lore.kernel.org/r/20230404003508.GA254019@google.com
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
kernel/rcu/srcutree.c