From patchwork Wed Jul 8 09:42:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 50861 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BAC42213FD for ; Wed, 8 Jul 2015 09:42:55 +0000 (UTC) Received: by lagc2 with SMTP id c2sf20510706lag.0 for ; Wed, 08 Jul 2015 02:42:54 -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=SxR7+y3nExvNb1ihTZ2jmaBKS1p4pWa5T/74Ah+xwG4=; b=M9nFNnq1XXIkuPrhCTqVzwituuGH1kQZg8pCf03fPc27Wk5Y+VV8mdiqTjkPAMCtwD Hw0qbb4+wWLvtyZueM5GBAO+xViACDNnP7pOYXt65m6zxEjBgKi9hkeXVncPzOUOMOzf FLnrC/xIkA4VHoR/NkFx76sHKJ4wXQZxFgJKndqVWatldh7wkwWD/tfmXw76xTaNjJcX M3tZAjkTHrc5nE5R8H7oA8kCcZ3oo9sui9K7DEPIgQzCN2zfrx7H7bRhj5/O+b/G0ocF lhEDeDgz2g08/lY+1ZUmBI8lKe/7CLlQNGSLVmsacBuqp8ipZ8DgGBKxL7UIpNfdJvbd 3QKw== X-Gm-Message-State: ALoCoQmyJgIA6p9vPTJtl7bkINy+ISfDaP/dW+8SJsQivAuVnfnjigQVmMZfRA1IKSAFyjAlarR4 X-Received: by 10.152.88.70 with SMTP id be6mr4382222lab.9.1436348574696; Wed, 08 Jul 2015 02:42:54 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.205.6 with SMTP id lc6ls932605lac.80.gmail; Wed, 08 Jul 2015 02:42:54 -0700 (PDT) X-Received: by 10.112.52.2 with SMTP id p2mr8469130lbo.8.1436348574418; Wed, 08 Jul 2015 02:42:54 -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 ec8si1485404lbb.68.2015.07.08.02.42.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Jul 2015 02:42:54 -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 lbcpe5 with SMTP id pe5so52492074lbc.2 for ; Wed, 08 Jul 2015 02:42:54 -0700 (PDT) X-Received: by 10.112.234.200 with SMTP id ug8mr8370530lbc.117.1436348574314; Wed, 08 Jul 2015 02:42:54 -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 hn6csp2956288lbb; Wed, 8 Jul 2015 02:42:53 -0700 (PDT) X-Received: by 10.70.42.101 with SMTP id n5mr18876133pdl.93.1436348569972; Wed, 08 Jul 2015 02:42:49 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sl6si3163277pac.192.2015.07.08.02.42.49; Wed, 08 Jul 2015 02:42: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 S934639AbbGHJmj (ORCPT + 11 others); Wed, 8 Jul 2015 05:42:39 -0400 Received: from mail-pd0-f176.google.com ([209.85.192.176]:35793 "EHLO mail-pd0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934620AbbGHJme (ORCPT ); Wed, 8 Jul 2015 05:42:34 -0400 Received: by pdrg1 with SMTP id g1so11451861pdr.2 for ; Wed, 08 Jul 2015 02:42:34 -0700 (PDT) X-Received: by 10.66.66.172 with SMTP id g12mr18732269pat.74.1436348554162; Wed, 08 Jul 2015 02:42:34 -0700 (PDT) Received: from localhost ([122.171.186.190]) by smtp.gmail.com with ESMTPSA id tr2sm1854005pab.33.2015.07.08.02.42.32 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 08 Jul 2015 02:42:33 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , tixy@linaro.org Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, Viresh Kumar , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 2/2] cpufreq: Properly handle errors from cpufreq_init_policy() Date: Wed, 8 Jul 2015 15:12:16 +0530 Message-Id: <043703bd1914d52340653c3cc31207e505df6139.1436348436.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.4.0 In-Reply-To: <276debea91831d86c34079f6a40d773ce258a62c.1436348436.git.viresh.kumar@linaro.org> References: <276debea91831d86c34079f6a40d773ce258a62c.1436348436.git.viresh.kumar@linaro.org> In-Reply-To: <276debea91831d86c34079f6a40d773ce258a62c.1436348436.git.viresh.kumar@linaro.org> References: <276debea91831d86c34079f6a40d773ce258a62c.1436348436.git.viresh.kumar@linaro.org> 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: , cpufreq_init_policy() can fail, and we don't do anything except a call to ->exit() on that. The policy should be freed if this happens. Lets do it properly. Reported-by: "Jon Medhurst (Tixy)" Signed-off-by: Viresh Kumar Tested-by: Jon Medhurst --- drivers/cpufreq/cpufreq.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index b7aac8eec525..006299214d2e 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1051,11 +1051,10 @@ static int cpufreq_add_dev_interface(struct cpufreq_policy *policy, return cpufreq_add_dev_symlink(policy); } -static void cpufreq_init_policy(struct cpufreq_policy *policy) +static int cpufreq_init_policy(struct cpufreq_policy *policy) { struct cpufreq_governor *gov = NULL; struct cpufreq_policy new_policy; - int ret = 0; memcpy(&new_policy, policy, sizeof(*policy)); @@ -1074,12 +1073,7 @@ static void cpufreq_init_policy(struct cpufreq_policy *policy) cpufreq_parse_governor(gov->name, &new_policy.policy, NULL); /* set default policy */ - ret = cpufreq_set_policy(policy, &new_policy); - if (ret) { - pr_debug("setting policy failed\n"); - if (cpufreq_driver->exit) - cpufreq_driver->exit(policy); - } + return cpufreq_set_policy(policy, &new_policy); } static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, @@ -1376,7 +1370,12 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) write_unlock_irqrestore(&cpufreq_driver_lock, flags); } - cpufreq_init_policy(policy); + ret = cpufreq_init_policy(policy); + if (ret) { + pr_err("%s: Failed to initialize policy for cpu: %d (%d)\n", + __func__, cpu, ret); + goto out_remove_policy_notify; + } if (!recover_policy) { policy->user_policy.policy = policy->policy; @@ -1396,6 +1395,9 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) return 0; +out_remove_policy_notify: + /* cpufreq_policy_free() will notify based on this */ + recover_policy = true; out_exit_policy: up_write(&policy->rwsem);