From patchwork Tue Aug 6 17:23:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 18814 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-gh0-f198.google.com (mail-gh0-f198.google.com [209.85.160.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F2B4F25DF6 for ; Tue, 6 Aug 2013 17:24:59 +0000 (UTC) Received: by mail-gh0-f198.google.com with SMTP id r13sf724276ghr.1 for ; Tue, 06 Aug 2013 10:24:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-gm-message-state:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=2/yN7v4I0cAwOfzito1K4JhdX2+iindGq2v+jfBe8dE=; b=n8lZqwg9aBhlO65msAA0NR39HrFKFqxUGC4Nla4PxDuoCUYKqggbfFT80F4mvIjfgw gg0xRyaBK3FfeWS/1vjU5WvCrUZGgb3Mds9mxSgBETLpQGGd4HINwRzHfoG2Ta1s4eWO vDYwNU1joBSRFX8L4Z9vC9Z2/1qHCnXrRZkST4k20+GvYy4swLa1oLJFFeWBVRo1wSH6 CyWsodK7D9zOur7TI4IH2cjz2qsOAb2Cpc6kSzEjVnPBEVPyRYBGj7T9TEwo2hL1SVVW 2PhfOsbwKY+isrlMu64zvYbroHF0IKWKg0ZDoIe7FgzcJstn2b/Y7zYVtdz8SUGBxOw/ 97zw== X-Received: by 10.236.148.33 with SMTP id u21mr799373yhj.37.1375809899756; Tue, 06 Aug 2013 10:24:59 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.35.10 with SMTP id d10ls348311qej.19.gmail; Tue, 06 Aug 2013 10:24:59 -0700 (PDT) X-Received: by 10.59.8.232 with SMTP id dn8mr737576ved.8.1375809899623; Tue, 06 Aug 2013 10:24:59 -0700 (PDT) Received: from mail-ve0-f180.google.com (mail-ve0-f180.google.com [209.85.128.180]) by mx.google.com with ESMTPS id aw7si541151vec.12.2013.08.06.10.24.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 06 Aug 2013 10:24:59 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.180 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.180; Received: by mail-ve0-f180.google.com with SMTP id pb11so705637veb.25 for ; Tue, 06 Aug 2013 10:24:59 -0700 (PDT) X-Gm-Message-State: ALoCoQlD4lM6N2avlb0iLTEGzTDjSPlBXP0fZ2j1FaPvX1wybojBvVZKqbI3zQUEYq8Q2+MuUQUC X-Received: by 10.52.164.16 with SMTP id ym16mr592571vdb.32.1375809899491; Tue, 06 Aug 2013 10:24:59 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.11.8 with SMTP id pc8csp157213vcb; Tue, 6 Aug 2013 10:24:59 -0700 (PDT) X-Received: by 10.68.212.229 with SMTP id nn5mr2779357pbc.44.1375809898597; Tue, 06 Aug 2013 10:24:58 -0700 (PDT) Received: from mail-pb0-f54.google.com (mail-pb0-f54.google.com [209.85.160.54]) by mx.google.com with ESMTPS id x6si3058363pab.339.2013.08.06.10.24.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 06 Aug 2013 10:24:58 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.54 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=209.85.160.54; Received: by mail-pb0-f54.google.com with SMTP id ro12so729677pbb.41 for ; Tue, 06 Aug 2013 10:24:58 -0700 (PDT) X-Received: by 10.68.103.131 with SMTP id fw3mr2734404pbb.65.1375809898121; Tue, 06 Aug 2013 10:24:58 -0700 (PDT) Received: from localhost ([122.172.193.46]) by mx.google.com with ESMTPSA id nj9sm3141046pbc.13.2013.08.06.10.24.53 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 06 Aug 2013 10:24:57 -0700 (PDT) From: Viresh Kumar To: rjw@sisk.pl Cc: linaro-kernel@lists.linaro.org, patches@linaro.org, cpufreq@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, srivatsa.bhat@linux.vnet.ibm.com, Viresh Kumar Subject: [PATCH V2 11/11] cpufreq: improve error checking on return values of __cpufreq_governor() Date: Tue, 6 Aug 2013 22:53:13 +0530 Message-Id: <16cf42ac264fc8d0e7604807b01ae796ad6a77c0.1375809311.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: References: In-Reply-To: References: X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.180 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , __cpufreq_governor() function can fail in rare cases specially if there are bugs in cpufreq driver. And so we must stop processing as soon as this routine fails, otherwise it may result in undefined behavior. And so this patch adds error checking code whenever this routine is called from any place. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 48 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index ccaf025..06f8671 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -874,8 +874,13 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, int ret = 0, has_target = !!cpufreq_driver->target; unsigned long flags; - if (has_target) - __cpufreq_governor(policy, CPUFREQ_GOV_STOP); + if (has_target) { + ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP); + if (ret) { + pr_err("%s: Failed to stop governor\n", __func__); + return ret; + } + } lock_policy_rwsem_write(policy->cpu); @@ -889,8 +894,11 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unlock_policy_rwsem_write(policy->cpu); if (has_target) { - __cpufreq_governor(policy, CPUFREQ_GOV_START); - __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS); + if ((ret = __cpufreq_governor(policy, CPUFREQ_GOV_START)) || + (ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS))) { + pr_err("%s: Failed to start governor\n", __func__); + return ret; + } } /* Don't touch sysfs links during light-weight init */ @@ -1171,7 +1179,7 @@ static int __cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif, bool frozen) { unsigned int cpu = dev->id, cpus; - int new_cpu; + int new_cpu, ret; unsigned long flags; struct cpufreq_policy *policy; struct kobject *kobj; @@ -1195,8 +1203,13 @@ static int __cpufreq_remove_dev(struct device *dev, return -EINVAL; } - if (cpufreq_driver->target) - __cpufreq_governor(policy, CPUFREQ_GOV_STOP); + if (cpufreq_driver->target) { + ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP); + if (ret) { + pr_err("%s: Failed to stop governor\n", __func__); + return ret; + } + } #ifdef CONFIG_HOTPLUG_CPU if (!cpufreq_driver->setpolicy) @@ -1230,8 +1243,15 @@ static int __cpufreq_remove_dev(struct device *dev, /* If cpu is last user of policy, free policy */ if (cpus == 1) { - if (cpufreq_driver->target) - __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT); + if (cpufreq_driver->target) { + ret = __cpufreq_governor(policy, + CPUFREQ_GOV_POLICY_EXIT); + if (ret) { + pr_err("%s: Failed to exit governor\n", + __func__); + return ret; + } + } if (!frozen) { lock_policy_rwsem_read(cpu); @@ -1262,8 +1282,12 @@ static int __cpufreq_remove_dev(struct device *dev, cpufreq_policy_free(policy); } else { if (cpufreq_driver->target) { - __cpufreq_governor(policy, CPUFREQ_GOV_START); - __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS); + if ((ret = __cpufreq_governor(policy, CPUFREQ_GOV_START)) || + (ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS))) { + pr_err("%s: Failed to start governor\n", + __func__); + return ret; + } } } @@ -1911,7 +1935,7 @@ static int __cpufreq_set_policy(struct cpufreq_policy *policy, /* might be a policy change, too, so fall through */ } pr_debug("governor: change or update limits\n"); - __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS); + ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS); } error_out: