Skip to content

Commit f87da58

Browse files
committed
Merge branch 'generic_lookup_helpers' into driver-core-next
This was on a separate branch so that others can pull it in. Signed-off-by: Greg Kroah-Hartman <[email protected]>
2 parents fb583c8 + 36f3313 commit f87da58

File tree

48 files changed

+341
-383
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+341
-383
lines changed

drivers/amba/tegra-ahb.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,13 @@ static inline void gizmo_writel(struct tegra_ahb *ahb, u32 value, u32 offset)
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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -342,30 +342,6 @@ struct device *bus_find_device(struct bus_type *bus,
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

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2891,13 +2891,6 @@ struct device *device_create_with_groups(struct class *class,
28912891
}
28922892
EXPORT_SYMBOL_GPL(device_create_with_groups);
28932893

2894-
static int __match_devt(struct device *dev, const void *data)
2895-
{
2896-
const dev_t *devt = data;
2897-
2898-
return dev->devt == *devt;
2899-
}
2900-
29012894
/**
29022895
* device_destroy - removes a device that was created with device_create()
29032896
* @class: pointer to the struct class that this device was registered with
@@ -2910,7 +2903,7 @@ void device_destroy(struct class *class, dev_t devt)
29102903
{
29112904
struct device *dev;
29122905

2913-
dev = class_find_device(class, NULL, &devt, __match_devt);
2906+
dev = class_find_device_by_devt(class, devt);
29142907
if (dev) {
29152908
put_device(dev);
29162909
device_unregister(dev);
@@ -3381,8 +3374,38 @@ void device_set_of_node_from_dev(struct device *dev, const struct device *dev2)
33813374
}
33823375
EXPORT_SYMBOL_GPL(device_set_of_node_from_dev);
33833376

3377+
int device_match_name(struct device *dev, const void *name)
3378+
{
3379+
return sysfs_streq(dev_name(dev), name);
3380+
}
3381+
EXPORT_SYMBOL_GPL(device_match_name);
3382+
33843383
int device_match_of_node(struct device *dev, const void *np)
33853384
{
33863385
return dev->of_node == np;
33873386
}
33883387
EXPORT_SYMBOL_GPL(device_match_of_node);
3388+
3389+
int device_match_fwnode(struct device *dev, const void *fwnode)
3390+
{
3391+
return dev_fwnode(dev) == fwnode;
3392+
}
3393+
EXPORT_SYMBOL_GPL(device_match_fwnode);
3394+
3395+
int device_match_devt(struct device *dev, const void *pdevt)
3396+
{
3397+
return dev->devt == *(dev_t *)pdevt;
3398+
}
3399+
EXPORT_SYMBOL_GPL(device_match_devt);
3400+
3401+
int device_match_acpi_dev(struct device *dev, const void *adev)
3402+
{
3403+
return ACPI_COMPANION(dev) == adev;
3404+
}
3405+
EXPORT_SYMBOL(device_match_acpi_dev);
3406+
3407+
int device_match_any(struct device *dev, const void *unused)
3408+
{
3409+
return 1;
3410+
}
3411+
EXPORT_SYMBOL_GPL(device_match_any);

drivers/base/devcon.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,13 @@ static struct bus_type *generic_match_buses[] = {
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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,20 @@ struct bus_type platform_bus_type = {
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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ static struct class *fpga_bridge_class;
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,
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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,6 @@ struct fpga_manager *fpga_mgr_get(struct device *dev)
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)
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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,6 @@ static struct bus_type mipi_dsi_bus_type = {
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)
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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,7 @@ static struct component_match *exynos_drm_match_add(struct device *dev)
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)
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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,7 @@ static int mcde_probe(struct platform_device *pdev)
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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,7 @@ static struct component_match *rockchip_drm_match_add(struct device *dev)
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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,7 @@ static void vc4_match_add_drivers(struct device *dev,
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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ static int coresight_alloc_conns(struct device *dev,
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,17 +46,15 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
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

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,4 @@ static inline void *coresight_get_uci_data(const struct amba_id *id)
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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,9 +1046,7 @@ static void coresight_fixup_device_conns(struct coresight_device *csdev)
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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -789,22 +789,14 @@ static int intel_th_populate(struct intel_th *th)
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;
801795
struct intel_th_driver *thdrv;
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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,6 @@ static struct class stm_class = {
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)
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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -457,18 +457,12 @@ static struct pci_driver amd_mp2_pci_driver = {
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

0 commit comments

Comments
 (0)