public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Pete Zaitcev <zaitcev@redhat.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: get_device in device_create_file
Date: Thu, 3 Aug 2006 00:52:36 -0700	[thread overview]
Message-ID: <20060803075236.GC28301@kroah.com> (raw)
In-Reply-To: <20060801132509.27269013.zaitcev@redhat.com>

On Tue, Aug 01, 2006 at 01:25:09PM -0700, Pete Zaitcev wrote:
> Hi, Greg:
> 
> This code makes no sense to me:
> 
> > int device_create_file(struct device * dev, struct device_attribute * attr)
> > {
> > 	int error = 0;
> > 	if (get_device(dev)) {
> > 		error = sysfs_create_file(&dev->kobj, &attr->attr);
> > 		put_device(dev);
> > 	}
> > 	return error;
> > }
> 
> If the struct device *dev, and its presumably enclosing structure,
> can be freed by a different CPU (or pre-empt), then get_device
> does not protect it. It can be freed before get_device is reached.
> Buf it not, and the caller has a reference, then the call to
> get_device is redundant.

Yes, it is redundant, sorry.  I know there are a few places that we
gratuitously grab references in the core that we don't really need to do
so.

It's interesting that someone would cut-and-paste from a driver core
file into something new.  What kind of code did they do that for?

Anyway, patches to clean this kind of stuff up is gladly accepted.

thanks,

greg k-h

      parent reply	other threads:[~2006-08-03  7:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-01 20:25 get_device in device_create_file Pete Zaitcev
2006-08-02  1:13 ` Dmitry Torokhov
2006-08-02 21:49   ` Pete Zaitcev
2006-08-03  7:52 ` Greg KH [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=20060803075236.GC28301@kroah.com \
    --to=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zaitcev@redhat.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