]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
sysfs: use atomic_inc_unless_negative in sysfs_get_active
authorMaarten Lankhorst <m.b.lankhorst@gmail.com>
Fri, 8 Mar 2013 15:07:27 +0000 (16:07 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 25 Mar 2013 17:42:36 +0000 (10:42 -0700)
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: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/sysfs/dir.c

index 2fbdff6be25ce3d546e17fa4e72783e9d3f03637..7f968ede20d67dc02d88ed3e665c7ffdde443084 100644 (file)
@@ -165,21 +165,8 @@ 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)
-                       return NULL;
-
-               cpu_relax();
-       }
+       if (!atomic_inc_unless_negative(&sd->s_active))
+               return NULL;
 
        if (likely(!ignore_lockdep(sd)))
                rwsem_acquire_read(&sd->dep_map, 0, 1, _RET_IP_);