Skip to contentSkip to conversation

driver-core: Implement device_match_always()

PATCH In review Thierry Reding 2 participants 5 messages Jun 6, 2016 – Jun 10, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 driver-core: Implement device_match_always()

From: Thierry Reding <[email protected]>

This is a helper function that can be used in iterators, such as bus_find_device(), and will always match. This is useful to implement a custom iterator interface on top of bus_find_device() or to check if any devices have been registered at all.

---
 include/linux/device.h | 5 +++++
 1 file changed, 5 insertions(+)
include/linux/device.h +5 -0
index 38f02814d53a..bea9566cea96 100644
@@ -1031,6 +1031,11 @@ extern int device_online(struct device *dev);
 extern void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
 extern void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
 
+static inline int device_match_always(struct device *device, void *data)
+{
+	return 1;
+}
+
 /*
  * Root device objects for grouping under /sys/devices
  */
Signature · 1 line
2.8.3
#1 lore raw

PATCH 2/3 PCI: Use device_match_always()

From: Thierry Reding <[email protected]>

There is now a common implementation for a match function that will always match, so the PCI-specific implementation can be removed.

---
 drivers/pci/probe.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/pci/probe.c +1 -6
index 8e3ef720997d..3db06d8d6497 100644
@@ -62,11 +62,6 @@ static struct resource *get_pci_domain_busn_res(int domain_nr)
 	return &r->res;
 }
 
-static int find_anything(struct device *dev, void *data)
-{
-	return 1;
-}
-
 /*
  * Some device drivers need know if pci is initiated.
  * Basically, we think pci is not initiated when there
@@ -77,7 +72,7 @@ int no_pci_devices(void)
 	struct device *dev;
 	int no_devices;
 
-	dev = bus_find_device(&pci_bus_type, NULL, NULL, find_anything);
+	dev = bus_find_device(&pci_bus_type, NULL, NULL, device_match_always);
 	no_devices = (dev == NULL);
 	put_device(dev);
 	return no_devices;
Signature · 1 line
2.8.3
Acked-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] PCI: Use device_match_always()

Quoted 6 lines · Thierry Reding

From: Thierry Reding <[email protected]>

There is now a common implementation for a match function that will always match, so the PCI-specific implementation can be removed.

I'm sort of OK with this. It's clearly not going to break anything.

But I would far rather figure out a way to remove no_pci_devices() completely. There's only one in-tree caller, and it's sort of dubious, although the idea was added by Linus (2bff5e94f1bf).

I suppose nowadays we would use ACPI or DMI to do this. But I guess this is OK as-is. It'd be pretty hard to find a PC110 to test any real driver changes.

I assume all three of these patches would get merged together by somebody else.

Quoted 36 lines
---
 drivers/pci/probe.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/pci/probe.c +1 -6
index 8e3ef720997d..3db06d8d6497 100644
@@ -62,11 +62,6 @@ static struct resource *get_pci_domain_busn_res(int domain_nr)
 	return &r->res;
 }
 
-static int find_anything(struct device *dev, void *data)
-{
-	return 1;
-}
-
 /*
  * Some device drivers need know if pci is initiated.
  * Basically, we think pci is not initiated when there
@@ -77,7 +72,7 @@ int no_pci_devices(void)
 	struct device *dev;
 	int no_devices;
 
-	dev = bus_find_device(&pci_bus_type, NULL, NULL, find_anything);
+	dev = bus_find_device(&pci_bus_type, NULL, NULL, device_match_always);
 	no_devices = (dev == NULL);
 	put_device(dev);
 	return no_devices;
Signature · 6 lines
2.8.3

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

Re: [PATCH 2/3] PCI: Use device_match_always()

Quoted 8 lines · Bjorn Helgaas
Quoted 6 lines · Thierry Reding

From: Thierry Reding <[email protected]>

There is now a common implementation for a match function that will always match, so the PCI-specific implementation can be removed.

Quoted 7 lines

I'm sort of OK with this. It's clearly not going to break anything.

But I would far rather figure out a way to remove no_pci_devices() completely. There's only one in-tree caller, and it's sort of dubious, although the idea was added by Linus (2bff5e94f1bf).

This is sort of a spin-off from another series that I sent out, which introduced a common function that was used in far more places and has a more clearly legitimate use. While working on that other series the duplication here occurred to me, so I thought I'd remove it while at it, even if there are only two occurrences.

Quoted 6 lines

I suppose nowadays we would use ACPI or DMI to do this. But I guess this is OK as-is. It'd be pretty hard to find a PC110 to test any real driver changes.

I assume all three of these patches would get merged together by somebody else.

I was thinking Greg could take them through the driver core tree.

Thierry

#4 lore raw

PATCH 3/3 scsi: Use device_match_always()

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

There is now a common implementation for a match function that will always match, so the SCSI-specific implementation can be removed.

---
 drivers/scsi/scsi_proc.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/scsi/scsi_proc.c +1 -6
index 7a74b82e8973..4adcdc2caf27 100644
@@ -371,15 +371,10 @@ static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
 	return err;
 }
 
-static int always_match(struct device *dev, void *data)
-{
-	return 1;
-}
-
 static inline struct device *next_scsi_device(struct device *start)
 {
 	struct device *next = bus_find_device(&scsi_bus_type, start, NULL,
-					      always_match);
+					      device_match_always);
 	put_device(start);
 	return next;
 }
Signature · 1 line
2.8.3