Skip to content

Commit 72b5d5a

Browse files
KatrinJogregkh
authored andcommitted
kernfs: fix potential NULL dereference in __kernfs_remove
When lockdep is enabled, lockdep_assert_held_write would cause potential NULL pointer dereference. Fix the following smatch warnings: fs/kernfs/dir.c:1353 __kernfs_remove() warn: variable dereferenced before check 'kn' (see line 1346) Fixes: 393c371 ("kernfs: switch global kernfs_rwsem lock to per-fs lock") Signed-off-by: Yushan Zhou <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c882716 commit 72b5d5a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/kernfs/dir.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,14 +1343,17 @@ static void __kernfs_remove(struct kernfs_node *kn)
13431343
{
13441344
struct kernfs_node *pos;
13451345

1346+
/* Short-circuit if non-root @kn has already finished removal. */
1347+
if (!kn)
1348+
return;
1349+
13461350
lockdep_assert_held_write(&kernfs_root(kn)->kernfs_rwsem);
13471351

13481352
/*
1349-
* Short-circuit if non-root @kn has already finished removal.
13501353
* This is for kernfs_remove_self() which plays with active ref
13511354
* after removal.
13521355
*/
1353-
if (!kn || (kn->parent && RB_EMPTY_NODE(&kn->rb)))
1356+
if (kn->parent && RB_EMPTY_NODE(&kn->rb))
13541357
return;
13551358

13561359
pr_debug("kernfs %s: removing\n", kn->name);

0 commit comments

Comments
 (0)