Skip to content

Commit 8e66624

Browse files
t-8chJoelgranados
authored andcommitted
sysctl: Convert locking comments to lockdep assertions
The assertions work as well as the comment to inform developers about locking expectations. Additionally they are validated by lockdep at runtime, making sure the expectations are met. Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Joel Granados <[email protected]>
1 parent 5cc3199 commit 8e66624

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

fs/proc/proc_sysctl.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/bpf-cgroup.h>
1818
#include <linux/mount.h>
1919
#include <linux/kmemleak.h>
20+
#include <linux/lockdep.h>
2021
#include "internal.h"
2122

2223
#define list_for_each_table_entry(entry, header) \
@@ -109,14 +110,15 @@ static int namecmp(const char *name1, int len1, const char *name2, int len2)
109110
return cmp;
110111
}
111112

112-
/* Called under sysctl_lock */
113113
static const struct ctl_table *find_entry(struct ctl_table_header **phead,
114114
struct ctl_dir *dir, const char *name, int namelen)
115115
{
116116
struct ctl_table_header *head;
117117
const struct ctl_table *entry;
118118
struct rb_node *node = dir->root.rb_node;
119119

120+
lockdep_assert_held(&sysctl_lock);
121+
120122
while (node)
121123
{
122124
struct ctl_node *ctl_node;
@@ -263,18 +265,20 @@ static int insert_header(struct ctl_dir *dir, struct ctl_table_header *header)
263265
return err;
264266
}
265267

266-
/* called under sysctl_lock */
267268
static int use_table(struct ctl_table_header *p)
268269
{
270+
lockdep_assert_held(&sysctl_lock);
271+
269272
if (unlikely(p->unregistering))
270273
return 0;
271274
p->used++;
272275
return 1;
273276
}
274277

275-
/* called under sysctl_lock */
276278
static void unuse_table(struct ctl_table_header *p)
277279
{
280+
lockdep_assert_held(&sysctl_lock);
281+
278282
if (!--p->used)
279283
if (unlikely(p->unregistering))
280284
complete(p->unregistering);
@@ -285,9 +289,11 @@ static void proc_sys_invalidate_dcache(struct ctl_table_header *head)
285289
proc_invalidate_siblings_dcache(&head->inodes, &sysctl_lock);
286290
}
287291

288-
/* called under sysctl_lock, will reacquire if has to wait */
289292
static void start_unregistering(struct ctl_table_header *p)
290293
{
294+
/* will reacquire if has to wait */
295+
lockdep_assert_held(&sysctl_lock);
296+
291297
/*
292298
* if p->used is 0, nobody will ever touch that entry again;
293299
* we'll eliminate all paths to it before dropping sysctl_lock

0 commit comments

Comments
 (0)