From: Yijing Wang <wangyijing@huawei.com>
To: Yinghai Lu <yinghai@kernel.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>
Subject: Re: [PATCH] PCI: fix return in pci_bus_add_device
Date: Thu, 29 May 2014 09:37:04 +0800 [thread overview]
Message-ID: <53868F40.8000909@huawei.com> (raw)
In-Reply-To: <CAE9FiQWM15UHvX=7wv4aMXfTp5QLsB+J9c1qjOzpZ1vU0ePB4A@mail.gmail.com>
>> I found some kernel code still check this return value, and I also think return the
>> real retval make sense.
>
> No, that is not right.
>
> If you look closely,
>
> device_attach() returns
> 1: success
> 0: not attached
> <0: fail.
Hi Yinghai,
Thanks for your explanation.
I found all the kernel code to check its return value, only for print a warning for users.
So I think we can drop all return checking from calling path, or rework pci_bus_add_device(),
return 0 if device_attach success, otherwise return -1, indicates the device not bound to a driver.
int pci_bus_add_device(struct pci_dev *dev)
{
int retval;
/*
* Can not put in pci_device_add yet because resources
* are not assigned yet for some devices.
*/
pci_fixup_device(pci_fixup_final, dev);
pci_create_sysfs_dev_files(dev);
pci_proc_attach_device(dev);
dev->match_driver = true;
retval = device_attach(&dev->dev);
WARN_ON(retval < 0);
dev->is_added = 1;
return retval >=0 ? 0:-1;
}
Yinghai, which solution would you prefer?
Thanks!
Yijing.
>
> so if you return ret directly, you have false warning from
>
> drivers/edac/i82875p_edac.c: err = pci_bus_add_device(dev);
> drivers/edac/i82875p_edac.c: "%s():
> pci_bus_add_device() Failed\n",
> drivers/platform/x86/asus-wmi.c: if
> (pci_bus_add_device(dev))
> drivers/platform/x86/eeepc-laptop.c: if
> (pci_bus_add_device(dev))
>
> We already have
> WARN_ON(retval < 0);
>
> so please just remove all return checking from calling path.
> compiler already drop them...
>
>>
>> eg.
>>
>> list_for_each_entry(dev, &bus->devices, bus_list) {
>> /* Skip already-added devices */
>> if (dev->is_added)
>> continue;
>> retval = pci_bus_add_device(dev);
>> if (retval)
>> dev_err(&dev->dev, "Error adding device (%d)\n",
>> retval);
>
> should be dropped.
>
>> }
>>
>>
>>
>> if (!blocked) {
>> dev = pci_get_slot(bus, 0);
>> if (dev) {
>> /* Device already present */
>> pci_dev_put(dev);
>> goto out_put_dev;
>> }
>> dev = pci_scan_single_device(bus, 0);
>> if (dev) {
>> pci_bus_assign_resources(bus);
>> if (pci_bus_add_device(dev))
>> pr_err("Unable to hotplug wifi\n");
> oh, no, no one have that report. instead if should have trace printed out.
>> }
>
> Thanks
>
> Yinghai
>
> .
>
--
Thanks!
Yijing
next prev parent reply other threads:[~2014-05-29 1:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-22 3:32 [PATCH] PCI: fix return in pci_bus_add_device Yijing Wang
2014-05-28 3:22 ` Bjorn Helgaas
2014-05-28 3:32 ` Yijing Wang
2014-05-29 0:28 ` Yinghai Lu
2014-05-29 1:37 ` Yijing Wang [this message]
2014-05-29 3:36 ` Yinghai Lu
2014-05-29 3:53 ` Yijing Wang
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=53868F40.8000909@huawei.com \
--to=wangyijing@huawei.com \
--cc=bhelgaas@google.com \
--cc=linux-pci@vger.kernel.org \
--cc=yinghai@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 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.