Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3db3c625 authored by Maarten Lankhorst's avatar Maarten Lankhorst Committed by Greg Kroah-Hartman
Browse files

sysfs: use atomic_inc_unless_negative in sysfs_get_active



It seems that sysfs has an interesting way of doing the same thing.
This removes the cpu_relax unfortunately, but if it's really needed,
it would be better to add this to include/linux/atomic.h to benefit
all atomic ops users.

Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@canonical.com>
Acked-by: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 91721197
Loading
Loading
Loading
Loading
+2 −15
Original line number Diff line number Diff line
@@ -165,22 +165,9 @@ struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd)
	if (unlikely(!sd))
		return NULL;

	while (1) {
		int v, t;

		v = atomic_read(&sd->s_active);
		if (unlikely(v < 0))
			return NULL;

		t = atomic_cmpxchg(&sd->s_active, v, v + 1);
		if (likely(t == v))
			break;
		if (t < 0)
	if (!atomic_inc_unless_negative(&sd->s_active))
		return NULL;

		cpu_relax();
	}

	if (likely(!ignore_lockdep(sd)))
		rwsem_acquire_read(&sd->dep_map, 0, 1, _RET_IP_);
	return sd;