Re: [RFC PATCH 1/2] driver core: introduce module_platform_driver_match_and_probe

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Wed, 30 Oct 2013 01:12:50 -0500, Rob Herring <robherring2@xxxxxxxxx> wrote:
> From: Rob Herring <rob.herring@xxxxxxxxxxx>
> 
> Introduce a helper to match, create and probe a platform device. This
> is for drivers such as cpuidle or cpufreq that typically don't have a
> bus device node and need to match on a system-level compatible property.
> 
> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> Cc: Grant Likely <grant.likely@xxxxxxxxxx>
> Signed-off-by: Rob Herring <rob.herring@xxxxxxxxxxx>

Oh, ick. Please no. If a platform_device isn't getting created for a
device tree node, then we should be asking why it isn't getting created
and fix the core logic rather than trying to bodge it in the driver init
code.

We should never be creating and registering devices in module init code.
We've spent the last 4 years trying to get away from that.

g.

> ---
>  include/linux/platform_device.h | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
> index ce8e4ff..0b4b1c9 100644
> --- a/include/linux/platform_device.h
> +++ b/include/linux/platform_device.h
> @@ -12,6 +12,7 @@
>  #define _PLATFORM_DEVICE_H_
>  
>  #include <linux/device.h>
> +#include <linux/err.h>
>  #include <linux/mod_devicetable.h>
>  
>  #define PLATFORM_DEVID_NONE	(-1)
> @@ -241,6 +242,28 @@ extern struct platform_device *platform_create_bundle(
>  	struct resource *res, unsigned int n_res,
>  	const void *data, size_t size);
>  
> +/*
> + * module_platform_driver_match_and_probe() - Helper macro for drivers without
> + * a bus device node and need to match on an arbitrary compatible property.
> + * This eliminates a lot of boilerplate.  Each module may only use this macro
> + * once, and calling it replaces module_init() and module_exit()
> + */
> +#define module_platform_driver_match_and_probe(__platform_driver, __platform_probe) \
> +static int __init __platform_driver##_init(void) \
> +{ \
> +	if (of_find_matching_node(NULL, (__platform_driver).driver.of_match_table)) \
> +		return PTR_ERR_OR_ZERO(platform_create_bundle(&(__platform_driver), \
> +			__platform_probe, NULL, 0, NULL, 0)); \
> +	else \
> +		return -ENODEV;	\
> +} \
> +module_init(__platform_driver##_init); \
> +static void __exit __platform_driver##_exit(void) \
> +{ \
> +	platform_driver_unregister(&(__platform_driver)); \
> +} \
> +module_exit(__platform_driver##_exit);
> +
>  /* early platform driver interface */
>  struct early_platform_driver {
>  	const char *class_str;
> -- 
> 1.8.1.2
> 

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]
  Powered by Linux