[PATCH 1/6] driver-core: platform: Provide helpers for multi-driver modules

Thierry Reding thierry.reding at gmail.com
Fri Sep 25 08:15:43 PDT 2015


On Fri, Sep 25, 2015 at 01:27:28PM +0300, Jani Nikula wrote:
> On Thu, 24 Sep 2015, Thierry Reding <thierry.reding at gmail.com> wrote:
[...]
> > diff --git a/drivers/base/platform.c b/drivers/base/platform.c
[...]
> > +/**
> > + * 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]);
> > +		if (err < 0) {
> > +			pr_err("failed to register platform driver %ps: %d\n",
> > +			       drivers[i], err);
> > +			goto error;
> > +		}
> > +	}
> > +
> > +	return 0;
> > +
> > +error:
> > +	while (i--) {
> > +		pr_debug("unregistering platform driver %ps\n", drivers[i]);
> > +		platform_driver_unregister(drivers[i]);
> > +	}
> 
> This will call platform_driver_unregister() on the driver that failed,
> but not the first driver.
> 
> You should probably make i an int, and use while (--i >= 0).

Actually it won't. I was especially careful and even tested this with
one driver by instrumenting platform_driver_register() to return failure
at various points in the sequence.

This works fine.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/dri-devel/attachments/20150925/b254adba/attachment.sig>


More information about the dri-devel mailing list