public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: Maarten Lankhorst <m.b.lankhorst@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] sysfs: use atomic_inc_unless_negative in sysfs_get_active
Date: Mon, 18 Mar 2013 17:29:42 -0700	[thread overview]
Message-ID: <20130319002942.GI3042@htj.dyndns.org> (raw)
In-Reply-To: <20130319001418.GA13502@kroah.com>

On Mon, Mar 18, 2013 at 05:14:18PM -0700, Greg KH wrote:
> 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@canonical.com>
> >  ---
> 
> Tejun wrote this code originally, so I'll defer to him as to if the
> patch below is a valid cleanup or not.

Yeah, I think that code predates atomic_inc_unless_negative().

> > 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;

Looks good to me.

Acked-by: Tejun Heo <tj@kernel.org>

Thanks.

-- 
tejun

      reply	other threads:[~2013-03-19  0:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-08 15:07 [PATCH] sysfs: use atomic_inc_unless_negative in sysfs_get_active Maarten Lankhorst
2013-03-19  0:14 ` Greg KH
2013-03-19  0:29   ` Tejun Heo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130319002942.GI3042@htj.dyndns.org \
    --to=tj@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.b.lankhorst@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox