File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -31,10 +31,15 @@ static DEFINE_SPINLOCK(kernfs_idr_lock); /* root->ino_idr */
31
31
32
32
#define rb_to_kn (X ) rb_entry((X), struct kernfs_node, rb)
33
33
34
+ static bool __kernfs_active (struct kernfs_node * kn )
35
+ {
36
+ return atomic_read (& kn -> active ) >= 0 ;
37
+ }
38
+
34
39
static bool kernfs_active (struct kernfs_node * kn )
35
40
{
36
41
lockdep_assert_held (& kernfs_root (kn )-> kernfs_rwsem );
37
- return atomic_read ( & kn -> active ) >= 0 ;
42
+ return __kernfs_active ( kn ) ;
38
43
}
39
44
40
45
static bool kernfs_lockdep (struct kernfs_node * kn )
@@ -705,7 +710,12 @@ struct kernfs_node *kernfs_find_and_get_node_by_id(struct kernfs_root *root,
705
710
goto err_unlock ;
706
711
}
707
712
708
- if (unlikely (!kernfs_active (kn ) || !atomic_inc_not_zero (& kn -> count )))
713
+ /*
714
+ * We should fail if @kn has never been activated and guarantee success
715
+ * if the caller knows that @kn is active. Both can be achieved by
716
+ * __kernfs_active() which tests @kn->active without kernfs_rwsem.
717
+ */
718
+ if (unlikely (!__kernfs_active (kn ) || !atomic_inc_not_zero (& kn -> count )))
709
719
goto err_unlock ;
710
720
711
721
spin_unlock (& kernfs_idr_lock );
You can’t perform that action at this time.
0 commit comments