From: "Dave Young" <hidave.darkstar@gmail.com>
To: "Cornelia Huck" <cornelia.huck@de.ibm.com>
Cc: gregkh@suse.de, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] driver-core : get_device before create/remove sysfs files
Date: Thu, 31 Jan 2008 09:17:18 +0800 [thread overview]
Message-ID: <a8e1da0801301717v1ca21bd7y6ecf16065fe34f7d@mail.gmail.com> (raw)
In-Reply-To: <20080130113257.53555fee@gondolin.boeblingen.de.ibm.com>
On Jan 30, 2008 6:32 PM, Cornelia Huck <cornelia.huck@de.ibm.com> wrote:
> On Wed, 30 Jan 2008 09:56:25 +0800,
> Dave Young <hidave.darkstar@gmail.com> wrote:
>
> > get dev reference before create/remove sysfiles, errno fixes as well.
> >
> > Signed-off-by: Dave Young <hidave.darkstar@gmail.com>
> >
> > ---
> > drivers/base/core.c | 12 ++++++++----
> > 1 file changed, 8 insertions(+), 4 deletions(-)
> >
> > diff -upr a/drivers/base/core.c b/drivers/base/core.c
> > --- a/drivers/base/core.c 2008-01-30 09:49:56.000000000 +0800
> > +++ b/drivers/base/core.c 2008-01-30 09:49:56.000000000 +0800
> > @@ -414,7 +414,7 @@ struct kset *devices_kset;
> > */
> > int device_create_file(struct device *dev, struct device_attribute *attr)
> > {
> > - int error = 0;
> > + int error = -ENODEV;
>
> Uhm... why?
In this function :
if (get_device(dev)) {
do create issue
}
return error
So IMO the initial error should be -ENODEV
>
> > if (get_device(dev)) {
> > error = sysfs_create_file(&dev->kobj, &attr->attr);
> > put_device(dev);
> > @@ -442,9 +442,11 @@ void device_remove_file(struct device *d
> > */
> > int device_create_bin_file(struct device *dev, struct bin_attribute *attr)
> > {
> > - int error = -EINVAL;
> > - if (dev)
> > + int error = -ENODEV;
> > + if (get_device(dev)) {
> > error = sysfs_create_bin_file(&dev->kobj, attr);
> > + put_device(dev);
> > + }
>
> Why do we need to grab a reference here? If the calling site doesn't
> hold unto a reference already, something is seriously broken.
First, we should keep consistent with previous function "device_create_file";
Second, AFAIK this function mostly are called after something like device_add
and the dev reference are not hold.
>
> > return error;
> > }
> > EXPORT_SYMBOL_GPL(device_create_bin_file);
> > @@ -456,8 +458,10 @@ EXPORT_SYMBOL_GPL(device_create_bin_file
> > */
> > void device_remove_bin_file(struct device *dev, struct bin_attribute *attr)
> > {
> > - if (dev)
> > + if (get_device(dev)) {
> > sysfs_remove_bin_file(&dev->kobj, attr);
> > + put_device(dev);
> > + }
>
> Dito.
>
>
> > }
> > EXPORT_SYMBOL_GPL(device_remove_bin_file);
>
next prev parent reply other threads:[~2008-01-31 1:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-30 1:56 Dave Young
2008-01-30 10:32 ` Cornelia Huck
2008-01-31 1:17 ` Dave Young [this message]
2008-01-31 9:39 ` Cornelia Huck
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=a8e1da0801301717v1ca21bd7y6ecf16065fe34f7d@mail.gmail.com \
--to=hidave.darkstar@gmail.com \
--cc=cornelia.huck@de.ibm.com \
--cc=gregkh@suse.de \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®