From patchwork Tue Apr 24 09:39:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10359109 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 1418F601BE for ; Tue, 24 Apr 2018 09:41:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0482828B54 for ; Tue, 24 Apr 2018 09:41:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED5C628D42; Tue, 24 Apr 2018 09:41:39 +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 6F18228B54 for ; Tue, 24 Apr 2018 09:41:39 +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=fbZZMhg+v5lDf2smd50ylCDhOkaTVFs/AzteEQIg44E=; b=sKTGD0ccxBnJuIAWVhCDHRugb1 cH6SFpoMsY+nIg9SJAehDWpUaD6GBKwXgj0e/imqLIZnwUUAIt+pV6yn8JZcyjudBQG8ZGsHg0K8F MeQcQSs2jPfUaJZCJYwAkvScPP9fo7TtO5oz5Kz+LE43lbb+51QyOXso+MzJPTelvrwC6DmqFoSc9 rphwm2SgWz4srwFgXntfTlk6TicfsEUISDN1k3i5KQ89pS+enfKGgfUU6tggJ8mqv0YB1rpFjPXa1 9NdjLbX3nL8bhAia4iqmw4TSw5SVCOu4c13rPKDMKuFsD0WYk7Xw6+Kx1XjH63gcJCyP2wEi3PCm0 vmUoKZeA==; 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 1fAuS5-0002uw-Kx; Tue, 24 Apr 2018 09:41:33 +0000 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fAuQg-00015E-9k for linux-arm-kernel@lists.infradead.org; Tue, 24 Apr 2018 09:40:12 +0000 Received: by mail-pf0-x243.google.com with SMTP id f189so2678058pfa.7 for ; Tue, 24 Apr 2018 02:39:56 -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=U8XkeD5wZ4vKZyjeozXbrNX7G7V2nRsoJevxMxLxH5k=; b=FOggZ88u6TEFvKjRoNQ+M7pRHH9O1XKZuC/6Y3EuuExcvditf+kr8/pFO9+heMQzuQ l6Vi1n5eJmmuJhX3zdWbBJPoFQ6u1cib8CV2Nb7dP/p72oQ5W6NpevYHEFW6OoAebinW pn91xExvfwT4xnvZhDqZibbOQsdwc8wXrQOxM= 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=U8XkeD5wZ4vKZyjeozXbrNX7G7V2nRsoJevxMxLxH5k=; b=YKpAp/amO1nMes70lFaHSpFA25lK/sZ4qa14jKEwZm/oqExmay8yONKl6uTQ/01xZP Wvh1j676mhTqBv6/Z7d84rgwPfvLVf6kdZhFtJbOViK3DI6t5DZcWBPKfF6NINzFLCU9 28Mc+AFUOIt4oeJguLG4S1i3/JTS4yrwyHwImhfGwrhPthXYJh0pT1fkk973jRhRf7c3 WR/M1k6LZQ8woXOb7SlKy0wDoJK2swrUzKwmsYqlvxWKoqY5bQrW1+f8HcB/IhyLP40u b3eRB85P4e0/4eyWjR8U/23pEWqPgG+GwIL31TldpnEDCGGTLi2fICRcuwp9LW9h52MF yCqQ== X-Gm-Message-State: ALQs6tB0Cvv7U7ITuduSAv7aZeq//y7RTrr3q8vGVMBO5j81yVh2ZipA XRJJT1/iIiYyDzOtXqDMYRo0MA== X-Google-Smtp-Source: AIpwx48adW8xv+kaFWkD9oU+rJE0+SzE9+F8+cWa60I4AhjyE87xAyttgA/mm50pHSycNA+kb5T4vA== X-Received: by 2002:a17:902:59ce:: with SMTP id d14-v6mr22583915plj.253.1524562795685; Tue, 24 Apr 2018 02:39:55 -0700 (PDT) Received: from localhost ([122.172.61.40]) by smtp.gmail.com with ESMTPSA id c7sm45188562pfg.81.2018.04.24.02.39.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 02:39:55 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Miquel Raynal , Jason Cooper , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth Subject: [PATCH V3 2/3] cpufreq: armada: Free resources on error paths Date: Tue, 24 Apr 2018 15:09:46 +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-20180424_024006_385344_1B2B765A X-CRM114-Status: GOOD ( 15.74 ) 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 Tested-by: Miquel Raynal --- drivers/cpufreq/armada-37xx-cpufreq.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/cpufreq/armada-37xx-cpufreq.c b/drivers/cpufreq/armada-37xx-cpufreq.c index 72a2975499db..1d5db6f6ace9 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; @@ -207,33 +208,43 @@ static int __init armada37xx_cpufreq_driver_init(void) } dvfs = armada_37xx_cpu_freq_info_get(cur_frequency); - if (!dvfs) + if (!dvfs) { + clk_put(clk); return -EINVAL; + } 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; + +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); + } - return PTR_ERR_OR_ZERO(pdev); + return ret; } /* late_initcall, to guarantee the driver is loaded after A37xx clock driver */ late_initcall(armada37xx_cpufreq_driver_init);