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: 134059 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2011080lji; Tue, 24 Apr 2018 02:39:58 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+gLajV6DU3dABvaDskZM6X4Jat2hGbUtW4Mm4pwW05Pb33zD42h8XBqnJUowtDhmohLotb X-Received: by 2002:a17:902:70c4:: with SMTP id l4-v6mr24007814plt.382.1524562798427; Tue, 24 Apr 2018 02:39:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524562798; cv=none; d=google.com; s=arc-20160816; b=SVu3K2SZpd598Suc4E5lCJiJYqu00UmVpDnGL+A5rE4xRzKJzBXr0XEMWvOps7b7Bj VtkhQ0KyTGTJ3QcXR19Cuzn6bj/DfWs/0Tsa62EfUY82Ff05yBOCRY2SADLjBo6vixnZ NYcAmRKJnrOxP5cCra6GMIVPJpJYDh57mjWkyTNry+lhi+0ZlSxsbhVcllZAsSr4wgYu 5thzrMsBaH/IxpNkCJtoBQ+VprWxvmPGpZQgxP4XcbE4gukB0NTdDE0QCGEbN4SLTVdc ljPUtDfa0RQaQ6EJPZKeZE+up7DNCFgdgMA6DOhoyb1PUzRd5I+ycB+BnRKiQiEGukrX XEWQ== 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=U8XkeD5wZ4vKZyjeozXbrNX7G7V2nRsoJevxMxLxH5k=; b=QmpbLF98+qjborhmfzkaLqrTTZyt75QwvsEn6b0jUD3i3SM+vBQDxkZEva9tNG1lRu 2MAomnysXMpBYq9ki5tq+8KEpkvTQ0MUNC8egZITxgtda6GmQ9lqq1N5ufzbxAi17ecR gQpxkmeR7yBpDiuLWtFiTgVo9xEfMIXFgb5lhmQOoaQ2iY+CGe3kPhOEhO5DtL6GfN6+ elAmlKVnWApQJ3d+ouvtvrEhDlqXcURa/uwOYKaQ9kGtyvLADI1zYfIyKVBy9ZeZ0DoT M9TdkgZYg3f3tijXOl2d7k/+wfZwi9y1YRywshLMYLWTfXX4QcPE6ud2/rfnxC7ngt76 zZJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FOggZ88u; 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 m18si11109785pgu.352.2018.04.24.02.39.58; Tue, 24 Apr 2018 02:39:58 -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=FOggZ88u; 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 S1752949AbeDXJj5 (ORCPT + 11 others); 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-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 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(-) -- 2.15.0.194.g9af6a3dea062 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);