Skip to content

Commit 63c8c0d

Browse files
committed
Merge tag 'driver-core-6.1-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core
Pull driver core fixes from Greg KH: "Here are two small driver core fixes for 6.1-rc6: - utsname fix, this one should already be in your tree as it came from a different tree earlier. - kernfs bugfix for a much reported syzbot report that seems to keep getting triggered. Both of these have been in linux-next for a while with no reported issues" * tag 'driver-core-6.1-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: kernfs: Fix spurious lockdep warning in kernfs_find_and_get_node_by_id() kernel/utsname_sysctl.c: Add missing enum uts_proc value
2 parents 1f63d1a + 1edfe4e commit 63c8c0d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

fs/kernfs/dir.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@ static DEFINE_SPINLOCK(kernfs_idr_lock); /* root->ino_idr */
3131

3232
#define rb_to_kn(X) rb_entry((X), struct kernfs_node, rb)
3333

34+
static bool __kernfs_active(struct kernfs_node *kn)
35+
{
36+
return atomic_read(&kn->active) >= 0;
37+
}
38+
3439
static bool kernfs_active(struct kernfs_node *kn)
3540
{
3641
lockdep_assert_held(&kernfs_root(kn)->kernfs_rwsem);
37-
return atomic_read(&kn->active) >= 0;
42+
return __kernfs_active(kn);
3843
}
3944

4045
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,
705710
goto err_unlock;
706711
}
707712

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)))
709719
goto err_unlock;
710720

711721
spin_unlock(&kernfs_idr_lock);

0 commit comments

Comments
 (0)