diff options
-rw-r--r-- | fs/kernfs/dir.c | 31 | ||||
-rw-r--r-- | include/linux/kernfs.h | 1 |
2 files changed, 20 insertions, 12 deletions
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index ed62de6cdf8f..1c9130a33048 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c | |||
@@ -22,6 +22,15 @@ DEFINE_MUTEX(kernfs_mutex); | |||
22 | 22 | ||
23 | #define rb_to_kn(X) rb_entry((X), struct kernfs_node, rb) | 23 | #define rb_to_kn(X) rb_entry((X), struct kernfs_node, rb) |
24 | 24 | ||
25 | static bool kernfs_lockdep(struct kernfs_node *kn) | ||
26 | { | ||
27 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
28 | return kn->flags & KERNFS_LOCKDEP; | ||
29 | #else | ||
30 | return false; | ||
31 | #endif | ||
32 | } | ||
33 | |||
25 | /** | 34 | /** |
26 | * kernfs_name_hash | 35 | * kernfs_name_hash |
27 | * @name: Null terminated string to hash | 36 | * @name: Null terminated string to hash |
@@ -138,7 +147,7 @@ struct kernfs_node *kernfs_get_active(struct kernfs_node *kn) | |||
138 | if (!atomic_inc_unless_negative(&kn->active)) | 147 | if (!atomic_inc_unless_negative(&kn->active)) |
139 | return NULL; | 148 | return NULL; |
140 | 149 | ||
141 | if (kn->flags & KERNFS_LOCKDEP) | 150 | if (kernfs_lockdep(kn)) |
142 | rwsem_acquire_read(&kn->dep_map, 0, 1, _RET_IP_); | 151 | rwsem_acquire_read(&kn->dep_map, 0, 1, _RET_IP_); |
143 | return kn; | 152 | return kn; |
144 | } | 153 | } |
@@ -158,7 +167,7 @@ void kernfs_put_active(struct kernfs_node *kn) | |||
158 | if (unlikely(!kn)) | 167 | if (unlikely(!kn)) |
159 | return; | 168 | return; |
160 | 169 | ||
161 | if (kn->flags & KERNFS_LOCKDEP) | 170 | if (kernfs_lockdep(kn)) |
162 | rwsem_release(&kn->dep_map, 1, _RET_IP_); | 171 | rwsem_release(&kn->dep_map, 1, _RET_IP_); |
163 | v = atomic_dec_return(&kn->active); | 172 | v = atomic_dec_return(&kn->active); |
164 | if (likely(v != KN_DEACTIVATED_BIAS)) | 173 | if (likely(v != KN_DEACTIVATED_BIAS)) |
@@ -179,21 +188,21 @@ static void kernfs_deactivate(struct kernfs_node *kn) | |||
179 | 188 | ||
180 | BUG_ON(!(kn->flags & KERNFS_REMOVED)); | 189 | BUG_ON(!(kn->flags & KERNFS_REMOVED)); |
181 | 190 | ||
182 | if (!(kernfs_type(kn) & KERNFS_ACTIVE_REF)) | ||
183 | return; | ||
184 | |||
185 | rwsem_acquire(&kn->dep_map, 0, 0, _RET_IP_); | ||
186 | |||
187 | atomic_add(KN_DEACTIVATED_BIAS, &kn->active); | 191 | atomic_add(KN_DEACTIVATED_BIAS, &kn->active); |
188 | 192 | ||
189 | if (atomic_read(&kn->active) != KN_DEACTIVATED_BIAS) | 193 | if (kernfs_lockdep(kn)) { |
190 | lock_contended(&kn->dep_map, _RET_IP_); | 194 | rwsem_acquire(&kn->dep_map, 0, 0, _RET_IP_); |
195 | if (atomic_read(&kn->active) != KN_DEACTIVATED_BIAS) | ||
196 | lock_contended(&kn->dep_map, _RET_IP_); | ||
197 | } | ||
191 | 198 | ||
192 | wait_event(root->deactivate_waitq, | 199 | wait_event(root->deactivate_waitq, |
193 | atomic_read(&kn->active) == KN_DEACTIVATED_BIAS); | 200 | atomic_read(&kn->active) == KN_DEACTIVATED_BIAS); |
194 | 201 | ||
195 | lock_acquired(&kn->dep_map, _RET_IP_); | 202 | if (kernfs_lockdep(kn)) { |
196 | rwsem_release(&kn->dep_map, 1, _RET_IP_); | 203 | lock_acquired(&kn->dep_map, _RET_IP_); |
204 | rwsem_release(&kn->dep_map, 1, _RET_IP_); | ||
205 | } | ||
197 | } | 206 | } |
198 | 207 | ||
199 | /** | 208 | /** |
diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h index 232f1a632383..42ad32ff22f8 100644 --- a/include/linux/kernfs.h +++ b/include/linux/kernfs.h | |||
@@ -34,7 +34,6 @@ enum kernfs_node_type { | |||
34 | }; | 34 | }; |
35 | 35 | ||
36 | #define KERNFS_TYPE_MASK 0x000f | 36 | #define KERNFS_TYPE_MASK 0x000f |
37 | #define KERNFS_ACTIVE_REF KERNFS_FILE | ||
38 | #define KERNFS_FLAG_MASK ~KERNFS_TYPE_MASK | 37 | #define KERNFS_FLAG_MASK ~KERNFS_TYPE_MASK |
39 | 38 | ||
40 | enum kernfs_node_flag { | 39 | enum kernfs_node_flag { |