All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Andrew Morton <akpm@osdl.org>
Cc: Paul Mackerras <paulus@samba.org>, linux-kernel@vger.kernel.org
Subject: Re: Why is device_create_file __must_check?
Date: Mon, 9 Oct 2006 22:04:53 -0700	[thread overview]
Message-ID: <20061010050453.GA5479@kroah.com> (raw)
In-Reply-To: <20061009214936.a2788702.akpm@osdl.org>

On Mon, Oct 09, 2006 at 09:49:36PM -0700, Andrew Morton wrote:
> On Tue, 10 Oct 2006 14:32:33 +1000
> Paul Mackerras <paulus@samba.org> wrote:
> 
> > I am seeing a bunch of warnings about not checking the return value
> > from device_create_file() for code like this (from
> > arch/powerpc/kernel/pci_64.c):
> > 
> > static ssize_t pci_show_devspec(struct device *dev,
> > 		struct device_attribute *attr, char *buf)
> > {
> > 	struct pci_dev *pdev;
> > 	struct device_node *np;
> > 
> > 	pdev = to_pci_dev (dev);
> > 	np = pci_device_to_OF_node(pdev);
> > 	if (np == NULL || np->full_name == NULL)
> > 		return 0;
> > 	return sprintf(buf, "%s", np->full_name);
> > }
> > static DEVICE_ATTR(devspec, S_IRUGO, pci_show_devspec, NULL);
> > 
> > void pcibios_add_platform_entries(struct pci_dev *pdev)
> > {
> > 	device_create_file(&pdev->dev, &dev_attr_devspec);
> > }
> > 
> > What bad thing could happen if device_create_file fails, other than
> > that the "devspec" file doesn't appear in sysfs?
> 
> There are no super-strong reasons here, but if device_create_file() fails
> then the required control files aren't there and the subsystem isn't
> working as intended.  If it's in a module then we should fail the modprobe. 
> If it's a bootup thing then best we can do is to panic.  Or at least log
> the event.
> 
> The most common cause of this is a programming error: we tried to create
> the same entry twice.   We want to know about that.

Exactly, that's the most common cause here (different programmers trying
to create the same file in the same place.)  That needs to error out so
that it is caught properly.

thanks,

greg k-h

  reply	other threads:[~2006-10-10  5:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-10  4:32 Why is device_create_file __must_check? Paul Mackerras
2006-10-10  4:49 ` Andrew Morton
2006-10-10  5:04   ` Greg KH [this message]
2006-10-10  5:14   ` Paul Mackerras
2006-10-10  5:26     ` Andrew Morton
2006-10-10  7:03       ` Paul Mackerras
2006-10-10  5:27     ` Greg KH

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=20061010050453.GA5479@kroah.com \
    --to=greg@kroah.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulus@samba.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.