lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20130319001418.GA13502@kroah.com>
Date:	Mon, 18 Mar 2013 17:14:18 -0700
From:	Greg KH <gregkh@...uxfoundation.org>
To:	Maarten Lankhorst <m.b.lankhorst@...il.com>, tj@...nel.org
Cc:	LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] sysfs: use atomic_inc_unless_negative in sysfs_get_active

On Fri, Mar 08, 2013 at 04:07:27PM +0100, Maarten Lankhorst wrote:
> 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@...onical.com>
>  ---

Tejun wrote this code originally, so I'll defer to him as to if the
patch below is a valid cleanup or not.

Tejun?


> 
> diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
> index 2fbdff6..7f968ed 100644
> --- a/fs/sysfs/dir.c
> +++ b/fs/sysfs/dir.c
> @@ -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_);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ