From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757036AbbIYPXX (ORCPT ); Fri, 25 Sep 2015 11:23:23 -0400 Received: from mail-wi0-f170.google.com ([209.85.212.170]:38049 "EHLO mail-wi0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755269AbbIYPXU (ORCPT ); Fri, 25 Sep 2015 11:23:20 -0400 Date: Fri, 25 Sep 2015 17:23:07 +0200 From: Thierry Reding To: dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: Re: [PATCH 1/6] driver-core: platform: Provide helpers for multi-driver modules Message-ID: <20150925152307.GA7424@ulmo> References: <1443114161-7965-1-git-send-email-thierry.reding@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="tKW2IUtsqtDRztdT" Content-Disposition: inline In-Reply-To: <1443114161-7965-1-git-send-email-thierry.reding@gmail.com> User-Agent: Mutt/1.5.23+102 (2ca89bed6448) (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --tKW2IUtsqtDRztdT Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Sep 24, 2015 at 07:02:36PM +0200, Thierry Reding wrote: > From: Thierry Reding >=20 > 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. >=20 > Cc: Greg Kroah-Hartman > Signed-off-by: Thierry Reding > --- > Documentation/driver-model/platform.txt | 11 ++++++ > drivers/base/platform.c | 60 +++++++++++++++++++++++++++= ++++++ > include/linux/platform_device.h | 5 +++ > 3 files changed, 76 insertions(+) >=20 > diff --git a/Documentation/driver-model/platform.txt b/Documentation/driv= er-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 *)) > =20 > +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 *driver= s, > + unsigned int count); > + > +If one of the drivers fails to register, all drivers registered up to th= at > +point will be unregistered in reverse order. > + > =20 > 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); > =20 > +/** > + * 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 regis= ter a > + * driver, all previously registered drivers will be unregistered. Calle= rs of > + * this API should use platform_unregister_drivers() to unregister drive= rs 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 =3D 0; i < count; i++) { > + pr_debug("registering platform driver %ps\n", drivers[i]); > + > + err =3D 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 --tKW2IUtsqtDRztdT Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAABCAAGBQJWBWbbAAoJEN0jrNd/PrOhKOwQAJGpeU4ySG0hTQMo9aIlvw+M Tp3CW62va7POu6FBjno2Ar6zqdTGtNSEb1r5dR6ktxii6EK1nUhDcFQLI6GdG7Tc XSAUxp4MZIWlui14d7i9s/BEAIc0sy23QBdN59tfcdeU+JR+H7v7qgJuNiTinxjl QFLCJcmScEDFQzJHAV/ivAuAZiBroFTrasEHbdr/QwR0kdDt2TzXgUABDpwXYhO3 5EQCDX1HV/OWV4MdceRBxfDpT97DfpNqvGeTnsk1oL8G9fUv/T0yNWRZUH474AbL SbNf10D00XhmJykYSMWfbJVpbMP1DtdKulSwrvX8up84mBca2zPDtutaRTStH596 R9/92QPXRmL8Uzf9t3wmoIqRVGpqnI4X0JBulaLGAmQkakgNxbFVUGAkiEQvoyOp 1i9qtfFXd03FSAaEIGrraJw2dXTu6+NK2fFnUWDvc3ISZFhHWYFYR9zEzJAlOXJn 51/rDG3ajIbIw2y+cxkWSgi8GDesBbYFd3gibv7GDjyfzZtnG/kU3ZvA+BgS6Coo KNlxEmdq9zAsbnDHwx4dOsypg6+QFhyNb4R7ZDPfSSpZQxFGVUVu5PGYgkwAVGAN AYadIp0ZOrCJkO7Cu49k6epRHZAr9QXPDkfZo/4DsFu31bgzjHMKsQbczZLfJsf5 5Vz5uBEEqw8ItQALygoC =araf -----END PGP SIGNATURE----- --tKW2IUtsqtDRztdT--