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: 10359103 X-Patchwork-Delegate: rjw@sisk.pl 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 D9609601BE for ; Tue, 24 Apr 2018 09:39:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C9C2128D0E for ; Tue, 24 Apr 2018 09:39:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC5ED28D50; Tue, 24 Apr 2018 09:39:58 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 374BF28D0E for ; Tue, 24 Apr 2018 09:39:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752949AbeDXJj5 (ORCPT ); Tue, 24 Apr 2018 05:39:57 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:39366 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752549AbeDXJj4 (ORCPT ); Tue, 24 Apr 2018 05:39:56 -0400 Received: by mail-pf0-f194.google.com with SMTP id z9so11789734pfe.6 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=NfD95XNKmDzynwDfwgyxuyDGnhTm6CFr42VkAxhpbRgyuClfaqwWS/nhSSDW+AjxR/ JTzeAo2LVQgNpgPy0nOUABd3sw/HHzD5XYtldVji/A0lMMcaNFJJJtYyg+0GtxpY8H+1 3Kj1c5w+R5f6vgo8wk3XjBOR02t1RE5bufnmmDPjDe/M0501hhL1E890DXyGpJb8u6rE YJARn9UeUw0r5Sg0PS6EU6s+ijhoRig0MlssK5GG8hnHpoNzBxfXYgVzXo2w203nquns QiBornO6HXaEfxdD+PJHpi/J7ItBz68NQTQUR5FENDR32YB69HqgBn70Xyq/YSJXyQBd 1/1w== X-Gm-Message-State: ALQs6tCNfXSuUheOdB+I4zX9lyvfnaPeSVC3Gblip0aVx+2f5q9erVLg ZT/ZD77HTd+Iz3TL0rMKDGocSA== 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 Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , linux-arm-kernel@lists.infradead.org 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: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.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);