All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 1/6] driver-core: platform: Provide helpers for multi-driver modules
Date: Fri, 25 Sep 2015 17:15:43 +0200	[thread overview]
Message-ID: <20150925151543.GC22463@ulmo> (raw)
In-Reply-To: <87wpven69b.fsf@intel.com>


[-- Attachment #1.1: Type: text/plain, Size: 1850 bytes --]

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

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

WARNING: multiple messages have this Message-ID (diff)
From: Thierry Reding <thierry.reding@gmail.com>
To: Jani Nikula <jani.nikula@linux.intel.com>
Cc: dri-devel@lists.freedesktop.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/6] driver-core: platform: Provide helpers for multi-driver modules
Date: Fri, 25 Sep 2015 17:15:43 +0200	[thread overview]
Message-ID: <20150925151543.GC22463@ulmo> (raw)
In-Reply-To: <87wpven69b.fsf@intel.com>

[-- Attachment #1: Type: text/plain, Size: 1850 bytes --]

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2015-09-25 15:15 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-24 17:02 [PATCH 1/6] driver-core: platform: Provide helpers for multi-driver modules Thierry Reding
2015-09-24 17:02 ` Thierry Reding
2015-09-24 17:02 ` [PATCH 2/6] drm/tegra: Use new multi-driver module helpers Thierry Reding
2015-09-24 17:02   ` Thierry Reding
2015-09-24 17:02 ` [PATCH 3/6] drm/imx: Build monolithic driver Thierry Reding
2015-09-24 17:02   ` Thierry Reding
2015-09-25  7:16   ` Philipp Zabel
2015-09-25  7:16     ` Philipp Zabel
2015-09-25 12:17     ` Thierry Reding
2015-09-25 12:17       ` Thierry Reding
2015-09-25 13:09       ` Philipp Zabel
2015-09-25 13:09         ` Philipp Zabel
2015-09-25 13:13         ` Philipp Zabel
2015-09-25 13:13           ` Philipp Zabel
2015-09-25 14:21           ` Thierry Reding
2015-09-25 14:21             ` Thierry Reding
2015-09-24 17:02 ` [PATCH 4/6] drm/imx: Do not export symbols Thierry Reding
2015-09-24 17:02   ` Thierry Reding
2015-09-24 17:02 ` [PATCH 5/6] drm/sti: Build monolithic driver Thierry Reding
2015-09-24 17:02   ` Thierry Reding
2015-10-05  8:22   ` Vincent ABRIOU
2015-10-05  8:22     ` Vincent ABRIOU
2015-09-24 17:02 ` [PATCH 6/6] drm/sti: Do not export symbols Thierry Reding
2015-09-24 17:02   ` Thierry Reding
2015-10-05  8:22   ` Vincent ABRIOU
2015-10-05  8:22     ` Vincent ABRIOU
2015-09-25 10:27 ` [PATCH 1/6] driver-core: platform: Provide helpers for multi-driver modules Jani Nikula
2015-09-25 10:27   ` Jani Nikula
2015-09-25 15:15   ` Thierry Reding [this message]
2015-09-25 15:15     ` Thierry Reding
2015-09-28  6:37     ` Jani Nikula
2015-09-28  6:37       ` Jani Nikula
2015-09-25 14:29 ` Thierry Reding
2015-09-25 14:29   ` Thierry Reding
2015-09-26  0:55   ` Greg Kroah-Hartman
2015-09-25 15:23 ` Thierry Reding
2015-09-25 15:23   ` Thierry Reding
2015-09-25 15:29 ` [PATCH v2] " Thierry Reding
2015-09-25 15:29   ` Thierry Reding
2015-09-28  6:46   ` Andy Shevchenko
2015-09-28  9:05 ` [PATCH 1/6] " Daniel Vetter
2015-09-28  9:05   ` Daniel Vetter
2015-09-28 19:19   ` Eric Anholt
2015-09-28 19:19     ` Eric Anholt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150925151543.GC22463@ulmo \
    --to=thierry.reding@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.