@@ -74,8 +74,6 @@ module_param(lock_stat, int, 0644);
74
74
#define lock_stat 0
75
75
#endif
76
76
77
- static bool check_data_structure_consistency ;
78
-
79
77
/*
80
78
* lockdep_lock: protects the lockdep graph, the hashes and the
81
79
* class/list/hash allocators.
@@ -791,6 +789,8 @@ static bool assign_lock_key(struct lockdep_map *lock)
791
789
return true;
792
790
}
793
791
792
+ #ifdef CONFIG_DEBUG_LOCKDEP
793
+
794
794
/* Check whether element @e occurs in list @h */
795
795
static bool in_list (struct list_head * e , struct list_head * h )
796
796
{
@@ -855,31 +855,31 @@ static bool check_lock_chain_key(struct lock_chain *chain)
855
855
* The 'unsigned long long' casts avoid that a compiler warning
856
856
* is reported when building tools/lib/lockdep.
857
857
*/
858
- if (chain -> chain_key != chain_key )
858
+ if (chain -> chain_key != chain_key ) {
859
859
printk (KERN_INFO "chain %lld: key %#llx <> %#llx\n" ,
860
860
(unsigned long long )(chain - lock_chains ),
861
861
(unsigned long long )chain -> chain_key ,
862
862
(unsigned long long )chain_key );
863
- return chain -> chain_key == chain_key ;
864
- #else
865
- return true;
863
+ return false;
864
+ }
866
865
#endif
866
+ return true;
867
867
}
868
868
869
869
static bool in_any_zapped_class_list (struct lock_class * class )
870
870
{
871
871
struct pending_free * pf ;
872
872
int i ;
873
873
874
- for (i = 0 , pf = delayed_free .pf ; i < ARRAY_SIZE (delayed_free .pf );
875
- i ++ , pf ++ )
874
+ for (i = 0 , pf = delayed_free .pf ; i < ARRAY_SIZE (delayed_free .pf ); i ++ , pf ++ ) {
876
875
if (in_list (& class -> lock_entry , & pf -> zapped ))
877
876
return true;
877
+ }
878
878
879
879
return false;
880
880
}
881
881
882
- static bool check_data_structures (void )
882
+ static bool __check_data_structures (void )
883
883
{
884
884
struct lock_class * class ;
885
885
struct lock_chain * chain ;
@@ -896,7 +896,6 @@ static bool check_data_structures(void)
896
896
printk (KERN_INFO "class %px/%s is not in any class list\n" ,
897
897
class , class -> name ? : "(?)" );
898
898
return false;
899
- return false;
900
899
}
901
900
}
902
901
@@ -953,6 +952,27 @@ static bool check_data_structures(void)
953
952
return true;
954
953
}
955
954
955
+ int check_consistency = 0 ;
956
+ module_param (check_consistency , int , 0644 );
957
+
958
+ static void check_data_structures (void )
959
+ {
960
+ static bool once = false;
961
+
962
+ if (check_consistency && !once ) {
963
+ if (!__check_data_structures ()) {
964
+ once = true;
965
+ WARN_ON (once );
966
+ }
967
+ }
968
+ }
969
+
970
+ #else /* CONFIG_DEBUG_LOCKDEP */
971
+
972
+ static inline void check_data_structures (void ) { }
973
+
974
+ #endif /* CONFIG_DEBUG_LOCKDEP */
975
+
956
976
/*
957
977
* Initialize the lock_classes[] array elements, the free_lock_classes list
958
978
* and also the delayed_free structure.
@@ -4474,10 +4494,11 @@ static void remove_class_from_lock_chain(struct pending_free *pf,
4474
4494
if (chain_hlocks [i ] != class - lock_classes )
4475
4495
continue ;
4476
4496
/* The code below leaks one chain_hlock[] entry. */
4477
- if (-- chain -> depth > 0 )
4497
+ if (-- chain -> depth > 0 ) {
4478
4498
memmove (& chain_hlocks [i ], & chain_hlocks [i + 1 ],
4479
4499
(chain -> base + chain -> depth - i ) *
4480
4500
sizeof (chain_hlocks [0 ]));
4501
+ }
4481
4502
/*
4482
4503
* Each lock class occurs at most once in a lock chain so once
4483
4504
* we found a match we can break out of this loop.
@@ -4631,8 +4652,7 @@ static void __free_zapped_classes(struct pending_free *pf)
4631
4652
{
4632
4653
struct lock_class * class ;
4633
4654
4634
- if (check_data_structure_consistency )
4635
- WARN_ON_ONCE (!check_data_structures ());
4655
+ check_data_structures ();
4636
4656
4637
4657
list_for_each_entry (class , & pf -> zapped , lock_entry )
4638
4658
reinit_class (class );
0 commit comments