From patchwork Wed Dec 12 11:45:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Pisati X-Patchwork-Id: 1865581 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id CBC50E01E7 for ; Wed, 12 Dec 2012 11:46:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752854Ab2LLLqX (ORCPT ); Wed, 12 Dec 2012 06:46:23 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:37479 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751711Ab2LLLqW (ORCPT ); Wed, 12 Dec 2012 06:46:22 -0500 Received: from 2-230-238-136.ip204.fastwebnet.it ([2.230.238.136] helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1TiklZ-0001ak-8B; Wed, 12 Dec 2012 11:46:21 +0000 From: Paolo Pisati To: linux-omap Cc: Paul Walmsley , Liam Girdwood , Mark Brown , linux-kernel@vger.kernel.org, Paolo Pisati Subject: [PATCH] regulator: core: if voltage scaling fails, restore original voltage values Date: Wed, 12 Dec 2012 12:45:53 +0100 Message-Id: <1355312753-16514-2-git-send-email-paolo.pisati@canonical.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1355312753-16514-1-git-send-email-paolo.pisati@canonical.com> References: <1355312753-16514-1-git-send-email-paolo.pisati@canonical.com> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org Signed-off-by: Paolo Pisati Tested-by: Robert Nelson --- drivers/regulator/core.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index e872c8b..c347fd0 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2250,6 +2250,7 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) { struct regulator_dev *rdev = regulator->rdev; int ret = 0; + int old_min_uV, old_max_uV; mutex_lock(&rdev->mutex); @@ -2271,18 +2272,29 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) ret = regulator_check_voltage(rdev, &min_uV, &max_uV); if (ret < 0) goto out; + + /* restore original values in case of error */ + old_min_uV = regulator->min_uV; + old_max_uV = regulator->max_uV; regulator->min_uV = min_uV; regulator->max_uV = max_uV; ret = regulator_check_consumers(rdev, &min_uV, &max_uV); if (ret < 0) - goto out; + goto out2; ret = _regulator_do_set_voltage(rdev, min_uV, max_uV); - + if (ret < 0) + goto out2; + out: mutex_unlock(&rdev->mutex); return ret; +out2: + regulator->min_uV = old_min_uV; + regulator->max_uV = old_max_uV; + mutex_unlock(&rdev->mutex); + return ret; } EXPORT_SYMBOL_GPL(regulator_set_voltage);