From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932951AbcBPPNF (ORCPT ); Tue, 16 Feb 2016 10:13:05 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:60967 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932640AbcBPPNC (ORCPT ); Tue, 16 Feb 2016 10:13:02 -0500 From: Arnd Bergmann To: linaro-kernel@lists.linaro.org Cc: Mark Brown , Nishanth Menon , linux-pm@vger.kernel.org, Viresh Kumar , Rafael Wysocki , linux-kernel@vger.kernel.org, Jon Hunter , Viresh Kumar , Stephen Boyd Subject: Re: [PATCH] PM / OPP: Initialize regulator pointer to an error value Date: Tue, 16 Feb 2016 16:12:39 +0100 Message-ID: <10492578.n5ZTGbvbYE@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) In-Reply-To: <20160216131108.GK18327@sirena.org.uk> References: <1455544758-7718-1-git-send-email-jonathanh@nvidia.com> <2628515.OmmYzoeulx@wuerfel> <20160216131108.GK18327@sirena.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:/+h16Ij6eFQIJix3o2KArkvoexQfzXA4bS8h0CC5OGNhm6X8Mvj CjQc0oO6BNkUL/6zcf6mq/4EWgNXKiS7C6CyzGqNqgmlKJZBFLm8RjbBJbq2t94B8bErgrY hzkqHPuu1ZGIe5DACMhCV5GAP1yB4sBo7sI6gLfyaa5fBx79t4umi/ecpHJ3raIwjOiRjzt u/+mVltHx/Vi7o2mhBRxg== X-UI-Out-Filterresults: notjunk:1;V01:K0:hkI/vLlZ7jI=:/ic/u3FShY8vNW3HhHEnfl dHn+gmpwEXH3C4S1I8VPEcelcBaSYHMPyMsU3DjaYT5bsCtKVO52y+/U0tlZdQ23OaRcbHOaG CRqKedgVlpvCzQ7TmAzz30dhrrpNMskaNV6t05Hnlef1P53yoI0euobxa7NOxX3Gmo0WF5dSc N1iOCEZS1xDngd2wd9XiAdZm3Yc1BpSwv4kdjksvs2fjclw4vWAOpgvk9dmFX49E2elzz2ZN6 PqXJMNTSdBl1IKdAdIzgY5m2PVi+5K8T0wH78T1hoA68Xj2su4XnCZP/27kzGqukrizTR90Qx b1wnNkCnyAXbD1uJexJi3hMjV1h9DxZjRShlbOOCo8qNAOPqeeFHJc3nqvsYCtR6HYkcCdB1m 61be4+k4uEdOzcy9J8b/oaifyxsnj7M8AF1OE9tHhTnFXFyI2fTY+lw1v1yE4N038gYEyUEMQ /x2ZPPe4xBxxg+wZKjLdCaeor+I0sqWjtIl5yA5FqlNwR85bIGYBHO5iAucBFon1Usrmnv14b TQlyiKP7L+EDsfxZ12Q5X+MAdtx0VzzGgbjpg/+cR04wrxfrJZzCyQw3EpMaxfFpLO7JjtwwP NKSvPfjLmOEq/6BswfKbO2+DmwneqMtNJqrmOi24vbnl8o9NVuLPa4ggxK7N1Khdzt8Q8hwWg 1tG7gR2D9mcM/FimqisvgQlEbAWKLBb/s5tQSytKKxUY4MAOc/gdfIRlwq9H6Rwy9Y+Sp7b/h i7r2bVkSp3C/Fz/Z Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tuesday 16 February 2016 13:11:08 Mark Brown wrote: > 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. Right, that is what I understood. > > 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. Sorry, I should not have said "optional" here, which has a specific meaning in the API. I meant a driver that can work with either CONFIG_REGULATOR enabled or disabled (which is something slightly different). I guess a driver needing to know whether regulators are built-in should check 'if (IS_ENABLED(CONFIG_REGULATOR))' rather than checking the return code for NULL. Arnd