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


Groups > linux.kernel > #1335362

Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value

From Mark Brown <broonie@kernel.org>
Newsgroups linux.kernel
Subject Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value
Date 2016-02-16 14:20 +0100
Message-ID <r2NHQ-8jx-17@gated-at.bofh.it> (permalink)
References <r2ucb-3qG-61@gated-at.bofh.it> <r2Cjo-wW-11@gated-at.bofh.it> <r2D5M-Rv-9@gated-at.bofh.it> <r2JXB-5TU-45@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Tue, Feb 16, 2016 at 10:10:44AM +0100, Arnd Bergmann wrote:
> On Tuesday 16 February 2016 01:56:16 Mark Brown wrote:

> > No, NULL is explicitly not something you can substitute in,
> > essentially all the users are just not bothering to implement error
> > checking and we don't want to encourage that.  The set of use cases
> > where we legitimately have optional supplies is very small, much smaller
> > than clocks, because it makes the electrical engineering a lot harder.

> I must have misinterpreted the idea behind that API as well then.

> From this function definition:

> static inline struct regulator *__must_check regulator_get(struct device *dev,
>         const char *id)
> {       
>         /* Nothing except the stubbed out regulator API should be
>          * looking at the value except to check if it is an error
>          * value. Drivers are free to handle NULL specifically by
>          * skipping all regulator API calls, but they don't have to.
>          * Drivers which don't, should make sure they properly handle
>          * corner cases of the API, such as regulator_get_voltage()
>          * returning 0.
>          */             
>         return NULL;
> }

This is the stubbed regulator API which is only ever used with the stub
regulator API, it uses NULL to give a non-error pointer it can return to
well written callers so they don't know they are running with the stubs.
We are explicitly using NULL because callers should treat it as a valid
regulator.

> my reading was that the expected behavior in any driver was:

> * call regulator_get()
> * if IS_ERR(), fail device probe function, never use invalid
>   pointer other than PTR_ERR()
> * if NULL, and regulator is required, fail probe so we never
>   use the regulator

No, drivers should never look at the value of the pointer other than to
check it for error.  If there is a problem of any kind an error will be
returned.

> * if NULL, and regulators are optional, continue with the NULL
>   value.

No, we always return an error pointer if we fail to get a regulator.
The difference with optional regulators is in how we handle the
situation where we have full constraints and a regulator is not mapped
in, normally we assume there must be one with no software control but we
need to work around buggy bindings as the device would be non-functional
without power.

> * drivers never look into the regulator pointer, and only
>   pass it into regulator APIs which can cope with the NULL
>   value when CONFIG_REGULATOR is disabled.

> That would be similar to what we have for clocks. Which part of
> my interpretation is wrong?

See above.

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


Thread

[PATCH] PM / OPP: Initialize regulator pointer to an error value Viresh Kumar <viresh.kumar@linaro.org> - 2016-02-15 17:30 +0100
  Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value Viresh Kumar <viresh.kumar@linaro.org> - 2016-02-15 17:50 +0100
  Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value Jon Hunter <jonathanh@nvidia.com> - 2016-02-15 17:50 +0100
  Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value Arnd Bergmann <arnd@arndb.de> - 2016-02-15 21:40 +0100
    Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value "Rafael J. Wysocki" <rafael@kernel.org> - 2016-02-15 22:20 +0100
      Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value Viresh Kumar <viresh.kumar@linaro.org> - 2016-02-16 01:50 +0100
        Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2016-02-16 01:50 +0100
    Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value Viresh Kumar <viresh.kumar@linaro.org> - 2016-02-16 02:10 +0100
      Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value Mark Brown <broonie@kernel.org> - 2016-02-16 03:00 +0100
        Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value Arnd Bergmann <arnd@arndb.de> - 2016-02-16 10:20 +0100
          Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value Mark Brown <broonie@kernel.org> - 2016-02-16 14:20 +0100
            Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value Arnd Bergmann <arnd@arndb.de> - 2016-02-16 16:20 +0100
              Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value Mark Brown <broonie@kernel.org> - 2016-02-16 18:00 +0100

csiph-web