From: Pingfan Liu <kernelfans@gmail.com>
To: linux-pci@vger.kernel.org
Cc: Bjorn Helgaas <bhelgaas@google.com>,
Christoph Hellwig <hch@infradead.org>,
linuxppc-dev@lists.ozlabs.org
Subject: [patchV2 1/2] pci: introduce an extra method for matching in pci_driver
Date: Wed, 13 Jun 2018 14:29:56 +0800 [thread overview]
Message-ID: <1528871397-17917-2-git-send-email-kernelfans@gmail.com> (raw)
In-Reply-To: <1528871397-17917-1-git-send-email-kernelfans@gmail.com>
In __driver_attach(), if a driver matches a device, the device will
be appended to the tail of devices_kset, no matter what the probing
result of the device. Hence in order to prevent a driver to append
a probed device to devices_kset, it requires a correct matching.
As for pci, pci driver uses pci_device_id to match a device. But it may
be not enough, since there is need for extra info such as pcie, which
can not be provided in pci_device_id. Such info is driver specific, and
this patch introduces a new method "extra_match" in pci_driver.
This is used by next patch.
Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
---
drivers/pci/pci-driver.c | 4 ++++
include/linux/pci.h | 2 ++
2 files changed, 6 insertions(+)
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index b9a1311..151865f 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -273,6 +273,10 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv,
if (!found_id && dev->driver_override)
found_id = &pci_device_id_any;
+ /* more strictly matching besides id_table */
+ if (drv->extra_match && drv->extra_match(dev) < 0)
+ found_id = NULL;
+
return found_id;
}
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 73178a2..6ed960d 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -738,10 +738,12 @@ struct pci_error_handlers {
struct module;
+typedef int (*ematch)(struct pci_dev *pdev);
struct pci_driver {
struct list_head node;
const char *name;
const struct pci_device_id *id_table; /* Must be non-NULL for probe to be called */
+ ematch extra_match; /* more strictly matching besides id_table */
int (*probe)(struct pci_dev *dev, const struct pci_device_id *id); /* New device inserted */
void (*remove)(struct pci_dev *dev); /* Device removed (NULL if not a hot-plug capable driver) */
int (*suspend)(struct pci_dev *dev, pm_message_t state); /* Device suspended */
--
2.7.4
next prev parent reply other threads:[~2018-06-13 6:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-13 6:29 [patchV2 0/2] shpchp: no claim on pcie port device Pingfan Liu
2018-06-13 6:29 ` Pingfan Liu [this message]
2018-06-13 6:37 ` [patchV2 1/2] pci: introduce an extra method for matching in pci_driver Christoph Hellwig
2018-06-13 7:28 ` Pingfan Liu
2018-06-13 6:29 ` [patchV2 2/2] pci/shpchp: no claim on pcie port device Pingfan Liu
2018-06-13 13:13 ` Bjorn Helgaas
2018-06-25 2:59 ` Pingfan Liu
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=1528871397-17917-2-git-send-email-kernelfans@gmail.com \
--to=kernelfans@gmail.com \
--cc=bhelgaas@google.com \
--cc=hch@infradead.org \
--cc=linux-pci@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.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;
as well as URLs for NNTP newsgroup(s).