From patchwork Tue Apr 24 06:07:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10358685 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 91A31601BE for ; Tue, 24 Apr 2018 06:09:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F91428B8C for ; Tue, 24 Apr 2018 06:09:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7245228BDA; Tue, 24 Apr 2018 06:09:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ED97228B8C for ; Tue, 24 Apr 2018 06:09:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=5FlOpORS6lf9Hd6DslISHgUTQQGimrURzzV2QCyxjyg=; b=ihAJngq5pMXHyzAigo0yDC6jK0 MGHfAri/WJ5VOnxqEYB9ghkZWrj3N1/s/BnlAwcz2HNidXflVaJx8TbvEYQcRTKfV9jkJ+G/+CPRE vo1jeGopHdGPrNTlg6bfVwhA6zdvEvAlGOiQU/2p+zpAM8DQJbhwdwu89Nwr4JmI8yjZKU+cw/DpD H80Hk94GWXES7ZrrGYwIhj4LAgT0kO6+Tj8NQ2poVCWnX/K75R2EJN4wI5ilT3GQgWbp7GijO6fUQ bSgBrCR/3m5DXofC84Tl97Lqm03ndPLNdmppqLdUPBOnUyUl1rPR7PB4+6q6jBF9mfGRoXk498N2k sLUcpKrQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fAr8a-0004Mq-Gj; Tue, 24 Apr 2018 06:09:12 +0000 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fAr83-00042e-1X for linux-arm-kernel@lists.infradead.org; Tue, 24 Apr 2018 06:08:40 +0000 Received: by mail-pf0-x244.google.com with SMTP id g14so11357179pfh.3 for ; Mon, 23 Apr 2018 23:08:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=z3umFelSZyo4/s2aIJrG7pE6wGW7GPFzfnER4DGATgg=; b=VIKCf1AR5xv8xlDyyrm5fW8U9WomwcJ2O9oBLeDk/LlQeCIW882SBD+Gf8W1Fk8E1R oNgMbFWebUXidcDY2FhIlo1eJ28L2pifiNU8fPpLTuCBOZQ28bTbWSXtJfPr8yNZQk31 r88oERAtyJcoEY3S0crqKt0JD3t3eGWMysIfE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=z3umFelSZyo4/s2aIJrG7pE6wGW7GPFzfnER4DGATgg=; b=emCvAgoNtf70LwvhfUPMkcYnV9FuC2ggy29CVgfUxgzQixLP6DO0b2dGgtUAZjy9zF oB28AG8t5kxtzanhQ03tMCjs7qvS3VmbnkZcAh8V1myXSUJRj2VoC5rJPAHVjJnu+2if TL7d2tPFYrCGqV4JU3pEJCFZn+e2awGIlGv8Oo9jYmRceUxjiHrpM6EpdaQiRBWu4R6I sj+nbmHWX7HRtkE/9QN0Wlr/+xxtTwIbpU86dnHE0H8h6U2u7V0kYH9kEtWnHa888ACo avCmJ5aSazqy2cvEXka/IZkX4mWgOPSgzQ+Gq0csLoHu4SD4/nGMWxRvbyZK7JNLN7PH pd7w== X-Gm-Message-State: ALQs6tDRilxM1UJcS8CP39tliKxlMBGGTBr9XD2pwPh3BvNnSnobzRFh eUJhFI3U3ovmvpDpAxg8H2G5iQ== X-Google-Smtp-Source: AIpwx48DxYRjZvcieJFH9hHWcn8TA944YTFy6FYfeAB6A5kgMtkBgkY6sNq07YDQTkt160LJ79r7Mg== X-Received: by 2002:a17:902:5ac1:: with SMTP id g1-v6mr11242228plm.43.1524550108118; Mon, 23 Apr 2018 23:08:28 -0700 (PDT) Received: from localhost ([122.172.61.40]) by smtp.gmail.com with ESMTPSA id o64sm25774195pfb.62.2018.04.23.23.08.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Apr 2018 23:08:27 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Miquel Raynal , Jason Cooper , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth Subject: [PATCH 2/3] cpufreq: armada: Free resources on error paths Date: Tue, 24 Apr 2018 11:37:35 +0530 Message-Id: X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180423_230839_154364_E4C283C0 X-CRM114-Status: GOOD ( 14.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Viresh Kumar , Vincent Guittot , linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The resources weren't freed on failures, free them properly. Signed-off-by: Viresh Kumar --- drivers/cpufreq/armada-37xx-cpufreq.c | 40 +++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/drivers/cpufreq/armada-37xx-cpufreq.c b/drivers/cpufreq/armada-37xx-cpufreq.c index 72a2975499db..9dafb3bbc334 100644 --- a/drivers/cpufreq/armada-37xx-cpufreq.c +++ b/drivers/cpufreq/armada-37xx-cpufreq.c @@ -166,6 +166,7 @@ static int __init armada37xx_cpufreq_driver_init(void) { struct armada_37xx_dvfs *dvfs; struct platform_device *pdev; + unsigned long freq; unsigned int cur_frequency; struct regmap *nb_pm_base; struct device *cpu_dev; @@ -202,38 +203,49 @@ static int __init armada37xx_cpufreq_driver_init(void) cur_frequency = clk_get_rate(clk); if (!cur_frequency) { dev_err(cpu_dev, "Failed to get clock rate for CPU\n"); - clk_put(clk); - return -EINVAL; + ret = -EINVAL; + goto put_clk; } dvfs = armada_37xx_cpu_freq_info_get(cur_frequency); - if (!dvfs) - return -EINVAL; + if (!dvfs) { + ret = -EINVAL; + goto put_clk; + } armada37xx_cpufreq_dvfs_setup(nb_pm_base, clk, dvfs->divider); clk_put(clk); for (load_lvl = ARMADA_37XX_DVFS_LOAD_0; load_lvl < LOAD_LEVEL_NR; load_lvl++) { - unsigned long freq = cur_frequency / dvfs->divider[load_lvl]; + freq = cur_frequency / dvfs->divider[load_lvl]; ret = dev_pm_opp_add(cpu_dev, freq, 0); - if (ret) { - /* clean-up the already added opp before leaving */ - while (load_lvl-- > ARMADA_37XX_DVFS_LOAD_0) { - freq = cur_frequency / dvfs->divider[load_lvl]; - dev_pm_opp_remove(cpu_dev, freq); - } - return ret; - } + if (ret) + goto remove_opp; } /* Now that everything is setup, enable the DVFS at hardware level */ armada37xx_cpufreq_enable_dvfs(nb_pm_base); pdev = platform_device_register_simple("cpufreq-dt", -1, NULL, 0); + ret = PTR_ERR_OR_ZERO(pdev); + if (ret) + goto disable_dvfs; + + return 0; - return PTR_ERR_OR_ZERO(pdev); +disable_dvfs: + armada37xx_cpufreq_disable_dvfs(nb_pm_base); +remove_opp: + /* clean-up the already added opp before leaving */ + while (load_lvl-- > ARMADA_37XX_DVFS_LOAD_0) { + freq = cur_frequency / dvfs->divider[load_lvl]; + dev_pm_opp_remove(cpu_dev, freq); + } +put_clk: + clk_put(clk); + return ret; } /* late_initcall, to guarantee the driver is loaded after A37xx clock driver */ late_initcall(armada37xx_cpufreq_driver_init);