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: 134053 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1845192lji; Mon, 23 Apr 2018 23:08:30 -0700 (PDT) X-Google-Smtp-Source: AIpwx491EmFgxxz6wrol0SmO8JwS0mnshja0i60LwME60Z1gMKnKAH35gWC0apbKTwNz0+oEG7H+ X-Received: by 2002:a17:902:9a44:: with SMTP id x4-v6mr24154758plv.312.1524550110024; Mon, 23 Apr 2018 23:08:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524550110; cv=none; d=google.com; s=arc-20160816; b=dMll9SXEdEkMFYDp4mYT6GOe/iDWQ5e0biQWU6kIX+z76pw4n0UHx78INuAkltK8HB vuaanrQPpurqCUmDriCi+NAsS5hbudSMRUh+FAd9t6u38uJ36QOUv9gtG0Z4BPO+b/FZ PgWKEzkrCetyIerl0dsF9PACJWcM4aVlLgyUpLHJ6jT1ei/w8Ip+JbMVfnFHAFpen30i oJTVXOy/5ODMvKel1/wXv5BsngTfsMr7Ogxwpv1dBwgens/RxjatyIVU17BYR1fgGCjR BecSRN3/hJ2YHoBaMP545/xpUkUiB2QDkaL+miw19fqFKNf7UdLbIMudQBbPzhlCYMRh yn2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=z3umFelSZyo4/s2aIJrG7pE6wGW7GPFzfnER4DGATgg=; b=LSc1f52RWyaXjsmGQjSUQJJPClcBxFISoOl0tmFo4MnN1mbY3IwtMVi2wNSLfEVy7t fXosaZVyh1jiNYGx8rByj3UuJnjaOFt9kJWnGq4h5LYawBjYhibWzE74gmo5HZQeuLAN SqszmCa+R4vaW1QtKS7qETFUNtMbL+Z9eYtC/eU6txi2uhBfIs9h4ptooTinaux6Rnml ZiOl+o4BSxBeu4aeuzX20ISJAJGMZho+ZysN+A2C+stCKNokLnuposmsw+R+l29/EN1h VyxaB+JlYcyYUpFkt1bYOy4LNOrSnyRjYSc+efW7TM2TvTdyZkDVp37uriUbOu43HfwW MwWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VIKCf1AR; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y5si12475283pfe.184.2018.04.23.23.08.29; Mon, 23 Apr 2018 23:08:30 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VIKCf1AR; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756214AbeDXGI3 (ORCPT + 11 others); Tue, 24 Apr 2018 02:08:29 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:44279 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756208AbeDXGI2 (ORCPT ); Tue, 24 Apr 2018 02:08:28 -0400 Received: by mail-pf0-f194.google.com with SMTP id p15so11347898pff.11 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=RPfEpaaRT5xapimlxTnb5mCBBu/S34+StxSYLjVGXGkdI0qtuZ32RhGzDPLFEHMc9p o/3SrnpaQfPndFj83GrHEtvok2vGgYuVzbTYcU0UfScSdLPELZYoIGdrLaHwaG3a/J46 oU/MvzZ/SIrrFq91/x1LbXMXg7jOuMLEUPMa6t8mKsTTiWdLHFBWAhWn9UAxxg6tu367 REpuXtfM3hep2pGy6WSAMGpo5sOgYPCoIFNKlQVgeYI8xUTW+KdOobRmf35FgWNxVP02 7wekEdVJ80Yu7chAa2aJVknen0OWp3CCbcdipXqEBmBOv53vM3r6wUxEczVonTxYz+ot n0rQ== X-Gm-Message-State: ALQs6tCeHEm7YSH0oK2S1JrHdSLrhLrCuCgso0T3/3zWJahaS1G3MiZG RPFThF0L/egO6L2nRszjdNQeGQ== 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 Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , linux-arm-kernel@lists.infradead.org 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: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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(-) -- 2.15.0.194.g9af6a3dea062 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);