lkml.org 
[lkml]   [2015]   [Sep]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH 1/6] driver-core: platform: Provide helpers for multi-driver modules
    On Fri, Sep 25, 2015 at 01:27:28PM +0300, Jani Nikula wrote:
    > On Thu, 24 Sep 2015, Thierry Reding <thierry.reding@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
    [unhandled content-type:application/pgp-signature]
    \
     
     \ /
      Last update: 2015-09-25 17:21    [W:4.030 / U:0.808 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site