From patchwork Sun Nov 29 08:31:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pi-cheng.chen" X-Patchwork-Id: 57395 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp803439lbb; Sun, 29 Nov 2015 00:31:53 -0800 (PST) X-Received: by 10.98.19.12 with SMTP id b12mr60882411pfj.78.1448785913077; Sun, 29 Nov 2015 00:31:53 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p70si17059893pfi.231.2015.11.29.00.31.52; Sun, 29 Nov 2015 00:31:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro-org.20150623.gappssmtp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752087AbbK2Ibw (ORCPT + 11 others); Sun, 29 Nov 2015 03:31:52 -0500 Received: from mail-pa0-f41.google.com ([209.85.220.41]:35749 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752049AbbK2Ibv (ORCPT ); Sun, 29 Nov 2015 03:31:51 -0500 Received: by pacej9 with SMTP id ej9so152808467pac.2 for ; Sun, 29 Nov 2015 00:31:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sln3sJk6S5tNA6cWD4Jda96veRUX5l74DTq4DHAEH50=; b=2QPRztnhJQsOXuFoOe84dEGurMD5p/F1y4Nor+0ulnc/uINiOU3RHNXXIekgIytMSR XOgPcuo5Ua3dPfdJi/tV/BjD91YtwPM8L16a3I5E39WbK65MWT7XU5nVKcR87C5LggXN Mxo+eS+Dsx64teJFLs6pDewiURCNBC6m5NlO2gK5Z7ec21JQmQKt74a4o9D0/la4DH6V UUy6WfNIsUxGvtpnV7o8gELMMdyz5fUEGXI0ccbEgzJiUD4ZUpx3rjDZz0gJLED7p7AW ZfFSiCRHs/0B2V2u5o8ZT3N/C7u4ZrbWF86wOLIRb3I490NGDiieUNEvmtl/vbPJYO+8 3txw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sln3sJk6S5tNA6cWD4Jda96veRUX5l74DTq4DHAEH50=; b=ecI1QAJCSB0sRne9vhsxMShRAV4TChpbvi6ViR6GZVHHsyOlYY8AKtpHjbwrPTnvWT AgqG1+VlLLL54XqEKB7zJ2Yx/b3ZzNDAas+VKWOQfXqbzAjH5Y8oodbFtoRMKIvTRTNO g6ZmMyIG9AVTEpGdqcp9R9hK1dkBq/F5VQZVLuVR6z2xDedjU1McssoXYD3Vo7C5XP7Y xrGiCKvLFXO1nTh0IbHF2px5dxAuIQwt6KSNdmYAKAiJR5XYqLIboVqmzFh44+l8bEqb wDYMQXSn8HbJUcSd+HfjP584TynXYDZ2IH8DFv3OqqkNYQlmjsC187cz0TfUd5vWLBfk je9Q== X-Gm-Message-State: ALoCoQmFJHcixhaPObLe2RHkcMkr8CUpApyNZS8MTGSwg5UqpWhcEE8ppOsr4ReZQb5L+mNU3lS4 X-Received: by 10.98.18.22 with SMTP id a22mr60592488pfj.54.1448785911325; Sun, 29 Nov 2015 00:31:51 -0800 (PST) Received: from localhost.localdomain ([124.219.30.17]) by smtp.googlemail.com with ESMTPSA id l84sm2516886pfb.15.2015.11.29.00.31.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 29 Nov 2015 00:31:50 -0800 (PST) From: Pi-Cheng Chen To: Viresh Kumar , Matthias Brugger Cc: Daniel Kurtz , linux-mediatek@lists.infradead.org, linaro-kernel@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org Subject: [PATCH 3/4] cpufreq: mt8173: check return value of regulator_get_voltage() call Date: Sun, 29 Nov 2015 16:31:37 +0800 Message-Id: <1448785898-17838-3-git-send-email-pi-cheng.chen@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1448785898-17838-1-git-send-email-pi-cheng.chen@linaro.org> References: <1448785898-17838-1-git-send-email-pi-cheng.chen@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Sometimes regulator_get_voltage() call returns negative values for reasons(e.g. underlying I2C bus timeout). Add check for the return values and fail out early. Signed-off-by: Pi-Cheng Chen --- drivers/cpufreq/mt8173-cpufreq.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Acked-by: Viresh Kumar diff --git a/drivers/cpufreq/mt8173-cpufreq.c b/drivers/cpufreq/mt8173-cpufreq.c index 750cda7..9d0fe37 100644 --- a/drivers/cpufreq/mt8173-cpufreq.c +++ b/drivers/cpufreq/mt8173-cpufreq.c @@ -59,6 +59,10 @@ static int mtk_cpufreq_voltage_tracking(struct mtk_cpu_dvfs_info *info, int old_vproc, old_vsram, new_vsram, vsram, vproc, ret; old_vproc = regulator_get_voltage(proc_reg); + if (old_vproc < 0) { + pr_err("%s: invalid Vproc value: %d\n", __func__, old_vproc); + return old_vproc; + } /* Vsram should not exceed the maximum allowed voltage of SoC. */ new_vsram = min(new_vproc + MIN_VOLT_SHIFT, MAX_VOLT_LIMIT); @@ -71,7 +75,17 @@ static int mtk_cpufreq_voltage_tracking(struct mtk_cpu_dvfs_info *info, */ do { old_vsram = regulator_get_voltage(sram_reg); + if (old_vsram < 0) { + pr_err("%s: invalid Vsram value: %d\n", + __func__, old_vsram); + return old_vsram; + } old_vproc = regulator_get_voltage(proc_reg); + if (old_vproc < 0) { + pr_err("%s: invalid Vproc value: %d\n", + __func__, old_vproc); + return old_vproc; + } vsram = min(new_vsram, old_vproc + MAX_VOLT_SHIFT); @@ -116,7 +130,17 @@ static int mtk_cpufreq_voltage_tracking(struct mtk_cpu_dvfs_info *info, */ do { old_vproc = regulator_get_voltage(proc_reg); + if (old_vproc < 0) { + pr_err("%s: invalid Vproc value: %d\n", + __func__, old_vproc); + return old_vproc; + } old_vsram = regulator_get_voltage(sram_reg); + if (old_vsram < 0) { + pr_err("%s: invalid Vsram value: %d\n", + __func__, old_vsram); + return old_vsram; + } vproc = max(new_vproc, old_vsram - MAX_VOLT_SHIFT); ret = regulator_set_voltage(proc_reg, vproc, @@ -184,6 +208,10 @@ static int mtk_cpufreq_set_target(struct cpufreq_policy *policy, old_freq_hz = clk_get_rate(cpu_clk); old_vproc = regulator_get_voltage(info->proc_reg); + if (old_vproc < 0) { + pr_err("%s: invalid Vproc value: %d\n", __func__, old_vproc); + return old_vproc; + } freq_hz = freq_table[index].frequency * 1000;