mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	platform: Add platform_find_device_by_driver() helper
Provide a helper to lookup platform devices by matching device driver in order to avoid drivers trying to use platform bus internals. Cc: Eric Anholt <eric@anholt.net> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: "Heiko Stübner" <heiko@sntech.de> Cc: Inki Dae <inki.dae@samsung.com> Cc: "Rafael J. Wysocki" <rafael@kernel.org> Cc: Sandy Huang <hjc@rock-chips.com> Cc: Seung-Woo Kim <sw0312.kim@samsung.com> Tested-by: Heiko Stuebner <heiko@sntech.de> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> Link: https://lore.kernel.org/r/20190723221838.12024-8-suzuki.poulose@arm.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
		
							parent
							
								
									6bf85ba9e5
								
							
						
					
					
						commit
						36f3313d6b
					
				
					 6 changed files with 23 additions and 12 deletions
				
			
		| 
						 | 
					@ -1197,6 +1197,20 @@ struct bus_type platform_bus_type = {
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
EXPORT_SYMBOL_GPL(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 __init platform_bus_init(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int error;
 | 
						int error;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -242,9 +242,7 @@ static struct component_match *exynos_drm_match_add(struct device *dev)
 | 
				
			||||||
		if (!info->driver || !(info->flags & DRM_COMPONENT_DRIVER))
 | 
							if (!info->driver || !(info->flags & DRM_COMPONENT_DRIVER))
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		while ((d = bus_find_device(&platform_bus_type, p,
 | 
							while ((d = platform_find_device_by_driver(p, &info->driver->driver))) {
 | 
				
			||||||
					    &info->driver->driver,
 | 
					 | 
				
			||||||
					    (void *)platform_bus_type.match))) {
 | 
					 | 
				
			||||||
			put_device(p);
 | 
								put_device(p);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (!(info->flags & DRM_FIMC_DEVICE) ||
 | 
								if (!(info->flags & DRM_FIMC_DEVICE) ||
 | 
				
			||||||
| 
						 | 
					@ -412,9 +410,8 @@ static void exynos_drm_unregister_devices(void)
 | 
				
			||||||
		if (!info->driver || !(info->flags & DRM_VIRTUAL_DEVICE))
 | 
							if (!info->driver || !(info->flags & DRM_VIRTUAL_DEVICE))
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		while ((dev = bus_find_device(&platform_bus_type, NULL,
 | 
							while ((dev = platform_find_device_by_driver(NULL,
 | 
				
			||||||
					    &info->driver->driver,
 | 
											&info->driver->driver))) {
 | 
				
			||||||
					    (void *)platform_bus_type.match))) {
 | 
					 | 
				
			||||||
			put_device(dev);
 | 
								put_device(dev);
 | 
				
			||||||
			platform_device_unregister(to_platform_device(dev));
 | 
								platform_device_unregister(to_platform_device(dev));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -477,8 +477,7 @@ static int mcde_probe(struct platform_device *pdev)
 | 
				
			||||||
		struct device_driver *drv = &mcde_component_drivers[i]->driver;
 | 
							struct device_driver *drv = &mcde_component_drivers[i]->driver;
 | 
				
			||||||
		struct device *p = NULL, *d;
 | 
							struct device *p = NULL, *d;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		while ((d = bus_find_device(&platform_bus_type, p, drv,
 | 
							while ((d = platform_find_device_by_driver(p, drv))) {
 | 
				
			||||||
					    (void *)platform_bus_type.match))) {
 | 
					 | 
				
			||||||
			put_device(p);
 | 
								put_device(p);
 | 
				
			||||||
			component_match_add(dev, &match, mcde_compare_dev, d);
 | 
								component_match_add(dev, &match, mcde_compare_dev, d);
 | 
				
			||||||
			p = d;
 | 
								p = d;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -330,8 +330,7 @@ static struct component_match *rockchip_drm_match_add(struct device *dev)
 | 
				
			||||||
		struct device *p = NULL, *d;
 | 
							struct device *p = NULL, *d;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		do {
 | 
							do {
 | 
				
			||||||
			d = bus_find_device(&platform_bus_type, p, &drv->driver,
 | 
								d = platform_find_device_by_driver(p, &drv->driver);
 | 
				
			||||||
					    (void *)platform_bus_type.match);
 | 
					 | 
				
			||||||
			put_device(p);
 | 
								put_device(p);
 | 
				
			||||||
			p = d;
 | 
								p = d;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -237,8 +237,7 @@ static void vc4_match_add_drivers(struct device *dev,
 | 
				
			||||||
		struct device_driver *drv = &drivers[i]->driver;
 | 
							struct device_driver *drv = &drivers[i]->driver;
 | 
				
			||||||
		struct device *p = NULL, *d;
 | 
							struct device *p = NULL, *d;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		while ((d = bus_find_device(&platform_bus_type, p, drv,
 | 
							while ((d = platform_find_device_by_driver(p, drv))) {
 | 
				
			||||||
					    (void *)platform_bus_type.match))) {
 | 
					 | 
				
			||||||
			put_device(p);
 | 
								put_device(p);
 | 
				
			||||||
			component_match_add(dev, match, compare_dev, d);
 | 
								component_match_add(dev, match, compare_dev, d);
 | 
				
			||||||
			p = d;
 | 
								p = d;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,6 +51,9 @@ extern struct device platform_bus;
 | 
				
			||||||
extern void arch_setup_pdev_archdata(struct platform_device *);
 | 
					extern void arch_setup_pdev_archdata(struct platform_device *);
 | 
				
			||||||
extern struct resource *platform_get_resource(struct platform_device *,
 | 
					extern struct resource *platform_get_resource(struct platform_device *,
 | 
				
			||||||
					      unsigned int, unsigned int);
 | 
										      unsigned int, unsigned int);
 | 
				
			||||||
 | 
					extern struct device *
 | 
				
			||||||
 | 
					platform_find_device_by_driver(struct device *start,
 | 
				
			||||||
 | 
								       const struct device_driver *drv);
 | 
				
			||||||
extern void __iomem *
 | 
					extern void __iomem *
 | 
				
			||||||
devm_platform_ioremap_resource(struct platform_device *pdev,
 | 
					devm_platform_ioremap_resource(struct platform_device *pdev,
 | 
				
			||||||
			       unsigned int index);
 | 
								       unsigned int index);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue