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: 6743361 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E33C79F2F0 for ; Wed, 8 Jul 2015 09:42:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1531E2060D for ; Wed, 8 Jul 2015 09:42:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8A9F5205AA for ; Wed, 8 Jul 2015 09:42:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934639AbbGHJmj (ORCPT ); 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-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:in-reply-to:references; bh=75jmG9+n65vJpdKwOPJlcn/IIR2D7/3bi4Lr9H55Lv0=; b=OMsy1PzHcbj0mxo98GqJaZuzCC/LGOdwqGf2xpT9Jjhb5Voxbz3Fe0LYrzEiH/LnHM jdvYmolpOD7Gn56S+amEI5XnIy2WmD5PTDVsrJi1dJFD4j6+jHi/EQMj7OYYb3y6YxWZ ZpxTxyk7/pbGmooHpTykY8YzKJl5Rmbd89wYVYYPUJHTi2EgjG9C81Sau4ifuL5UXcKl Mno3LhNRbjOVBjqITzYV44FPSREVbEFBi/Ip4GgfatYMtwlVdOJBhUXocTuNvE+Yt2YL rco946j6MTMZLULiTr4FICkDPehvWtnV8iGlGpD4qHs1WGI49DzJtZiX0JFgjF0sFKtX P79A== X-Gm-Message-State: ALoCoQlYJU7/SiROVcjGnivmiug8oBFhn1favc1FvjjtOU3bzPNjZ5jkDpYfC+qXszgrWrqyPn3/ 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: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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);