Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1233879

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

From Jani Nikula <jani.nikula@linux.intel.com>
Newsgroups linux.kernel
Subject Re: [PATCH 1/6] driver-core: platform: Provide helpers for multi-driver modules
Date 2015-09-28 08:40 +0200
Message-ID <qdAgp-6c0-3@gated-at.bofh.it> (permalink)
References <qcibT-Sv-5@gated-at.bofh.it> <qcyql-6Zt-9@gated-at.bofh.it> <qcCX0-58P-23@gated-at.bofh.it>
Organization Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo

Show all headers | View raw


On Fri, 25 Sep 2015, Thierry Reding <thierry.reding@gmail.com> wrote:
> 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.

You are right, of course. What was I thinking. My kingdom for an excuse!

BR,
Jani.




-- 
Jani Nikula, Intel Open Source Technology Center
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 1/6] driver-core: platform: Provide helpers for multi-driver modules Thierry Reding <thierry.reding@gmail.com> - 2015-09-24 19:10 +0200
  Re: [PATCH 1/6] driver-core: platform: Provide helpers for multi-driver modules Jani Nikula <jani.nikula@linux.intel.com> - 2015-09-25 12:30 +0200
    Re: [PATCH 1/6] driver-core: platform: Provide helpers for  multi-driver modules Thierry Reding <thierry.reding@gmail.com> - 2015-09-25 17:20 +0200
      Re: [PATCH 1/6] driver-core: platform: Provide helpers for multi-driver modules Jani Nikula <jani.nikula@linux.intel.com> - 2015-09-28 08:40 +0200
  Re: [PATCH 1/6] driver-core: platform: Provide helpers for  multi-driver modules Thierry Reding <thierry.reding@gmail.com> - 2015-09-25 16:30 +0200
    Re: [PATCH 1/6] driver-core: platform: Provide helpers for  multi-driver modules Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-09-26 03:00 +0200
  [PATCH v2] driver-core: platform: Provide helpers for multi-driver modules Thierry Reding <thierry.reding@gmail.com> - 2015-09-25 17:30 +0200
    Re: [PATCH v2] driver-core: platform: Provide helpers for  multi-driver modules Andy Shevchenko <andy.shevchenko@gmail.com> - 2015-09-28 08:50 +0200
  Re: [PATCH 1/6] driver-core: platform: Provide helpers for  multi-driver modules Thierry Reding <thierry.reding@gmail.com> - 2015-09-25 17:30 +0200
  Re: [PATCH 1/6] driver-core: platform: Provide helpers for  multi-driver modules Daniel Vetter <daniel@ffwll.ch> - 2015-09-28 11:10 +0200
    Re: [PATCH 1/6] driver-core: platform: Provide helpers for multi-driver modules Eric Anholt <eric@anholt.net> - 2015-09-28 21:20 +0200

csiph-web