diff mbox

[patchV2,1/2] pci: introduce an extra method for matching in pci_driver

Message ID 1528871397-17917-2-git-send-email-kernelfans@gmail.com (mailing list archive)
State New, archived
Delegated to: Bjorn Helgaas
Headers show

Commit Message

Pingfan Liu June 13, 2018, 6:29 a.m. UTC
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(+)

Comments

Christoph Hellwig June 13, 2018, 6:37 a.m. UTC | #1
If we successfull call ->probe twice on a device we have a much
deeper problem than we can fix in the PCI layer or shpchp.

Please explain the actual race or other condition that can lead to
this and report it to the driver core maintainer.
Pingfan Liu June 13, 2018, 7:28 a.m. UTC | #2
On Wed, Jun 13, 2018 at 2:37 PM Christoph Hellwig <hch@infradead.org> wrote:
>
> If we successfull call ->probe twice on a device we have a much
> deeper problem than we can fix in the PCI layer or shpchp.
>
OK, see your point.

> Please explain the actual race or other condition that can lead to
> this and report it to the driver core maintainer.
Oh, then it should be. I will add more debug info to narrow down the
problem, and report it to driver core maintainer.

Thanks for your kindly review.

Regards,
Pingfan
diff mbox

Patch

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 */