lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75Vdj78SwTv9KzopqsqMVc0CK=WiCcizvh-jUjp+_iVg5Ew@mail.gmail.com>
Date:	Mon, 28 Sep 2015 09:46:23 +0300
From:	Andy Shevchenko <andy.shevchenko@...il.com>
To:	Thierry Reding <thierry.reding@...il.com>
Cc:	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	dri-devel@...ts.freedesktop.org,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2] driver-core: platform: Provide helpers for
 multi-driver modules

On Fri, Sep 25, 2015 at 6:29 PM, Thierry Reding
<thierry.reding@...il.com> 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>

> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index f80aaaf9f610..68c58c43e45a 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -711,6 +711,67 @@ 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
> + * @owner: module owning the drivers
> + *
> + * 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, struct module *owner)
> +{
> +       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], owner);
> +               if (err < 0) {
> +                       pr_err("failed to register platform driver %ps: %d\n",
> +                              drivers[i], err);

Would
platform_unregister_drivers(drivers, i);
work?

> +                       goto error;
> +               }
> +       }
> +
> +       return 0;
> +
> +error:
> +       while (i--) {

I think Jani was confused since often idiom is 'while (--i >=0)' is used.

> +               pr_debug("unregistering platform driver %ps\n", drivers[i]);
> +               platform_driver_unregister(drivers[i]);
> +       }
> +
> +       return err;
> +}
> +EXPORT_SYMBOL_GPL(__platform_register_drivers);
> +
> +/**
> + * platform_unregister_drivers - unregister an array of platform drivers
> + * @drivers: an array of drivers to unregister
> + * @count: the number of drivers to unregister
> + *
> + * Unegisters platform drivers specified by an array. This is typically used
> + * to complement an earlier call to platform_register_drivers(). Drivers are
> + * unregistered in the reverse order in which they were registered.
> + */
> +void platform_unregister_drivers(struct platform_driver * const *drivers,
> +                                unsigned int count)
> +{
> +       while (count--) {
> +               pr_debug("unregistering platform driver %ps\n", drivers[count]);
> +               platform_driver_unregister(drivers[count]);
> +       }
> +}
> +EXPORT_SYMBOL_GPL(platform_unregister_drivers);

-- 
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ