History

Merge tag 'generic_lookup_helpers' into for-next

Generic Device Lookup Helpers Persistent tag for others to pull this branch from Based on patch series from Suzuki K Poulose <suzuki.poulose@arm.com> with Subject: [PATCH v3 0/7] drivers: Add generic device lookup helpers Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> * tag 'generic_lookup_helpers': platform: Add platform_find_device_by_driver() helper drivers: Add generic helper to match any device drivers: Introduce device lookup variants by ACPI_COMPANION device drivers: Introduce device lookup variants by device type drivers: Introduce device lookup variants by fwnode drivers: Introduce device lookup variants by of_node drivers: Introduce device lookup variants by name

Jacek Anaszewski committed 7 years ago

Commit be7fc2c2 parents af7b650 36f331348 files · +341 −383Browse files

Unified · Split

48 files
  1. drivers/amba/tegra-ahb.c +1 −10
  2. drivers/base/bus.c +0 −24
  3. drivers/base/core.c +31 −8
  4. drivers/base/devcon.c +1 −7
  5. drivers/base/platform.c +14 −0
  6. drivers/fpga/fpga-bridge.c +1 −7
  7. drivers/fpga/fpga-mgr.c +1 −7
  8. drivers/gpu/drm/drm_mipi_dsi.c +1 −6
  9. drivers/gpu/drm/exynos/exynos_drm_drv.c +3 −6
  10. drivers/gpu/drm/mcde/mcde_drv.c +1 −2
  11. drivers/gpu/drm/rockchip/rockchip_drm_drv.c +1 −2
  12. drivers/gpu/drm/vc4/vc4_drv.c +1 −2
  13. drivers/hwtracing/coresight/coresight-platform.c +2 −9
  14. drivers/hwtracing/coresight/coresight-priv.h +0 −2
  15. drivers/hwtracing/coresight/coresight.c +1 −3
  16. drivers/hwtracing/intel_th/core.c +1 −9
  17. drivers/hwtracing/stm/core.c +1 −8
  18. drivers/i2c/busses/i2c-amd-mp2-pci.c +1 −7
  19. drivers/i2c/i2c-core-acpi.c +2 −9
  20. drivers/i2c/i2c-core-of.c +1 −6
  21. drivers/infiniband/hw/hns/hns_roce_hw_v1.c +1 −7
  22. drivers/iommu/arm-smmu-v3.c +2 −7
  23. drivers/iommu/arm-smmu.c +2 −7
  24. drivers/leds/led-class.c +1 −8
  25. drivers/mfd/altera-sysmgr.c +2 −12
  26. drivers/misc/mei/main.c +1 −8
  27. drivers/mux/core.c +1 −6
  28. drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c +1 −7
  29. drivers/net/phy/mdio_bus.c +1 −8
  30. drivers/nvmem/core.c +1 −6
  31. drivers/of/of_mdio.c +1 −7
  32. drivers/of/platform.c +1 −6
  33. drivers/pci/probe.c +1 −6
  34. drivers/regulator/of_regulator.c +1 −6
  35. drivers/rtc/interface.c +1 −10
  36. drivers/s390/cio/ccwgroup.c +2 −16
  37. drivers/s390/cio/device.c +1 −14
  38. drivers/s390/crypto/zcrypt_api.c +2 −20
  39. drivers/scsi/scsi_proc.c +2 −7
  40. drivers/spi/spi.c +5 −23
  41. drivers/tty/tty_io.c +1 −7
  42. drivers/usb/core/devio.c +1 −7
  43. drivers/usb/roles/class.c +2 −14
  44. drivers/usb/typec/class.c +2 −14
  45. include/linux/device.h +234 −3
  46. include/linux/platform_device.h +3 −0
  47. net/ieee802154/core.c +1 −6
  48. sound/soc/rockchip/rk3399_gru_sound.c +2 −7
drivers/amba/tegra-ahb.c+1−10
@@ -134,22 +134,13 @@ static inline void gizmo_writel(struct tegra_ahb *ahb, u32 value, u32 offset) · 133 unmodified lines
134134 }
135135
136136 #ifdef CONFIG_TEGRA_IOMMU_SMMU
137−static int tegra_ahb_match_by_smmu(struct device *dev, const void *data)
138−{
139− struct tegra_ahb *ahb = dev_get_drvdata(dev);
140− const struct device_node *dn = data;
141−
142− return (ahb->dev->of_node == dn) ? 1 : 0;
143−}
144−
145137 int tegra_ahb_enable_smmu(struct device_node *dn)
146138 {
147139 struct device *dev;
148140 u32 val;
149141 struct tegra_ahb *ahb;
150142
151− dev = driver_find_device(&tegra_ahb_driver.driver, NULL, dn,
152− tegra_ahb_match_by_smmu);
143+ dev = driver_find_device_by_of_node(&tegra_ahb_driver.driver, dn);
153144 if (!dev)
154145 return -EPROBE_DEFER;
155146 ahb = dev_get_drvdata(dev);
drivers/base/bus.c+0−24
@@ -342,30 +342,6 @@ struct device *bus_find_device(struct bus_type *bus, · 341 unmodified lines
342342 }
343343 EXPORT_SYMBOL_GPL(bus_find_device);
344344
345−static int match_name(struct device *dev, const void *data)
346−{
347− const char *name = data;
348−
349− return sysfs_streq(name, dev_name(dev));
350−}
351−
352−/**
353− * bus_find_device_by_name - device iterator for locating a particular device of a specific name
354− * @bus: bus type
355− * @start: Device to begin with
356− * @name: name of the device to match
357− *
358− * This is similar to the bus_find_device() function above, but it handles
359− * searching by a name automatically, no need to write another strcmp matching
360− * function.
361− */
362−struct device *bus_find_device_by_name(struct bus_type *bus,
363− struct device *start, const char *name)
364−{
365− return bus_find_device(bus, start, (void *)name, match_name);
366−}
367−EXPORT_SYMBOL_GPL(bus_find_device_by_name);
368−
369345 /**
370346 * subsys_find_device_by_id - find a device with a specific enumeration number
371347 * @subsys: subsystem
drivers/base/core.c+31−8
@@ -2867,13 +2867,6 @@ struct device *device_create_with_groups(struct class *class, · 2866 unmodified lines
28672867 }
28682868 EXPORT_SYMBOL_GPL(device_create_with_groups);
28692869
2870−static int __match_devt(struct device *dev, const void *data)
2871−{
2872− const dev_t *devt = data;
2873−
2874− return dev->devt == *devt;
2875−}
2876−
28772870 /**
28782871 * device_destroy - removes a device that was created with device_create()
28792872 * @class: pointer to the struct class that this device was registered with
@@ -2886,7 +2879,7 @@ void device_destroy(struct class *class, dev_t devt) · 6 unmodified lines
28862879 {
28872880 struct device *dev;
28882881
2889− dev = class_find_device(class, NULL, &devt, __match_devt);
2882+ dev = class_find_device_by_devt(class, devt);
28902883 if (dev) {
28912884 put_device(dev);
28922885 device_unregister(dev);
@@ -3357,8 +3350,38 @@ void device_set_of_node_from_dev(struct device *dev, const struct device *dev2) · 464 unmodified lines
33573350 }
33583351 EXPORT_SYMBOL_GPL(device_set_of_node_from_dev);
33593352
3353+int device_match_name(struct device *dev, const void *name)
3354+{
3355+ return sysfs_streq(dev_name(dev), name);
3356+}
3357+EXPORT_SYMBOL_GPL(device_match_name);
3358+
33603359 int device_match_of_node(struct device *dev, const void *np)
33613360 {
33623361 return dev->of_node == np;
33633362 }
33643363 EXPORT_SYMBOL_GPL(device_match_of_node);
3364+
3365+int device_match_fwnode(struct device *dev, const void *fwnode)
3366+{
3367+ return dev_fwnode(dev) == fwnode;
3368+}
3369+EXPORT_SYMBOL_GPL(device_match_fwnode);
3370+
3371+int device_match_devt(struct device *dev, const void *pdevt)
3372+{
3373+ return dev->devt == *(dev_t *)pdevt;
3374+}
3375+EXPORT_SYMBOL_GPL(device_match_devt);
3376+
3377+int device_match_acpi_dev(struct device *dev, const void *adev)
3378+{
3379+ return ACPI_COMPANION(dev) == adev;
3380+}
3381+EXPORT_SYMBOL(device_match_acpi_dev);
3382+
3383+int device_match_any(struct device *dev, const void *unused)
3384+{
3385+ return 1;
3386+}
3387+EXPORT_SYMBOL_GPL(device_match_any);
drivers/base/devcon.c+1−7
@@ -133,19 +133,13 @@ static struct bus_type *generic_match_buses[] = { · 132 unmodified lines
133133 NULL,
134134 };
135135
136−static int device_fwnode_match(struct device *dev, const void *fwnode)
137−{
138− return dev_fwnode(dev) == fwnode;
139−}
140−
141136 static void *device_connection_fwnode_match(struct device_connection *con)
142137 {
143138 struct bus_type *bus;
144139 struct device *dev;
145140
146141 for (bus = generic_match_buses[0]; bus; bus++) {
147− dev = bus_find_device(bus, NULL, (void *)con->fwnode,
148− device_fwnode_match);
142+ dev = bus_find_device_by_fwnode(bus, con->fwnode);
149143 if (dev && !strncmp(dev_name(dev), con->id, strlen(con->id)))
150144 return dev;
151145
drivers/base/platform.c+14−0
@@ -1197,6 +1197,20 @@ struct bus_type platform_bus_type = { · 1196 unmodified lines
11971197 };
11981198 EXPORT_SYMBOL_GPL(platform_bus_type);
11991199
1200+/**
1201+ * platform_find_device_by_driver - Find a platform device with a given
1202+ * driver.
1203+ * @start: The device to start the search from.
1204+ * @drv: The device driver to look for.
1205+ */
1206+struct device *platform_find_device_by_driver(struct device *start,
1207+ const struct device_driver *drv)
1208+{
1209+ return bus_find_device(&platform_bus_type, start, drv,
1210+ (void *)platform_match);
1211+}
1212+EXPORT_SYMBOL_GPL(platform_find_device_by_driver);
1213+
12001214 int __init platform_bus_init(void)
12011215 {
12021216 int error;
drivers/fpga/fpga-bridge.c+1−7
@@ -19,11 +19,6 @@ static struct class *fpga_bridge_class; · 18 unmodified lines
1919 /* Lock for adding/removing bridges to linked lists*/
2020 static spinlock_t bridge_list_lock;
2121
22−static int fpga_bridge_of_node_match(struct device *dev, const void *data)
23−{
24− return dev->of_node == data;
25−}
26−
2722 /**
2823 * fpga_bridge_enable - Enable transactions on the bridge
2924 *
@@ -104,8 +99,7 @@ struct fpga_bridge *of_fpga_bridge_get(struct device_node *np, · 74 unmodified lines
10499 {
105100 struct device *dev;
106101
107− dev = class_find_device(fpga_bridge_class, NULL, np,
108− fpga_bridge_of_node_match);
102+ dev = class_find_device_by_of_node(fpga_bridge_class, np);
109103 if (!dev)
110104 return ERR_PTR(-ENODEV);
111105
drivers/fpga/fpga-mgr.c+1−7
@@ -482,11 +482,6 @@ struct fpga_manager *fpga_mgr_get(struct device *dev) · 481 unmodified lines
482482 }
483483 EXPORT_SYMBOL_GPL(fpga_mgr_get);
484484
485−static int fpga_mgr_of_node_match(struct device *dev, const void *data)
486−{
487− return dev->of_node == data;
488−}
489−
490485 /**
491486 * of_fpga_mgr_get - Given a device node, get a reference to a fpga mgr.
492487 *
@@ -498,8 +493,7 @@ struct fpga_manager *of_fpga_mgr_get(struct device_node *node) · 5 unmodified lines
498493 {
499494 struct device *dev;
500495
501− dev = class_find_device(fpga_mgr_class, NULL, node,
502− fpga_mgr_of_node_match);
496+ dev = class_find_device_by_of_node(fpga_mgr_class, node);
503497 if (!dev)
504498 return ERR_PTR(-ENODEV);
505499
drivers/gpu/drm/drm_mipi_dsi.c+1−6
@@ -93,11 +93,6 @@ static struct bus_type mipi_dsi_bus_type = { · 92 unmodified lines
9393 .pm = &mipi_dsi_device_pm_ops,
9494 };
9595
96−static int of_device_match(struct device *dev, const void *data)
97−{
98− return dev->of_node == data;
99−}
100−
10196 /**
10297 * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a
10398 * device tree node
@@ -110,7 +105,7 @@ struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np) · 6 unmodified lines
110105 {
111106 struct device *dev;
112107
113− dev = bus_find_device(&mipi_dsi_bus_type, NULL, np, of_device_match);
108+ dev = bus_find_device_by_of_node(&mipi_dsi_bus_type, np);
114109
115110 return dev ? to_mipi_dsi_device(dev) : NULL;
116111 }
drivers/gpu/drm/exynos/exynos_drm_drv.c+3−6
@@ -242,9 +242,7 @@ static struct component_match *exynos_drm_match_add(struct device *dev) · 241 unmodified lines
242242 if (!info->driver || !(info->flags & DRM_COMPONENT_DRIVER))
243243 continue;
244244
245− while ((d = bus_find_device(&platform_bus_type, p,
246− &info->driver->driver,
247− (void *)platform_bus_type.match))) {
245+ while ((d = platform_find_device_by_driver(p, &info->driver->driver))) {
248246 put_device(p);
249247
250248 if (!(info->flags & DRM_FIMC_DEVICE) ||
@@ -412,9 +410,8 @@ static void exynos_drm_unregister_devices(void) · 161 unmodified lines
412410 if (!info->driver || !(info->flags & DRM_VIRTUAL_DEVICE))
413411 continue;
414412
415− while ((dev = bus_find_device(&platform_bus_type, NULL,
416− &info->driver->driver,
417− (void *)platform_bus_type.match))) {
413+ while ((dev = platform_find_device_by_driver(NULL,
414+ &info->driver->driver))) {
418415 put_device(dev);
419416 platform_device_unregister(to_platform_device(dev));
420417 }
drivers/gpu/drm/mcde/mcde_drv.c+1−2
@@ -477,8 +477,7 @@ static int mcde_probe(struct platform_device *pdev) · 476 unmodified lines
477477 struct device_driver *drv = &mcde_component_drivers[i]->driver;
478478 struct device *p = NULL, *d;
479479
480− while ((d = bus_find_device(&platform_bus_type, p, drv,
481− (void *)platform_bus_type.match))) {
480+ while ((d = platform_find_device_by_driver(p, drv))) {
482481 put_device(p);
483482 component_match_add(dev, &match, mcde_compare_dev, d);
484483 p = d;
drivers/gpu/drm/rockchip/rockchip_drm_drv.c+1−2
@@ -330,8 +330,7 @@ static struct component_match *rockchip_drm_match_add(struct device *dev) · 329 unmodified lines
330330 struct device *p = NULL, *d;
331331
332332 do {
333− d = bus_find_device(&platform_bus_type, p, &drv->driver,
334− (void *)platform_bus_type.match);
333+ d = platform_find_device_by_driver(p, &drv->driver);
335334 put_device(p);
336335 p = d;
337336
drivers/gpu/drm/vc4/vc4_drv.c+1−2
@@ -237,8 +237,7 @@ static void vc4_match_add_drivers(struct device *dev, · 236 unmodified lines
237237 struct device_driver *drv = &drivers[i]->driver;
238238 struct device *p = NULL, *d;
239239
240− while ((d = bus_find_device(&platform_bus_type, p, drv,
241− (void *)platform_bus_type.match))) {
240+ while ((d = platform_find_device_by_driver(p, drv))) {
242241 put_device(p);
243242 component_match_add(dev, match, compare_dev, d);
244243 p = d;
drivers/hwtracing/coresight/coresight-platform.c+2−9
@@ -37,11 +37,6 @@ static int coresight_alloc_conns(struct device *dev, · 36 unmodified lines
3737 return 0;
3838 }
3939
40−int coresight_device_fwnode_match(struct device *dev, const void *fwnode)
41−{
42− return dev_fwnode(dev) == fwnode;
43−}
44−
4540 static struct device *
4641 coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
4742 {
@@ -51,8 +46,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode) · 3 unmodified lines
5146 * If we have a non-configurable replicator, it will be found on the
5247 * platform bus.
5348 */
54− dev = bus_find_device(&platform_bus_type, NULL,
55− fwnode, coresight_device_fwnode_match);
49+ dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
5650 if (dev)
5751 return dev;
5852
@@ -60,8 +54,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode) · 1 unmodified line
6054 * We have a configurable component - circle through the AMBA bus
6155 * looking for the device that matches the endpoint node.
6256 */
63− return bus_find_device(&amba_bustype, NULL,
64− fwnode, coresight_device_fwnode_match);
57+ return bus_find_device_by_fwnode(&amba_bustype, fwnode);
6558 }
6659
6760 #ifdef CONFIG_OF
drivers/hwtracing/coresight/coresight-priv.h+0−2
@@ -202,6 +202,4 @@ static inline void *coresight_get_uci_data(const struct amba_id *id) · 201 unmodified lines
202202
203203 void coresight_release_platform_data(struct coresight_platform_data *pdata);
204204
205−int coresight_device_fwnode_match(struct device *dev, const void *fwnode);
206−
207205 #endif
drivers/hwtracing/coresight/coresight.c+1−3
@@ -1046,9 +1046,7 @@ static void coresight_fixup_device_conns(struct coresight_device *csdev) · 1045 unmodified lines
10461046 struct coresight_connection *conn = &csdev->pdata->conns[i];
10471047 struct device *dev = NULL;
10481048
1049− dev = bus_find_device(&coresight_bustype, NULL,
1050− (void *)conn->child_fwnode,
1051− coresight_device_fwnode_match);
1049+ dev = bus_find_device_by_fwnode(&coresight_bustype, conn->child_fwnode);
10521050 if (dev) {
10531051 conn->child_dev = to_coresight_device(dev);
10541052 /* and put reference from 'bus_find_device()' */
drivers/hwtracing/intel_th/core.c+1−9
@@ -789,12 +789,6 @@ static int intel_th_populate(struct intel_th *th) · 788 unmodified lines
789789 return 0;
790790 }
791791
792−static int match_devt(struct device *dev, const void *data)
793−{
794− dev_t devt = (dev_t)(unsigned long)(void *)data;
795− return dev->devt == devt;
796−}
797−
798792 static int intel_th_output_open(struct inode *inode, struct file *file)
799793 {
800794 const struct file_operations *fops;
@@ -802,9 +796,7 @@ static int intel_th_output_open(struct inode *inode, struct file *file) · 1 unmodified line
802796 struct device *dev;
803797 int err;
804798
805− dev = bus_find_device(&intel_th_bus, NULL,
806− (void *)(unsigned long)inode->i_rdev,
807− match_devt);
799+ dev = bus_find_device_by_devt(&intel_th_bus, inode->i_rdev);
808800 if (!dev || !dev->driver)
809801 return -ENODEV;
810802
drivers/hwtracing/stm/core.c+1−8
@@ -89,13 +89,6 @@ static struct class stm_class = { · 88 unmodified lines
8989 .dev_groups = stm_groups,
9090 };
9191
92−static int stm_dev_match(struct device *dev, const void *data)
93−{
94− const char *name = data;
95−
96− return sysfs_streq(name, dev_name(dev));
97−}
98−
9992 /**
10093 * stm_find_device() - find stm device by name
10194 * @buf: character buffer containing the name
@@ -116,7 +109,7 @@ struct stm_device *stm_find_device(const char *buf) · 14 unmodified lines
116109 if (!stm_core_up)
117110 return NULL;
118111
119− dev = class_find_device(&stm_class, NULL, buf, stm_dev_match);
112+ dev = class_find_device_by_name(&stm_class, buf);
120113 if (!dev)
121114 return NULL;
122115
drivers/i2c/busses/i2c-amd-mp2-pci.c+1−7
@@ -457,18 +457,12 @@ static struct pci_driver amd_mp2_pci_driver = { · 456 unmodified lines
457457 };
458458 module_pci_driver(amd_mp2_pci_driver);
459459
460−static int amd_mp2_device_match(struct device *dev, const void *data)
461−{
462− return 1;
463−}
464−
465460 struct amd_mp2_dev *amd_mp2_find_device(void)
466461 {
467462 struct device *dev;
468463 struct pci_dev *pci_dev;
469464
470− dev = driver_find_device(&amd_mp2_pci_driver.driver, NULL, NULL,
471− amd_mp2_device_match);
465+ dev = driver_find_next_device(&amd_mp2_pci_driver.driver, NULL);
472466 if (!dev)
473467 return NULL;
474468
drivers/i2c/i2c-core-acpi.c+2−9
@@ -354,17 +354,11 @@ static int i2c_acpi_find_match_adapter(struct device *dev, const void *data) · 353 unmodified lines
354354 return ACPI_HANDLE(dev) == (acpi_handle)data;
355355 }
356356
357−static int i2c_acpi_find_match_device(struct device *dev, const void *data)
358−{
359− return ACPI_COMPANION(dev) == data;
360−}
361357
362358 struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
363359 {
364− struct device *dev;
360+ struct device *dev = bus_find_device_by_acpi_dev(&i2c_bus_type, handle);
365361
366− dev = bus_find_device(&i2c_bus_type, NULL, handle,
367− i2c_acpi_find_match_adapter);
368362 return dev ? i2c_verify_adapter(dev) : NULL;
369363 }
370364 EXPORT_SYMBOL_GPL(i2c_acpi_find_adapter_by_handle);
@@ -373,8 +367,7 @@ static struct i2c_client *i2c_acpi_find_client_by_adev(struct acpi_device *adev) · 2 unmodified lines
373367 {
374368 struct device *dev;
375369
376− dev = bus_find_device(&i2c_bus_type, NULL, adev,
377− i2c_acpi_find_match_device);
370+ dev = bus_find_device_by_acpi_dev(&i2c_bus_type, adev);
378371 return dev ? i2c_verify_client(dev) : NULL;
379372 }
380373
drivers/i2c/i2c-core-of.c+1−6
@@ -113,11 +113,6 @@ void of_i2c_register_devices(struct i2c_adapter *adap) · 112 unmodified lines
113113 of_node_put(bus);
114114 }
115115
116−static int of_dev_node_match(struct device *dev, const void *data)
117−{
118− return dev->of_node == data;
119−}
120−
121116 static int of_dev_or_parent_node_match(struct device *dev, const void *data)
122117 {
123118 if (dev->of_node == data)
@@ -135,7 +130,7 @@ struct i2c_client *of_find_i2c_device_by_node(struct device_node *node) · 11 unmodified lines
135130 struct device *dev;
136131 struct i2c_client *client;
137132
138− dev = bus_find_device(&i2c_bus_type, NULL, node, of_dev_node_match);
133+ dev = bus_find_device_by_of_node(&i2c_bus_type, node);
139134 if (!dev)
140135 return NULL;
141136
drivers/infiniband/hw/hns/hns_roce_hw_v1.c+1−7
@@ -4499,19 +4499,13 @@ static const struct acpi_device_id hns_roce_acpi_match[] = { · 4498 unmodified lines
44994499 };
45004500 MODULE_DEVICE_TABLE(acpi, hns_roce_acpi_match);
45014501
4502−static int hns_roce_node_match(struct device *dev, const void *fwnode)
4503−{
4504− return dev->fwnode == fwnode;
4505−}
4506−
45074502 static struct
45084503 platform_device *hns_roce_find_pdev(struct fwnode_handle *fwnode)
45094504 {
45104505 struct device *dev;
45114506
45124507 /* get the 'device' corresponding to the matching 'fwnode' */
4513− dev = bus_find_device(&platform_bus_type, NULL,
4514− fwnode, hns_roce_node_match);
4508+ dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
45154509 /* get the platform device */
45164510 return dev ? to_platform_device(dev) : NULL;
45174511 }
drivers/iommu/arm-smmu-v3.c+2−7
@@ -2034,16 +2034,11 @@ arm_smmu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova) · 2033 unmodified lines
20342034
20352035 static struct platform_driver arm_smmu_driver;
20362036
2037−static int arm_smmu_match_node(struct device *dev, const void *data)
2038−{
2039− return dev->fwnode == data;
2040−}
2041−
20422037 static
20432038 struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
20442039 {
2045− struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
2046− fwnode, arm_smmu_match_node);
2040+ struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver,
2041+ fwnode);
20472042 put_device(dev);
20482043 return dev ? dev_get_drvdata(dev) : NULL;
20492044 }
drivers/iommu/arm-smmu.c+2−7
@@ -1426,16 +1426,11 @@ static bool arm_smmu_capable(enum iommu_cap cap) · 1425 unmodified lines
14261426 }
14271427 }
14281428
1429−static int arm_smmu_match_node(struct device *dev, const void *data)
1430−{
1431− return dev->fwnode == data;
1432−}
1433−
14341429 static
14351430 struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
14361431 {
1437− struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
1438− fwnode, arm_smmu_match_node);
1432+ struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver,
1433+ fwnode);
14391434 put_device(dev);
14401435 return dev ? dev_get_drvdata(dev) : NULL;
14411436 }
drivers/leds/led-class.c+1−8
@@ -214,13 +214,6 @@ static int led_resume(struct device *dev) · 213 unmodified lines
214214
215215 static SIMPLE_DEV_PM_OPS(leds_class_dev_pm_ops, led_suspend, led_resume);
216216
217−static int match_name(struct device *dev, const void *data)
218−{
219− if (!dev_name(dev))
220− return 0;
221− return !strcmp(dev_name(dev), (char *)data);
222−}
223−
224217 static int led_classdev_next_name(const char *init_name, char *name,
225218 size_t len)
226219 {
@@ -231,7 +224,7 @@ static int led_classdev_next_name(const char *init_name, char *name, · 4 unmodified lines
231224 strlcpy(name, init_name, len);
232225
233226 while ((ret < len) &&
234− (dev = class_find_device(leds_class, NULL, name, match_name))) {
227+ (dev = class_find_device_by_name(leds_class, name))) {
235228 put_device(dev);
236229 ret = snprintf(name, len, "%s_%u", init_name, ++i);
237230 }
drivers/mfd/altera-sysmgr.c+2−12
@@ -87,16 +87,6 @@ static struct regmap_config altr_sysmgr_regmap_cfg = { · 86 unmodified lines
8787 .use_single_write = true,
8888 };
8989
90−/**
91− * sysmgr_match_phandle
92− * Matching function used by driver_find_device().
93− * Return: True if match is found, otherwise false.
94− */
95−static int sysmgr_match_phandle(struct device *dev, const void *data)
96−{
97− return dev->of_node == (const struct device_node *)data;
98−}
99−
10090 /**
10191 * altr_sysmgr_regmap_lookup_by_phandle
10292 * Find the sysmgr previous configured in probe() and return regmap property.
@@ -117,8 +107,8 @@ struct regmap *altr_sysmgr_regmap_lookup_by_phandle(struct device_node *np, · 14 unmodified lines
117107 if (!sysmgr_np)
118108 return ERR_PTR(-ENODEV);
119109
120− dev = driver_find_device(&altr_sysmgr_driver.driver, NULL,
121− (void *)sysmgr_np, sysmgr_match_phandle);
110+ dev = driver_find_device_by_of_node(&altr_sysmgr_driver.driver,
111+ (void *)sysmgr_np);
122112 of_node_put(sysmgr_np);
123113 if (!dev)
124114 return ERR_PTR(-EPROBE_DEFER);
drivers/misc/mei/main.c+1−8
@@ -858,13 +858,6 @@ static ssize_t dev_state_show(struct device *device, · 857 unmodified lines
858858 }
859859 static DEVICE_ATTR_RO(dev_state);
860860
861−static int match_devt(struct device *dev, const void *data)
862−{
863− const dev_t *devt = data;
864−
865− return dev->devt == *devt;
866−}
867−
868861 /**
869862 * dev_set_devstate: set to new device state and notify sysfs file.
870863 *
@@ -880,7 +873,7 @@ void mei_set_devstate(struct mei_device *dev, enum mei_dev_state state) · 9 unmodified lines
880873
881874 dev->dev_state = state;
882875
883− clsdev = class_find_device(mei_class, NULL, &dev->cdev.dev, match_devt);
876+ clsdev = class_find_device_by_devt(mei_class, dev->cdev.dev);
884877 if (clsdev) {
885878 sysfs_notify(&clsdev->kobj, NULL, "dev_state");
886879 put_device(clsdev);
drivers/mux/core.c+1−6
@@ -405,17 +405,12 @@ int mux_control_deselect(struct mux_control *mux) · 404 unmodified lines
405405 }
406406 EXPORT_SYMBOL_GPL(mux_control_deselect);
407407
408−static int of_dev_node_match(struct device *dev, const void *data)
409−{
410− return dev->of_node == data;
411−}
412−
413408 /* Note this function returns a reference to the mux_chip dev. */
414409 static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np)
415410 {
416411 struct device *dev;
417412
418− dev = class_find_device(&mux_class, NULL, np, of_dev_node_match);
413+ dev = class_find_device_by_of_node(&mux_class, np);
419414
420415 return dev ? to_mux_chip(dev) : NULL;
421416 }
drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c+1−7
@@ -754,17 +754,11 @@ struct dsaf_misc_op *hns_misc_op_get(struct dsaf_device *dsaf_dev) · 753 unmodified lines
754754 return (void *)misc_op;
755755 }
756756
757−static int hns_dsaf_dev_match(struct device *dev, const void *fwnode)
758−{
759− return dev->fwnode == fwnode;
760−}
761−
762757 struct
763758 platform_device *hns_dsaf_find_platform_device(struct fwnode_handle *fwnode)
764759 {
765760 struct device *dev;
766761
767− dev = bus_find_device(&platform_bus_type, NULL,
768− fwnode, hns_dsaf_dev_match);
762+ dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
769763 return dev ? to_platform_device(dev) : NULL;
770764 }
drivers/net/phy/mdio_bus.c+1−8
@@ -262,11 +262,6 @@ static struct class mdio_bus_class = { · 261 unmodified lines
262262 };
263263
264264 #if IS_ENABLED(CONFIG_OF_MDIO)
265−/* Helper function for of_mdio_find_bus */
266−static int of_mdio_bus_match(struct device *dev, const void *mdio_bus_np)
267−{
268− return dev->of_node == mdio_bus_np;
269−}
270265 /**
271266 * of_mdio_find_bus - Given an mii_bus node, find the mii_bus.
272267 * @mdio_bus_np: Pointer to the mii_bus.
@@ -287,9 +282,7 @@ struct mii_bus *of_mdio_find_bus(struct device_node *mdio_bus_np) · 14 unmodified lines
287282 if (!mdio_bus_np)
288283 return NULL;
289284
290− d = class_find_device(&mdio_bus_class, NULL, mdio_bus_np,
291− of_mdio_bus_match);
292−
285+ d = class_find_device_by_of_node(&mdio_bus_class, mdio_bus_np);
293286 return d ? to_mii_bus(d) : NULL;
294287 }
295288 EXPORT_SYMBOL(of_mdio_find_bus);
drivers/nvmem/core.c+1−6
@@ -76,11 +76,6 @@ static struct bus_type nvmem_bus_type = { · 75 unmodified lines
7676 .name = "nvmem",
7777 };
7878
79−static int of_nvmem_match(struct device *dev, const void *nvmem_np)
80−{
81− return dev->of_node == nvmem_np;
82−}
83−
8479 static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np)
8580 {
8681 struct device *d;
@@ -88,7 +83,7 @@ static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np) · 1 unmodified line
8883 if (!nvmem_np)
8984 return NULL;
9085
91− d = bus_find_device(&nvmem_bus_type, NULL, nvmem_np, of_nvmem_match);
86+ d = bus_find_device_by_of_node(&nvmem_bus_type, nvmem_np);
9287
9388 if (!d)
9489 return NULL;
drivers/of/of_mdio.c+1−7
@@ -280,12 +280,6 @@ unregister: · 279 unmodified lines
280280 }
281281 EXPORT_SYMBOL(of_mdiobus_register);
282282
283−/* Helper function for of_phy_find_device */
284−static int of_phy_match(struct device *dev, const void *phy_np)
285−{
286− return dev->of_node == phy_np;
287−}
288−
289283 /**
290284 * of_phy_find_device - Give a PHY node, find the phy_device
291285 * @phy_np: Pointer to the phy's device tree node
@@ -301,7 +295,7 @@ struct phy_device *of_phy_find_device(struct device_node *phy_np) · 9 unmodified lines
301295 if (!phy_np)
302296 return NULL;
303297
304− d = bus_find_device(&mdio_bus_type, NULL, phy_np, of_phy_match);
298+ d = bus_find_device_by_of_node(&mdio_bus_type, phy_np);
305299 if (d) {
306300 mdiodev = to_mdio_device(d);
307301 if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
drivers/of/platform.c+1−6
@@ -37,11 +37,6 @@ static const struct of_device_id of_skipped_node_table[] = { · 36 unmodified lines
3737 {} /* Empty terminated list */
3838 };
3939
40−static int of_dev_node_match(struct device *dev, const void *data)
41−{
42− return dev->of_node == data;
43−}
44−
4540 /**
4641 * of_find_device_by_node - Find the platform_device associated with a node
4742 * @np: Pointer to device tree node
@@ -55,7 +50,7 @@ struct platform_device *of_find_device_by_node(struct device_node *np) · 7 unmodified lines
5550 {
5651 struct device *dev;
5752
58− dev = bus_find_device(&platform_bus_type, NULL, np, of_dev_node_match);
53+ dev = bus_find_device_by_of_node(&platform_bus_type, np);
5954 return dev ? to_platform_device(dev) : NULL;
6055 }
6156 EXPORT_SYMBOL(of_find_device_by_node);
drivers/pci/probe.c+1−6
@@ -64,11 +64,6 @@ static struct resource *get_pci_domain_busn_res(int domain_nr) · 63 unmodified lines
6464 return &r->res;
6565 }
6666
67−static int find_anything(struct device *dev, const void *data)
68−{
69− return 1;
70−}
71−
7267 /*
7368 * Some device drivers need know if PCI is initiated.
7469 * Basically, we think PCI is not initiated when there
@@ -79,7 +74,7 @@ int no_pci_devices(void) · 4 unmodified lines
7974 struct device *dev;
8075 int no_devices;
8176
82− dev = bus_find_device(&pci_bus_type, NULL, NULL, find_anything);
77+ dev = bus_find_next_device(&pci_bus_type, NULL);
8378 no_devices = (dev == NULL);
8479 put_device(dev);
8580 return no_devices;
drivers/regulator/of_regulator.c+1−6
@@ -460,16 +460,11 @@ error: · 459 unmodified lines
460460 return NULL;
461461 }
462462
463−static int of_node_match(struct device *dev, const void *data)
464−{
465− return dev->of_node == data;
466−}
467−
468463 struct regulator_dev *of_find_regulator_by_node(struct device_node *np)
469464 {
470465 struct device *dev;
471466
472− dev = class_find_device(&regulator_class, NULL, np, of_node_match);
467+ dev = class_find_device_by_of_node(&regulator_class, np);
473468
474469 return dev ? dev_to_rdev(dev) : NULL;
475470 }
drivers/rtc/interface.c+1−10
@@ -663,21 +663,12 @@ void rtc_update_irq(struct rtc_device *rtc, · 662 unmodified lines
663663 }
664664 EXPORT_SYMBOL_GPL(rtc_update_irq);
665665
666−static int __rtc_match(struct device *dev, const void *data)
667−{
668− const char *name = data;
669−
670− if (strcmp(dev_name(dev), name) == 0)
671− return 1;
672− return 0;
673−}
674−
675666 struct rtc_device *rtc_class_open(const char *name)
676667 {
677668 struct device *dev;
678669 struct rtc_device *rtc = NULL;
679670
680− dev = class_find_device(rtc_class, NULL, name, __rtc_match);
671+ dev = class_find_device_by_name(rtc_class, name);
681672 if (dev)
682673 rtc = to_rtc_device(dev);
683674
drivers/s390/cio/ccwgroup.c+2−16
@@ -581,11 +581,6 @@ int ccwgroup_driver_register(struct ccwgroup_driver *cdriver) · 580 unmodified lines
581581 }
582582 EXPORT_SYMBOL(ccwgroup_driver_register);
583583
584−static int __ccwgroup_match_all(struct device *dev, const void *data)
585−{
586− return 1;
587−}
588−
589584 /**
590585 * ccwgroup_driver_unregister() - deregister a ccw group driver
591586 * @cdriver: driver to be deregistered
@@ -597,8 +592,7 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver) · 5 unmodified lines
597592 struct device *dev;
598593
599594 /* We don't want ccwgroup devices to live longer than their driver. */
600− while ((dev = driver_find_device(&cdriver->driver, NULL, NULL,
601− __ccwgroup_match_all))) {
595+ while ((dev = driver_find_next_device(&cdriver->driver, NULL))) {
602596 struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
603597
604598 ccwgroup_ungroup(gdev);
@@ -608,13 +602,6 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver) · 3 unmodified lines
608602 }
609603 EXPORT_SYMBOL(ccwgroup_driver_unregister);
610604
611−static int __ccwgroupdev_check_busid(struct device *dev, const void *id)
612−{
613− const char *bus_id = id;
614−
615− return (strcmp(bus_id, dev_name(dev)) == 0);
616−}
617−
618605 /**
619606 * get_ccwgroupdev_by_busid() - obtain device from a bus id
620607 * @gdrv: driver the device is owned by
@@ -631,8 +618,7 @@ struct ccwgroup_device *get_ccwgroupdev_by_busid(struct ccwgroup_driver *gdrv, · 10 unmodified lines
631618 {
632619 struct device *dev;
633620
634− dev = driver_find_device(&gdrv->driver, NULL, bus_id,
635− __ccwgroupdev_check_busid);
621+ dev = driver_find_device_by_name(&gdrv->driver, bus_id);
636622
637623 return dev ? to_ccwgroupdev(dev) : NULL;
638624 }
drivers/s390/cio/device.c+1−14
@@ -1695,18 +1695,6 @@ int ccw_device_force_console(struct ccw_device *cdev) · 1694 unmodified lines
16951695 EXPORT_SYMBOL_GPL(ccw_device_force_console);
16961696 #endif
16971697
1698−/*
1699− * get ccw_device matching the busid, but only if owned by cdrv
1700− */
1701−static int
1702−__ccwdev_check_busid(struct device *dev, const void *id)
1703−{
1704− const char *bus_id = id;
1705−
1706− return (strcmp(bus_id, dev_name(dev)) == 0);
1707−}
1708−
1709−
17101698 /**
17111699 * get_ccwdev_by_busid() - obtain device from a bus id
17121700 * @cdrv: driver the device is owned by
@@ -1723,8 +1711,7 @@ struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv, · 10 unmodified lines
17231711 {
17241712 struct device *dev;
17251713
1726− dev = driver_find_device(&cdrv->driver, NULL, (void *)bus_id,
1727− __ccwdev_check_busid);
1714+ dev = driver_find_device_by_name(&cdrv->driver, bus_id);
17281715
17291716 return dev ? to_ccwdev(dev) : NULL;
17301717 }
drivers/s390/crypto/zcrypt_api.c+2−20
@@ -133,18 +133,6 @@ struct zcdn_device { · 132 unmodified lines
133133 static int zcdn_create(const char *name);
134134 static int zcdn_destroy(const char *name);
135135
136−/* helper function, matches the name for find_zcdndev_by_name() */
137−static int __match_zcdn_name(struct device *dev, const void *data)
138−{
139− return strcmp(dev_name(dev), (const char *)data) == 0;
140−}
141−
142−/* helper function, matches the devt value for find_zcdndev_by_devt() */
143−static int __match_zcdn_devt(struct device *dev, const void *data)
144−{
145− return dev->devt == *((dev_t *) data);
146−}
147−
148136 /*
149137 * Find zcdn device by name.
150138 * Returns reference to the zcdn device which needs to be released
@@ -152,10 +140,7 @@ static int __match_zcdn_devt(struct device *dev, const void *data) · 1 unmodified line
152140 */
153141 static inline struct zcdn_device *find_zcdndev_by_name(const char *name)
154142 {
155− struct device *dev =
156− class_find_device(zcrypt_class, NULL,
157− (void *) name,
158− __match_zcdn_name);
143+ struct device *dev = class_find_device_by_name(zcrypt_class, name);
159144
160145 return dev ? to_zcdn_dev(dev) : NULL;
161146 }
@@ -167,10 +152,7 @@ static inline struct zcdn_device *find_zcdndev_by_name(const char *name) · 5 unmodified lines
167152 */
168153 static inline struct zcdn_device *find_zcdndev_by_devt(dev_t devt)
169154 {
170− struct device *dev =
171− class_find_device(zcrypt_class, NULL,
172− (void *) &devt,
173− __match_zcdn_devt);
155+ struct device *dev = class_find_device_by_devt(zcrypt_class, devt);
174156
175157 return dev ? to_zcdn_dev(dev) : NULL;
176158 }
drivers/scsi/scsi_proc.c+2−7
@@ -372,15 +372,10 @@ static ssize_t proc_scsi_write(struct file *file, const char __user *buf, · 371 unmodified lines
372372 return err;
373373 }
374374
375−static int always_match(struct device *dev, const void *data)
376−{
377− return 1;
378−}
379−
380375 static inline struct device *next_scsi_device(struct device *start)
381376 {
382− struct device *next = bus_find_device(&scsi_bus_type, start, NULL,
383− always_match);
377+ struct device *next = bus_find_next_device(&scsi_bus_type, start);
378+
384379 put_device(start);
385380 return next;
386381 }
drivers/spi/spi.c+5−23
@@ -3652,37 +3652,25 @@ EXPORT_SYMBOL_GPL(spi_write_then_read); · 3651 unmodified lines
36523652 /*-------------------------------------------------------------------------*/
36533653
36543654 #if IS_ENABLED(CONFIG_OF)
3655−static int __spi_of_device_match(struct device *dev, const void *data)
3656−{
3657− return dev->of_node == data;
3658−}
3659−
36603655 /* must call put_device() when done with returned spi_device device */
36613656 struct spi_device *of_find_spi_device_by_node(struct device_node *node)
36623657 {
3663− struct device *dev = bus_find_device(&spi_bus_type, NULL, node,
3664− __spi_of_device_match);
3658+ struct device *dev = bus_find_device_by_of_node(&spi_bus_type, node);
3659+
36653660 return dev ? to_spi_device(dev) : NULL;
36663661 }
36673662 EXPORT_SYMBOL_GPL(of_find_spi_device_by_node);
36683663 #endif /* IS_ENABLED(CONFIG_OF) */
36693664
36703665 #if IS_ENABLED(CONFIG_OF_DYNAMIC)
3671−static int __spi_of_controller_match(struct device *dev, const void *data)
3672−{
3673− return dev->of_node == data;
3674−}
3675−
36763666 /* the spi controllers are not using spi_bus, so we find it with another way */
36773667 static struct spi_controller *of_find_spi_controller_by_node(struct device_node *node)
36783668 {
36793669 struct device *dev;
36803670
3681− dev = class_find_device(&spi_master_class, NULL, node,
3682− __spi_of_controller_match);
3671+ dev = class_find_device_by_of_node(&spi_master_class, node);
36833672 if (!dev && IS_ENABLED(CONFIG_SPI_SLAVE))
3684− dev = class_find_device(&spi_slave_class, NULL, node,
3685− __spi_of_controller_match);
3673+ dev = class_find_device_by_of_node(&spi_slave_class, node);
36863674 if (!dev)
36873675 return NULL;
36883676
@@ -3753,11 +3741,6 @@ static int spi_acpi_controller_match(struct device *dev, const void *data) · 64 unmodified lines
37533741 return ACPI_COMPANION(dev->parent) == data;
37543742 }
37553743
3756−static int spi_acpi_device_match(struct device *dev, const void *data)
3757−{
3758− return ACPI_COMPANION(dev) == data;
3759−}
3760−
37613744 static struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev)
37623745 {
37633746 struct device *dev;
@@ -3777,8 +3760,7 @@ static struct spi_device *acpi_spi_find_device_by_adev(struct acpi_device *adev) · 13 unmodified lines
37773760 {
37783761 struct device *dev;
37793762
3780− dev = bus_find_device(&spi_bus_type, NULL, adev, spi_acpi_device_match);
3781−
3763+ dev = bus_find_device_by_acpi_dev(&spi_bus_type, adev);
37823764 return dev ? to_spi_device(dev) : NULL;
37833765 }
37843766
drivers/tty/tty_io.c+1−7
@@ -2952,17 +2952,11 @@ void do_SAK(struct tty_struct *tty) · 2951 unmodified lines
29522952
29532953 EXPORT_SYMBOL(do_SAK);
29542954
2955−static int dev_match_devt(struct device *dev, const void *data)
2956−{
2957− const dev_t *devt = data;
2958− return dev->devt == *devt;
2959−}
2960−
29612955 /* Must put_device() after it's unused! */
29622956 static struct device *tty_get_device(struct tty_struct *tty)
29632957 {
29642958 dev_t devt = tty_devnum(tty);
2965− return class_find_device(tty_class, NULL, &devt, dev_match_devt);
2959+ return class_find_device_by_devt(tty_class, devt);
29662960 }
29672961
29682962
drivers/usb/core/devio.c+1−7
@@ -942,17 +942,11 @@ error: · 941 unmodified lines
942942 return ret;
943943 }
944944
945−static int match_devt(struct device *dev, const void *data)
946−{
947− return dev->devt == (dev_t)(unsigned long)(void *)data;
948−}
949−
950945 static struct usb_device *usbdev_lookup_by_devt(dev_t devt)
951946 {
952947 struct device *dev;
953948
954− dev = bus_find_device(&usb_bus_type, NULL,
955− (void *) (unsigned long) devt, match_devt);
949+ dev = bus_find_device_by_devt(&usb_bus_type, devt);
956950 if (!dev)
957951 return NULL;
958952 return to_usb_device(dev);
drivers/usb/roles/class.c+2−14
@@ -85,16 +85,6 @@ enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw) · 84 unmodified lines
8585 }
8686 EXPORT_SYMBOL_GPL(usb_role_switch_get_role);
8787
88−static int switch_fwnode_match(struct device *dev, const void *fwnode)
89−{
90− return dev_fwnode(dev) == fwnode;
91−}
92−
93−static int switch_name_match(struct device *dev, const void *name)
94−{
95− return !strcmp((const char *)name, dev_name(dev));
96−}
97−
9888 static void *usb_role_switch_match(struct device_connection *con, int ep,
9989 void *data)
10090 {
@@ -104,11 +94,9 @@ static void *usb_role_switch_match(struct device_connection *con, int ep, · 3 unmodified lines
10494 if (con->id && !fwnode_property_present(con->fwnode, con->id))
10595 return NULL;
10696
107− dev = class_find_device(role_class, NULL, con->fwnode,
108− switch_fwnode_match);
97+ dev = class_find_device_by_fwnode(role_class, con->fwnode);
10998 } else {
110− dev = class_find_device(role_class, NULL, con->endpoint[ep],
111− switch_name_match);
99+ dev = class_find_device_by_name(role_class, con->endpoint[ep]);
112100 }
113101
114102 return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
drivers/usb/typec/class.c+2−14
@@ -205,16 +205,6 @@ static void typec_altmode_put_partner(struct altmode *altmode) · 204 unmodified lines
205205 put_device(&adev->dev);
206206 }
207207
208−static int typec_port_fwnode_match(struct device *dev, const void *fwnode)
209−{
210− return dev_fwnode(dev) == fwnode;
211−}
212−
213−static int typec_port_name_match(struct device *dev, const void *name)
214−{
215− return !strcmp((const char *)name, dev_name(dev));
216−}
217−
218208 static void *typec_port_match(struct device_connection *con, int ep, void *data)
219209 {
220210 struct device *dev;
@@ -224,11 +214,9 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data) · 3 unmodified lines
224214 * we need to return ERR_PTR(-PROBE_DEFER) when there is no device.
225215 */
226216 if (con->fwnode)
227− return class_find_device(typec_class, NULL, con->fwnode,
228− typec_port_fwnode_match);
217+ return class_find_device_by_fwnode(typec_class, con->fwnode);
229218
230− dev = class_find_device(typec_class, NULL, con->endpoint[ep],
231− typec_port_name_match);
219+ dev = class_find_device_by_name(typec_class, con->endpoint[ep]);
232220
233221 return dev ? dev : ERR_PTR(-EPROBE_DEFER);
234222 }
include/linux/device.h+234−3
@@ -164,16 +164,100 @@ void subsys_dev_iter_init(struct subsys_dev_iter *iter, · 163 unmodified lines
164164 struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);
165165 void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
166166
167+int device_match_name(struct device *dev, const void *name);
167168 int device_match_of_node(struct device *dev, const void *np);
169+int device_match_fwnode(struct device *dev, const void *fwnode);
170+int device_match_devt(struct device *dev, const void *pdevt);
171+int device_match_acpi_dev(struct device *dev, const void *adev);
172+int device_match_any(struct device *dev, const void *unused);
168173
169174 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
170175 int (*fn)(struct device *dev, void *data));
171176 struct device *bus_find_device(struct bus_type *bus, struct device *start,
172177 const void *data,
173178 int (*match)(struct device *dev, const void *data));
174−struct device *bus_find_device_by_name(struct bus_type *bus,
175− struct device *start,
176− const char *name);
179+/**
180+ * bus_find_device_by_name - device iterator for locating a particular device
181+ * of a specific name.
182+ * @bus: bus type
183+ * @start: Device to begin with
184+ * @name: name of the device to match
185+ */
186+static inline struct device *bus_find_device_by_name(struct bus_type *bus,
187+ struct device *start,
188+ const char *name)
189+{
190+ return bus_find_device(bus, start, name, device_match_name);
191+}
192+
193+/**
194+ * bus_find_device_by_of_node : device iterator for locating a particular device
195+ * matching the of_node.
196+ * @bus: bus type
197+ * @np: of_node of the device to match.
198+ */
199+static inline struct device *
200+bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
201+{
202+ return bus_find_device(bus, NULL, np, device_match_of_node);
203+}
204+
205+/**
206+ * bus_find_device_by_fwnode : device iterator for locating a particular device
207+ * matching the fwnode.
208+ * @bus: bus type
209+ * @fwnode: fwnode of the device to match.
210+ */
211+static inline struct device *
212+bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode)
213+{
214+ return bus_find_device(bus, NULL, fwnode, device_match_fwnode);
215+}
216+
217+/**
218+ * bus_find_device_by_devt : device iterator for locating a particular device
219+ * matching the device type.
220+ * @bus: bus type
221+ * @devt: device type of the device to match.
222+ */
223+static inline struct device *bus_find_device_by_devt(struct bus_type *bus,
224+ dev_t devt)
225+{
226+ return bus_find_device(bus, NULL, &devt, device_match_devt);
227+}
228+
229+/**
230+ * bus_find_next_device - Find the next device after a given device in a
231+ * given bus.
232+ */
233+static inline struct device *
234+bus_find_next_device(struct bus_type *bus,struct device *cur)
235+{
236+ return bus_find_device(bus, cur, NULL, device_match_any);
237+}
238+
239+#ifdef CONFIG_ACPI
240+struct acpi_device;
241+
242+/**
243+ * bus_find_device_by_acpi_dev : device iterator for locating a particular device
244+ * matching the ACPI COMPANION device.
245+ * @bus: bus type
246+ * @adev: ACPI COMPANION device to match.
247+ */
248+static inline struct device *
249+bus_find_device_by_acpi_dev(struct bus_type *bus, const struct acpi_device *adev)
250+{
251+ return bus_find_device(bus, NULL, adev, device_match_acpi_dev);
252+}
253+#else
254+static inline struct device *
255+bus_find_device_by_acpi_dev(struct bus_type *bus, const void *adev)
256+{
257+ return NULL;
258+}
259+#endif
260+
177261 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
178262 struct device *hint);
179263 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
@@ -342,6 +426,83 @@ struct device *driver_find_device(struct device_driver *drv, · 162 unmodified lines
342426 struct device *start, const void *data,
343427 int (*match)(struct device *dev, const void *data));
344428
429+/**
430+ * driver_find_device_by_name - device iterator for locating a particular device
431+ * of a specific name.
432+ * @driver: the driver we're iterating
433+ * @name: name of the device to match
434+ */
435+static inline struct device *driver_find_device_by_name(struct device_driver *drv,
436+ const char *name)
437+{
438+ return driver_find_device(drv, NULL, name, device_match_name);
439+}
440+
441+/**
442+ * driver_find_device_by_of_node- device iterator for locating a particular device
443+ * by of_node pointer.
444+ * @driver: the driver we're iterating
445+ * @np: of_node pointer to match.
446+ */
447+static inline struct device *
448+driver_find_device_by_of_node(struct device_driver *drv,
449+ const struct device_node *np)
450+{
451+ return driver_find_device(drv, NULL, np, device_match_of_node);
452+}
453+
454+/**
455+ * driver_find_device_by_fwnode- device iterator for locating a particular device
456+ * by fwnode pointer.
457+ * @driver: the driver we're iterating
458+ * @fwnode: fwnode pointer to match.
459+ */
460+static inline struct device *
461+driver_find_device_by_fwnode(struct device_driver *drv,
462+ const struct fwnode_handle *fwnode)
463+{
464+ return driver_find_device(drv, NULL, fwnode, device_match_fwnode);
465+}
466+
467+/**
468+ * driver_find_device_by_devt- device iterator for locating a particular device
469+ * by devt.
470+ * @driver: the driver we're iterating
471+ * @devt: devt pointer to match.
472+ */
473+static inline struct device *driver_find_device_by_devt(struct device_driver *drv,
474+ dev_t devt)
475+{
476+ return driver_find_device(drv, NULL, &devt, device_match_devt);
477+}
478+
479+static inline struct device *driver_find_next_device(struct device_driver *drv,
480+ struct device *start)
481+{
482+ return driver_find_device(drv, start, NULL, device_match_any);
483+}
484+
485+#ifdef CONFIG_ACPI
486+/**
487+ * driver_find_device_by_acpi_dev : device iterator for locating a particular
488+ * device matching the ACPI_COMPANION device.
489+ * @driver: the driver we're iterating
490+ * @adev: ACPI_COMPANION device to match.
491+ */
492+static inline struct device *
493+driver_find_device_by_acpi_dev(struct device_driver *drv,
494+ const struct acpi_device *adev)
495+{
496+ return driver_find_device(drv, NULL, adev, device_match_acpi_dev);
497+}
498+#else
499+static inline struct device *
500+driver_find_device_by_acpi_dev(struct device_driver *drv, const void *adev)
501+{
502+ return NULL;
503+}
504+#endif
505+
345506 void driver_deferred_probe_add(struct device *dev);
346507 int driver_deferred_probe_check_state(struct device *dev);
347508 int driver_deferred_probe_check_state_continue(struct device *dev);
@@ -471,6 +632,76 @@ extern struct device *class_find_device(struct class *class, · 123 unmodified lines
471632 struct device *start, const void *data,
472633 int (*match)(struct device *, const void *));
473634
635+/**
636+ * class_find_device_by_name - device iterator for locating a particular device
637+ * of a specific name.
638+ * @class: class type
639+ * @name: name of the device to match
640+ */
641+static inline struct device *class_find_device_by_name(struct class *class,
642+ const char *name)
643+{
644+ return class_find_device(class, NULL, name, device_match_name);
645+}
646+
647+/**
648+ * class_find_device_by_of_node : device iterator for locating a particular device
649+ * matching the of_node.
650+ * @class: class type
651+ * @np: of_node of the device to match.
652+ */
653+static inline struct device *
654+class_find_device_by_of_node(struct class *class, const struct device_node *np)
655+{
656+ return class_find_device(class, NULL, np, device_match_of_node);
657+}
658+
659+/**
660+ * class_find_device_by_fwnode : device iterator for locating a particular device
661+ * matching the fwnode.
662+ * @class: class type
663+ * @fwnode: fwnode of the device to match.
664+ */
665+static inline struct device *
666+class_find_device_by_fwnode(struct class *class,
667+ const struct fwnode_handle *fwnode)
668+{
669+ return class_find_device(class, NULL, fwnode, device_match_fwnode);
670+}
671+
672+/**
673+ * class_find_device_by_devt : device iterator for locating a particular device
674+ * matching the device type.
675+ * @class: class type
676+ * @devt: device type of the device to match.
677+ */
678+static inline struct device *class_find_device_by_devt(struct class *class,
679+ dev_t devt)
680+{
681+ return class_find_device(class, NULL, &devt, device_match_devt);
682+}
683+
684+#ifdef CONFIG_ACPI
685+struct acpi_device;
686+/**
687+ * class_find_device_by_acpi_dev : device iterator for locating a particular
688+ * device matching the ACPI_COMPANION device.
689+ * @class: class type
690+ * @adev: ACPI_COMPANION device to match.
691+ */
692+static inline struct device *
693+class_find_device_by_acpi_dev(struct class *class, const struct acpi_device *adev)
694+{
695+ return class_find_device(class, NULL, adev, device_match_acpi_dev);
696+}
697+#else
698+static inline struct device *
699+class_find_device_by_acpi_dev(struct class *class, const void *adev)
700+{
701+ return NULL;
702+}
703+#endif
704+
474705 struct class_attribute {
475706 struct attribute attr;
476707 ssize_t (*show)(struct class *class, struct class_attribute *attr,
include/linux/platform_device.h+3−0
@@ -51,6 +51,9 @@ extern struct device platform_bus; · 50 unmodified lines
5151 extern void arch_setup_pdev_archdata(struct platform_device *);
5252 extern struct resource *platform_get_resource(struct platform_device *,
5353 unsigned int, unsigned int);
54+extern struct device *
55+platform_find_device_by_driver(struct device *start,
56+ const struct device_driver *drv);
5457 extern void __iomem *
5558 devm_platform_ioremap_resource(struct platform_device *pdev,
5659 unsigned int index);
net/ieee802154/core.c+1−6
@@ -23,11 +23,6 @@ · 22 unmodified lines
2323 LIST_HEAD(cfg802154_rdev_list);
2424 int cfg802154_rdev_list_generation;
2525
26−static int wpan_phy_match(struct device *dev, const void *data)
27−{
28− return !strcmp(dev_name(dev), (const char *)data);
29−}
30−
3126 struct wpan_phy *wpan_phy_find(const char *str)
3227 {
3328 struct device *dev;
@@ -35,7 +30,7 @@ struct wpan_phy *wpan_phy_find(const char *str) · 1 unmodified line
3530 if (WARN_ON(!str))
3631 return NULL;
3732
38− dev = class_find_device(&wpan_phy_class, NULL, str, wpan_phy_match);
33+ dev = class_find_device_by_name(&wpan_phy_class, str);
3934 if (!dev)
4035 return NULL;
4136
sound/soc/rockchip/rk3399_gru_sound.c+2−7
@@ -422,11 +422,6 @@ static const struct dailink_match_data dailink_match[] = { · 421 unmodified lines
422422 },
423423 };
424424
425−static int of_dev_node_match(struct device *dev, const void *data)
426−{
427− return dev->of_node == data;
428−}
429−
430425 static int rockchip_sound_codec_node_match(struct device_node *np_codec)
431426 {
432427 struct device *dev;
@@ -438,8 +433,8 @@ static int rockchip_sound_codec_node_match(struct device_node *np_codec) · 5 unmodified lines
438433 continue;
439434
440435 if (dailink_match[i].bus_type) {
441− dev = bus_find_device(dailink_match[i].bus_type, NULL,
442− np_codec, of_dev_node_match);
436+ dev = bus_find_device_by_of_node(dailink_match[i].bus_type,
437+ np_codec);
443438 if (!dev)
444439 continue;
445440 put_device(dev);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t