From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756136AbbCDNpK (ORCPT ); Wed, 4 Mar 2015 08:45:10 -0500 Received: from bhuna.collabora.co.uk ([93.93.135.160]:36073 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752207AbbCDNpH (ORCPT ); Wed, 4 Mar 2015 08:45:07 -0500 Message-ID: <54F70C5C.4080201@collabora.co.uk> Date: Wed, 04 Mar 2015 14:45:00 +0100 From: Javier Martinez Canillas User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.2.0 MIME-Version: 1.0 To: Doug Anderson CC: Mark Brown , Liam Girdwood , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 1/1] regulator: Only enable disabled regulators on resume References: <1425328839-28330-1-git-send-email-javier.martinez@collabora.co.uk> <54F60602.3030505@collabora.co.uk> In-Reply-To: <54F60602.3030505@collabora.co.uk> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Doug, On 03/03/2015 08:05 PM, Javier Martinez Canillas wrote: > On 03/03/2015 06:24 PM, Doug Anderson wrote: >>> >>> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c >>> index f2452148c8da..8551400d57e4 100644 >>> --- a/drivers/regulator/core.c >>> +++ b/drivers/regulator/core.c >>> @@ -3816,9 +3816,11 @@ int regulator_suspend_finish(void) >>> list_for_each_entry(rdev, ®ulator_list, list) { >>> mutex_lock(&rdev->mutex); >>> if (rdev->use_count > 0 || rdev->constraints->always_on) { >>> - error = _regulator_do_enable(rdev); >>> - if (error) >>> - ret = error; >>> + if (!_regulator_is_enabled(rdev)) { >> >> Looking at _regulator_enable() I see that _regulator_is_enabled() >> could return an error. Should we be checking? Maybe we should have a >> helper function called by both callers? >> > > Thanks for pointing that out. I'll change it on v2 as well. > Looking at the code now I remember why I didn't checked for an error in _regulator_is_enable(), sorry I wrote the patch months ago. The thing is that _regulator_is_enabled() used to return -EINVAL if the rdev didn't have an .is_enabled callback but that changed in commit 9a7f6a4c6edc8 ("regulator: Assume regulators are enabled if they don't report anything") and now returns 1 in that case. But _regulator_enable() was not changed and is still checking for -EINVAL which seems to me like a left over after the mentioned commit. Also, _regulator_enable() is the only place that has a check for a negative errno value returned by _regulator_is_enabled(). All other functions calling _regulator_is_enabled() seems to assume that a return value != 0 means that the regulator is enabled. Is true though that the rdev .is_enabled callback function may return an error so I don't know if all those callers are missing a check or if it's a design decision to assume that a regulator should be enabled if the actual hardware state can't be obtained. Best regards, Javier