From patchwork Sat Jul 18 06:01:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 51248 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D29F122A28 for ; Sat, 18 Jul 2015 06:01:53 +0000 (UTC) Received: by lbcjf8 with SMTP id jf8sf29709713lbc.0 for ; Fri, 17 Jul 2015 23:01:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=4wGZG+YTo5VZeBfS/Ngh3fmfgNf9OjK/MVgPXOXDS50=; b=Nlc5CeEGGJxyxe+ZQvCrgDogXD3k0Zmf0ncf9us+DAdiFpwUdroly0gWjfrTgSiJZB toFgrcpfhgOYbzYMnArMno5PDWFXLMZ3/e4zZeI5Q522X7Gc2/EMUUVMMy5D78oKafF2 uDRkFa67EYFJtueIv4TRZB3AIwfOS9koNs3IOe3ms8XXE1Ef58jfjygStPrew8+JFJCT P18V2OeCU2owlyiyPYBCxPKUIwk6NFTKq2KBZiCVPEJ11vKk0qavioIR4VUnSU3o/8WO 2ds5OhKVQgGjKm79eJuY4D/fk34hXvauEsm52i8NcRikKjzoKI8/muHccPYiT4ZhYDl4 VBtA== X-Gm-Message-State: ALoCoQk2nXT40Lru0rwmFySsl4NuLXa/nclXwuMI7nNy2CXah3ul+umtcMb0YlA73kV/FbiSTKkt X-Received: by 10.194.2.169 with SMTP id 9mr9443011wjv.2.1437199312859; Fri, 17 Jul 2015 23:01:52 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.30.103 with SMTP id r7ls491536lah.106.gmail; Fri, 17 Jul 2015 23:01:52 -0700 (PDT) X-Received: by 10.152.116.75 with SMTP id ju11mr13669879lab.62.1437199312493; Fri, 17 Jul 2015 23:01:52 -0700 (PDT) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id g10si11663140laf.177.2015.07.17.23.01.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jul 2015 23:01:52 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by lblf12 with SMTP id f12so70924763lbl.2 for ; Fri, 17 Jul 2015 23:01:52 -0700 (PDT) X-Received: by 10.112.133.72 with SMTP id pa8mr17580329lbb.117.1437199312223; Fri, 17 Jul 2015 23:01:52 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp162775lbb; Fri, 17 Jul 2015 23:01:50 -0700 (PDT) X-Received: by 10.66.66.172 with SMTP id g12mr36397596pat.74.1437199309163; Fri, 17 Jul 2015 23:01:49 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sg9si22192475pac.108.2015.07.17.23.01.47; Fri, 17 Jul 2015 23:01:49 -0700 (PDT) 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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755703AbbGRGBe (ORCPT + 12 others); Sat, 18 Jul 2015 02:01:34 -0400 Received: from mail-pa0-f54.google.com ([209.85.220.54]:34252 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755673AbbGRGBc (ORCPT ); Sat, 18 Jul 2015 02:01:32 -0400 Received: by pacan13 with SMTP id an13so71871064pac.1 for ; Fri, 17 Jul 2015 23:01:32 -0700 (PDT) X-Received: by 10.66.221.226 with SMTP id qh2mr37024711pac.64.1437199292200; Fri, 17 Jul 2015 23:01:32 -0700 (PDT) Received: from localhost ([122.171.186.190]) by smtp.gmail.com with ESMTPSA id q5sm13169997pde.56.2015.07.17.23.01.31 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 17 Jul 2015 23:01:31 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, Viresh Kumar , linux-kernel@vger.kernel.org (open list) Subject: [PATCH V3 5/5] cpufreq: propagate errors returned from __cpufreq_governor() Date: Sat, 18 Jul 2015 11:31:03 +0530 Message-Id: X-Mailer: git-send-email 2.4.0 In-Reply-To: References: <2874468.iRvuV1Y9DI@vostro.rjw.lan> In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Return codes aren't honored properly in cpufreq_set_policy(). This can lead to two problems: - wrong errors propagated to sysfs - we try to do next state-change even if the previous one failed cpufreq_governor_dbs() now returns proper errors on all invalid state-transition requests and this code should honor that. Reviewed-and-tested-by: Preeti U Murthy Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index a7b6ac6e048e..a3e8fb61cbcc 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2295,16 +2295,31 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy, old_gov = policy->governor; /* end old governor */ if (old_gov) { - __cpufreq_governor(policy, CPUFREQ_GOV_STOP); + ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP); + if (ret) { + /* This can happen due to race with other operations */ + pr_debug("%s: Failed to Stop Governor: %s (%d)\n", + __func__, old_gov->name, ret); + return ret; + } + up_write(&policy->rwsem); - __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT); + ret = __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT); down_write(&policy->rwsem); + + if (ret) { + pr_err("%s: Failed to Exit Governor: %s (%d)\n", + __func__, old_gov->name, ret); + return ret; + } } /* start new governor */ policy->governor = new_policy->governor; - if (!__cpufreq_governor(policy, CPUFREQ_GOV_POLICY_INIT)) { - if (!__cpufreq_governor(policy, CPUFREQ_GOV_START)) + ret = __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_INIT); + if (!ret) { + ret = __cpufreq_governor(policy, CPUFREQ_GOV_START); + if (!ret) goto out; up_write(&policy->rwsem); @@ -2316,11 +2331,13 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy, pr_debug("starting governor %s failed\n", policy->governor->name); if (old_gov) { policy->governor = old_gov; - __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_INIT); - __cpufreq_governor(policy, CPUFREQ_GOV_START); + if (__cpufreq_governor(policy, CPUFREQ_GOV_POLICY_INIT)) + policy->governor = NULL; + else + __cpufreq_governor(policy, CPUFREQ_GOV_START); } - return -EINVAL; + return ret; out: pr_debug("governor: change or update limits\n");