[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20150925152307.GA7424@ulmo>
Date: Fri, 25 Sep 2015 17:23:07 +0200
From: Thierry Reding <thierry.reding@...il.com>
To: dri-devel@...ts.freedesktop.org
Cc: linux-kernel@...r.kernel.org,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Subject: Re: [PATCH 1/6] driver-core: platform: Provide helpers for
multi-driver modules
On Thu, Sep 24, 2015 at 07:02:36PM +0200, Thierry Reding wrote:
> From: Thierry Reding <treding@...dia.com>
>
> Some modules register several sub-drivers. Provide a helper that makes
> it easy to register and unregister a list of sub-drivers, as well as
> unwind properly on error.
>
> Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
> Signed-off-by: Thierry Reding <treding@...dia.com>
> ---
> Documentation/driver-model/platform.txt | 11 ++++++
> drivers/base/platform.c | 60 +++++++++++++++++++++++++++++++++
> include/linux/platform_device.h | 5 +++
> 3 files changed, 76 insertions(+)
>
> diff --git a/Documentation/driver-model/platform.txt b/Documentation/driver-model/platform.txt
> index 07795ec51cde..e80468738ba9 100644
> --- a/Documentation/driver-model/platform.txt
> +++ b/Documentation/driver-model/platform.txt
> @@ -63,6 +63,17 @@ runtime memory footprint:
> int platform_driver_probe(struct platform_driver *drv,
> int (*probe)(struct platform_device *))
>
> +Kernel modules can be composed of several platform drivers. The platform core
> +provides helpers to register and unregister an array of drivers:
> +
> + int platform_register_drivers(struct platform_driver * const *drivers,
> + unsigned int count);
> + void platform_unregister_drivers(struct platform_driver * const *drivers,
> + unsigned int count);
> +
> +If one of the drivers fails to register, all drivers registered up to that
> +point will be unregistered in reverse order.
> +
>
> Device Enumeration
> ~~~~~~~~~~~~~~~~~~
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index f80aaaf9f610..b7d7987fda97 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -711,6 +711,66 @@ err_out:
> }
> EXPORT_SYMBOL_GPL(__platform_create_bundle);
>
> +/**
> + * platform_register_drivers - register an array of platform drivers
> + * @drivers: an array of drivers to register
> + * @count: the number of drivers to register
> + *
> + * Registers platform drivers specified by an array. On failure to register a
> + * driver, all previously registered drivers will be unregistered. Callers of
> + * this API should use platform_unregister_drivers() to unregister drivers in
> + * the reverse order.
> + *
> + * Returns: 0 on success or a negative error code on failure.
> + */
> +int platform_register_drivers(struct platform_driver * const *drivers,
> + unsigned int count)
> +{
> + unsigned int i;
> + int err;
> +
> + for (i = 0; i < count; i++) {
> + pr_debug("registering platform driver %ps\n", drivers[i]);
> +
> + err = platform_driver_register(drivers[i]);
I notice that this is actually doing the wrong thing because the
platform drivers will end up with their .owner field set to NULL because
this file is always built-in. I've fixed it up by passing in a struct
module *owner into __platform_register_drivers() and pass it on to the
__platform_driver_register() function instead.
Thierry
Download attachment "signature.asc" of type "application/pgp-signature" (820 bytes)
Powered by blists - more mailing lists