Skip to content

Commit

Permalink
Merge generic_lookup_helpers into usb-next
Browse files Browse the repository at this point in the history
The lookup helpers are needed here.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Greg Kroah-Hartman committed Sep 3, 2019
2 parents a31f017 + 36f3313 commit c5c0283
Show file tree
Hide file tree
Showing 48 changed files with 341 additions and 383 deletions.
11 changes: 1 addition & 10 deletions drivers/amba/tegra-ahb.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,13 @@ static inline void gizmo_writel(struct tegra_ahb *ahb, u32 value, u32 offset)
}

#ifdef CONFIG_TEGRA_IOMMU_SMMU
static int tegra_ahb_match_by_smmu(struct device *dev, const void *data)
{
struct tegra_ahb *ahb = dev_get_drvdata(dev);
const struct device_node *dn = data;

return (ahb->dev->of_node == dn) ? 1 : 0;
}

int tegra_ahb_enable_smmu(struct device_node *dn)
{
struct device *dev;
u32 val;
struct tegra_ahb *ahb;

dev = driver_find_device(&tegra_ahb_driver.driver, NULL, dn,
tegra_ahb_match_by_smmu);
dev = driver_find_device_by_of_node(&tegra_ahb_driver.driver, dn);
if (!dev)
return -EPROBE_DEFER;
ahb = dev_get_drvdata(dev);
Expand Down
24 changes: 0 additions & 24 deletions drivers/base/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,30 +342,6 @@ struct device *bus_find_device(struct bus_type *bus,
}
EXPORT_SYMBOL_GPL(bus_find_device);

static int match_name(struct device *dev, const void *data)
{
const char *name = data;

return sysfs_streq(name, dev_name(dev));
}

/**
* bus_find_device_by_name - device iterator for locating a particular device of a specific name
* @bus: bus type
* @start: Device to begin with
* @name: name of the device to match
*
* This is similar to the bus_find_device() function above, but it handles
* searching by a name automatically, no need to write another strcmp matching
* function.
*/
struct device *bus_find_device_by_name(struct bus_type *bus,
struct device *start, const char *name)
{
return bus_find_device(bus, start, (void *)name, match_name);
}
EXPORT_SYMBOL_GPL(bus_find_device_by_name);

/**
* subsys_find_device_by_id - find a device with a specific enumeration number
* @subsys: subsystem
Expand Down
39 changes: 31 additions & 8 deletions drivers/base/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2932,13 +2932,6 @@ struct device *device_create_with_groups(struct class *class,
}
EXPORT_SYMBOL_GPL(device_create_with_groups);

static int __match_devt(struct device *dev, const void *data)
{
const dev_t *devt = data;

return dev->devt == *devt;
}

/**
* device_destroy - removes a device that was created with device_create()
* @class: pointer to the struct class that this device was registered with
Expand All @@ -2951,7 +2944,7 @@ void device_destroy(struct class *class, dev_t devt)
{
struct device *dev;

dev = class_find_device(class, NULL, &devt, __match_devt);
dev = class_find_device_by_devt(class, devt);
if (dev) {
put_device(dev);
device_unregister(dev);
Expand Down Expand Up @@ -3422,8 +3415,38 @@ void device_set_of_node_from_dev(struct device *dev, const struct device *dev2)
}
EXPORT_SYMBOL_GPL(device_set_of_node_from_dev);

int device_match_name(struct device *dev, const void *name)
{
return sysfs_streq(dev_name(dev), name);
}
EXPORT_SYMBOL_GPL(device_match_name);

int device_match_of_node(struct device *dev, const void *np)
{
return dev->of_node == np;
}
EXPORT_SYMBOL_GPL(device_match_of_node);

int device_match_fwnode(struct device *dev, const void *fwnode)
{
return dev_fwnode(dev) == fwnode;
}
EXPORT_SYMBOL_GPL(device_match_fwnode);

int device_match_devt(struct device *dev, const void *pdevt)
{
return dev->devt == *(dev_t *)pdevt;
}
EXPORT_SYMBOL_GPL(device_match_devt);

int device_match_acpi_dev(struct device *dev, const void *adev)
{
return ACPI_COMPANION(dev) == adev;
}
EXPORT_SYMBOL(device_match_acpi_dev);

int device_match_any(struct device *dev, const void *unused)
{
return 1;
}
EXPORT_SYMBOL_GPL(device_match_any);
8 changes: 1 addition & 7 deletions drivers/base/devcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,13 @@ static struct bus_type *generic_match_buses[] = {
NULL,
};

static int device_fwnode_match(struct device *dev, const void *fwnode)
{
return dev_fwnode(dev) == fwnode;
}

static void *device_connection_fwnode_match(struct device_connection *con)
{
struct bus_type *bus;
struct device *dev;

for (bus = generic_match_buses[0]; bus; bus++) {
dev = bus_find_device(bus, NULL, (void *)con->fwnode,
device_fwnode_match);
dev = bus_find_device_by_fwnode(bus, con->fwnode);
if (dev && !strncmp(dev_name(dev), con->id, strlen(con->id)))
return dev;

Expand Down
14 changes: 14 additions & 0 deletions drivers/base/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,20 @@ struct bus_type platform_bus_type = {
};
EXPORT_SYMBOL_GPL(platform_bus_type);

/**
* platform_find_device_by_driver - Find a platform device with a given
* driver.
* @start: The device to start the search from.
* @drv: The device driver to look for.
*/
struct device *platform_find_device_by_driver(struct device *start,
const struct device_driver *drv)
{
return bus_find_device(&platform_bus_type, start, drv,
(void *)platform_match);
}
EXPORT_SYMBOL_GPL(platform_find_device_by_driver);

int __init platform_bus_init(void)
{
int error;
Expand Down
8 changes: 1 addition & 7 deletions drivers/fpga/fpga-bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ static struct class *fpga_bridge_class;
/* Lock for adding/removing bridges to linked lists*/
static spinlock_t bridge_list_lock;

static int fpga_bridge_of_node_match(struct device *dev, const void *data)
{
return dev->of_node == data;
}

/**
* fpga_bridge_enable - Enable transactions on the bridge
*
Expand Down Expand Up @@ -104,8 +99,7 @@ struct fpga_bridge *of_fpga_bridge_get(struct device_node *np,
{
struct device *dev;

dev = class_find_device(fpga_bridge_class, NULL, np,
fpga_bridge_of_node_match);
dev = class_find_device_by_of_node(fpga_bridge_class, np);
if (!dev)
return ERR_PTR(-ENODEV);

Expand Down
8 changes: 1 addition & 7 deletions drivers/fpga/fpga-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,6 @@ struct fpga_manager *fpga_mgr_get(struct device *dev)
}
EXPORT_SYMBOL_GPL(fpga_mgr_get);

static int fpga_mgr_of_node_match(struct device *dev, const void *data)
{
return dev->of_node == data;
}

/**
* of_fpga_mgr_get - Given a device node, get a reference to a fpga mgr.
*
Expand All @@ -498,8 +493,7 @@ struct fpga_manager *of_fpga_mgr_get(struct device_node *node)
{
struct device *dev;

dev = class_find_device(fpga_mgr_class, NULL, node,
fpga_mgr_of_node_match);
dev = class_find_device_by_of_node(fpga_mgr_class, node);
if (!dev)
return ERR_PTR(-ENODEV);

Expand Down
7 changes: 1 addition & 6 deletions drivers/gpu/drm/drm_mipi_dsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ static struct bus_type mipi_dsi_bus_type = {
.pm = &mipi_dsi_device_pm_ops,
};

static int of_device_match(struct device *dev, const void *data)
{
return dev->of_node == data;
}

/**
* of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a
* device tree node
Expand All @@ -110,7 +105,7 @@ struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np)
{
struct device *dev;

dev = bus_find_device(&mipi_dsi_bus_type, NULL, np, of_device_match);
dev = bus_find_device_by_of_node(&mipi_dsi_bus_type, np);

return dev ? to_mipi_dsi_device(dev) : NULL;
}
Expand Down
9 changes: 3 additions & 6 deletions drivers/gpu/drm/exynos/exynos_drm_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,7 @@ static struct component_match *exynos_drm_match_add(struct device *dev)
if (!info->driver || !(info->flags & DRM_COMPONENT_DRIVER))
continue;

while ((d = bus_find_device(&platform_bus_type, p,
&info->driver->driver,
(void *)platform_bus_type.match))) {
while ((d = platform_find_device_by_driver(p, &info->driver->driver))) {
put_device(p);

if (!(info->flags & DRM_FIMC_DEVICE) ||
Expand Down Expand Up @@ -412,9 +410,8 @@ static void exynos_drm_unregister_devices(void)
if (!info->driver || !(info->flags & DRM_VIRTUAL_DEVICE))
continue;

while ((dev = bus_find_device(&platform_bus_type, NULL,
&info->driver->driver,
(void *)platform_bus_type.match))) {
while ((dev = platform_find_device_by_driver(NULL,
&info->driver->driver))) {
put_device(dev);
platform_device_unregister(to_platform_device(dev));
}
Expand Down
3 changes: 1 addition & 2 deletions drivers/gpu/drm/mcde/mcde_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,7 @@ static int mcde_probe(struct platform_device *pdev)
struct device_driver *drv = &mcde_component_drivers[i]->driver;
struct device *p = NULL, *d;

while ((d = bus_find_device(&platform_bus_type, p, drv,
(void *)platform_bus_type.match))) {
while ((d = platform_find_device_by_driver(p, drv))) {
put_device(p);
component_match_add(dev, &match, mcde_compare_dev, d);
p = d;
Expand Down
3 changes: 1 addition & 2 deletions drivers/gpu/drm/rockchip/rockchip_drm_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,7 @@ static struct component_match *rockchip_drm_match_add(struct device *dev)
struct device *p = NULL, *d;

do {
d = bus_find_device(&platform_bus_type, p, &drv->driver,
(void *)platform_bus_type.match);
d = platform_find_device_by_driver(p, &drv->driver);
put_device(p);
p = d;

Expand Down
3 changes: 1 addition & 2 deletions drivers/gpu/drm/vc4/vc4_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ static void vc4_match_add_drivers(struct device *dev,
struct device_driver *drv = &drivers[i]->driver;
struct device *p = NULL, *d;

while ((d = bus_find_device(&platform_bus_type, p, drv,
(void *)platform_bus_type.match))) {
while ((d = platform_find_device_by_driver(p, drv))) {
put_device(p);
component_match_add(dev, match, compare_dev, d);
p = d;
Expand Down
11 changes: 2 additions & 9 deletions drivers/hwtracing/coresight/coresight-platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ static int coresight_alloc_conns(struct device *dev,
return 0;
}

int coresight_device_fwnode_match(struct device *dev, const void *fwnode)
{
return dev_fwnode(dev) == fwnode;
}

static struct device *
coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
{
Expand All @@ -51,17 +46,15 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
* If we have a non-configurable replicator, it will be found on the
* platform bus.
*/
dev = bus_find_device(&platform_bus_type, NULL,
fwnode, coresight_device_fwnode_match);
dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
if (dev)
return dev;

/*
* We have a configurable component - circle through the AMBA bus
* looking for the device that matches the endpoint node.
*/
return bus_find_device(&amba_bustype, NULL,
fwnode, coresight_device_fwnode_match);
return bus_find_device_by_fwnode(&amba_bustype, fwnode);
}

#ifdef CONFIG_OF
Expand Down
2 changes: 0 additions & 2 deletions drivers/hwtracing/coresight/coresight-priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,4 @@ static inline void *coresight_get_uci_data(const struct amba_id *id)

void coresight_release_platform_data(struct coresight_platform_data *pdata);

int coresight_device_fwnode_match(struct device *dev, const void *fwnode);

#endif
4 changes: 1 addition & 3 deletions drivers/hwtracing/coresight/coresight.c
Original file line number Diff line number Diff line change
Expand Up @@ -1046,9 +1046,7 @@ static void coresight_fixup_device_conns(struct coresight_device *csdev)
struct coresight_connection *conn = &csdev->pdata->conns[i];
struct device *dev = NULL;

dev = bus_find_device(&coresight_bustype, NULL,
(void *)conn->child_fwnode,
coresight_device_fwnode_match);
dev = bus_find_device_by_fwnode(&coresight_bustype, conn->child_fwnode);
if (dev) {
conn->child_dev = to_coresight_device(dev);
/* and put reference from 'bus_find_device()' */
Expand Down
10 changes: 1 addition & 9 deletions drivers/hwtracing/intel_th/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,22 +789,14 @@ static int intel_th_populate(struct intel_th *th)
return 0;
}

static int match_devt(struct device *dev, const void *data)
{
dev_t devt = (dev_t)(unsigned long)(void *)data;
return dev->devt == devt;
}

static int intel_th_output_open(struct inode *inode, struct file *file)
{
const struct file_operations *fops;
struct intel_th_driver *thdrv;
struct device *dev;
int err;

dev = bus_find_device(&intel_th_bus, NULL,
(void *)(unsigned long)inode->i_rdev,
match_devt);
dev = bus_find_device_by_devt(&intel_th_bus, inode->i_rdev);
if (!dev || !dev->driver)
return -ENODEV;

Expand Down
9 changes: 1 addition & 8 deletions drivers/hwtracing/stm/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ static struct class stm_class = {
.dev_groups = stm_groups,
};

static int stm_dev_match(struct device *dev, const void *data)
{
const char *name = data;

return sysfs_streq(name, dev_name(dev));
}

/**
* stm_find_device() - find stm device by name
* @buf: character buffer containing the name
Expand All @@ -116,7 +109,7 @@ struct stm_device *stm_find_device(const char *buf)
if (!stm_core_up)
return NULL;

dev = class_find_device(&stm_class, NULL, buf, stm_dev_match);
dev = class_find_device_by_name(&stm_class, buf);
if (!dev)
return NULL;

Expand Down
8 changes: 1 addition & 7 deletions drivers/i2c/busses/i2c-amd-mp2-pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,18 +457,12 @@ static struct pci_driver amd_mp2_pci_driver = {
};
module_pci_driver(amd_mp2_pci_driver);

static int amd_mp2_device_match(struct device *dev, const void *data)
{
return 1;
}

struct amd_mp2_dev *amd_mp2_find_device(void)
{
struct device *dev;
struct pci_dev *pci_dev;

dev = driver_find_device(&amd_mp2_pci_driver.driver, NULL, NULL,
amd_mp2_device_match);
dev = driver_find_next_device(&amd_mp2_pci_driver.driver, NULL);
if (!dev)
return NULL;

Expand Down
Loading

0 comments on commit c5c0283

Please sign in to comment.