Skip to content

Commit 79a20a8

Browse files
Zhen LeiFrederic Weisbecker
authored andcommitted
srcu: Replace WARN_ON_ONCE() with BUILD_BUG_ON() if possible
The value of ARRAY_SIZE() can be determined at compile time, so if both sides of the equation are ARRAY_SIZE(), using BUILD_BUG_ON() can help us catch the problem earlier. While there are cases where unequal array sizes will work, there is no point in allowing them, so it makes more sense to force them to be equal using BUILD_BUG_ON(). Signed-off-by: Zhen Lei <[email protected]> Signed-off-by: Neeraj Upadhyay <[email protected]> Signed-off-by: Frederic Weisbecker <[email protected]>
1 parent f7345cc commit 79a20a8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kernel/rcu/srcutree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static void init_srcu_struct_data(struct srcu_struct *ssp)
128128
* Initialize the per-CPU srcu_data array, which feeds into the
129129
* leaves of the srcu_node tree.
130130
*/
131-
WARN_ON_ONCE(ARRAY_SIZE(sdp->srcu_lock_count) !=
131+
BUILD_BUG_ON(ARRAY_SIZE(sdp->srcu_lock_count) !=
132132
ARRAY_SIZE(sdp->srcu_unlock_count));
133133
for_each_possible_cpu(cpu) {
134134
sdp = per_cpu_ptr(ssp->sda, cpu);
@@ -187,7 +187,7 @@ static bool init_srcu_struct_nodes(struct srcu_struct *ssp, gfp_t gfp_flags)
187187
/* Each pass through this loop initializes one srcu_node structure. */
188188
srcu_for_each_node_breadth_first(ssp, snp) {
189189
spin_lock_init(&ACCESS_PRIVATE(snp, lock));
190-
WARN_ON_ONCE(ARRAY_SIZE(snp->srcu_have_cbs) !=
190+
BUILD_BUG_ON(ARRAY_SIZE(snp->srcu_have_cbs) !=
191191
ARRAY_SIZE(snp->srcu_data_have_cbs));
192192
for (i = 0; i < ARRAY_SIZE(snp->srcu_have_cbs); i++) {
193193
snp->srcu_have_cbs[i] = SRCU_SNP_INIT_SEQ;

0 commit comments

Comments
 (0)