From patchwork Wed Feb 27 10:04:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10831497 X-Patchwork-Delegate: viresh.linux@gmail.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 42763139A for ; Wed, 27 Feb 2019 10:04:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 220052AF68 for ; Wed, 27 Feb 2019 10:04:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 156632B83B; Wed, 27 Feb 2019 10:04:54 +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 93A112AF68 for ; Wed, 27 Feb 2019 10:04:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725983AbfB0KEs (ORCPT ); Wed, 27 Feb 2019 05:04:48 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:32972 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726807AbfB0KEr (ORCPT ); Wed, 27 Feb 2019 05:04:47 -0500 Received: by mail-pl1-f195.google.com with SMTP id y10so7801024plp.0 for ; Wed, 27 Feb 2019 02:04:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Zg0+GNn7Z6P9rpnhFL7IPuLh6JHfTMBGrvRxKokx2eg=; b=DoIanckoA0erRA0PrlnqWrq/AlZ2MR2T5dT4KJ1uwAxKjqAMMvCAyXZgqOa39Q8+Ku wvLF37wKlTMWykM2z8Mdizume3X79EjM7DYWseNCBbAQ7BsS4TANbBOP+QuQyl5D780R x1HWQlaa5kYCfd0PtTumQPUZR25ew2mWxJzfXIggKYBe+pxVIrsdZVHsVbfJS6hNR7kg KwCiH8y8ftEsxYCtv6OmgAm5BnERmJKSRLkCpdvAOI9DejMKEflD6pHCAupWfxfFR55A /ijfJbTbv79fGyZz9RoX4BDkqhB12vmRtCo4KUrydywmEHjkkjxOMggKpPLHkzqo0P6y NpPw== 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:mime-version :content-transfer-encoding; bh=Zg0+GNn7Z6P9rpnhFL7IPuLh6JHfTMBGrvRxKokx2eg=; b=bQTxqhH5pdnYpgTd8dvG7pGWtznOiKoTscBCWo+s+6vnJOesFPivtbENBrZpUWCfHZ AO6bB00k1hRupYfwHhqI6NQNBhzjGL3fiXzSG+KaYLo1rgHGu1bfxGFYKlYWnLQK+gR7 VkngLbtIj9vFqHFkaIbbUdNafIL/YlQRhHrx7+AUNStHXEJc7TZlI84SZSPxs5goxTAc gJv+2HXLuWqWF5v01JRKTis/WHnAj7PABZfinJ+NqE93CjJk6PBQRzheWI6iXh85ACvb VR4KgM/16tu6Tqpx7h1BLsh6WnklXnpPTPZE4h4nd/rZqMfgEEIp/jhRIv1fX9H8+bIg cYFA== X-Gm-Message-State: AHQUAuaZjrInrwxFYyPkMWJz9jd/i9CYrBi/Enoh/Z9EPG3H4xuLOJaq Sk+2/XCEgaaShFQhK6cjSoiPDg== X-Google-Smtp-Source: AHgI3IaUArMmcXyIfHpin3HkAYvncnr9y/5I5YYKQADUQgTBOif1B4Pni2WF/b2Uhvw54WvJAS2Fjg== X-Received: by 2002:a17:902:8690:: with SMTP id g16mr1285258plo.284.1551261886367; Wed, 27 Feb 2019 02:04:46 -0800 (PST) Received: from localhost ([122.167.168.92]) by smtp.gmail.com with ESMTPSA id v4sm12051216pff.181.2019.02.27.02.04.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Feb 2019 02:04:45 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , Ilia Lin Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Arnd Bergmann , amit.kucheria@linaro.org, "4 . 18+" , linux-kernel@vger.kernel.org Subject: [PATCH V2] cpufreq: kyro: Release OPP tables on module removal Date: Wed, 27 Feb 2019 15:34:27 +0530 Message-Id: <78f96969448b17e95b0b21cb78194bb9f709a897.1551261748.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b MIME-Version: 1.0 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 Commit 5ad7346b4ae2 ("cpufreq: kryo: Add module remove and exit") made it possible to build the kyro cpufreq driver as a module, but it failed to release all the resources, i.e. OPP tables, when the module is unloaded. This patch fixes it by releasing the OPP tables, by calling dev_pm_opp_put_supported_hw() for them, from the qcom_cpufreq_kryo_remove() routine. The array of pointers to the OPP tables is also allocated dynamically now in qcom_cpufreq_kryo_probe(), as the pointers will be required while releasing the resources. Compile tested only. Cc: 4.18+ # v4.18+ Fixes: 5ad7346b4ae2 ("cpufreq: kryo: Add module remove and exit") Signed-off-by: Viresh Kumar Reviewed-by: Georgi Djakov --- V1->V2: - The previous version targeted a compile time issue of frame size but this fixes a bug in the driver and needs to get applied to 4.18+ kernels. - This may go in 5.0 release. - Haven't included any Reviewed-by tags as there were many changes in this version. drivers/cpufreq/qcom-cpufreq-kryo.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/qcom-cpufreq-kryo.c b/drivers/cpufreq/qcom-cpufreq-kryo.c index 2a3675c24032..65edbfd4d4a5 100644 --- a/drivers/cpufreq/qcom-cpufreq-kryo.c +++ b/drivers/cpufreq/qcom-cpufreq-kryo.c @@ -75,7 +75,7 @@ static enum _msm8996_version qcom_cpufreq_kryo_get_msm_id(void) static int qcom_cpufreq_kryo_probe(struct platform_device *pdev) { - struct opp_table *opp_tables[NR_CPUS] = {0}; + struct opp_table **opp_tables; enum _msm8996_version msm8996_version; struct nvmem_cell *speedbin_nvmem; struct device_node *np; @@ -133,6 +133,10 @@ static int qcom_cpufreq_kryo_probe(struct platform_device *pdev) } kfree(speedbin); + opp_tables = kcalloc(num_possible_cpus(), sizeof(*opp_tables), GFP_KERNEL); + if (!opp_tables) + return -ENOMEM; + for_each_possible_cpu(cpu) { cpu_dev = get_cpu_device(cpu); if (NULL == cpu_dev) { @@ -151,8 +155,10 @@ static int qcom_cpufreq_kryo_probe(struct platform_device *pdev) cpufreq_dt_pdev = platform_device_register_simple("cpufreq-dt", -1, NULL, 0); - if (!IS_ERR(cpufreq_dt_pdev)) + if (!IS_ERR(cpufreq_dt_pdev)) { + platform_set_drvdata(pdev, opp_tables); return 0; + } ret = PTR_ERR(cpufreq_dt_pdev); dev_err(cpu_dev, "Failed to register platform device\n"); @@ -163,13 +169,23 @@ static int qcom_cpufreq_kryo_probe(struct platform_device *pdev) break; dev_pm_opp_put_supported_hw(opp_tables[cpu]); } + kfree(opp_tables); return ret; } static int qcom_cpufreq_kryo_remove(struct platform_device *pdev) { + struct opp_table **opp_tables = platform_get_drvdata(pdev); + unsigned cpu; + platform_device_unregister(cpufreq_dt_pdev); + + for_each_possible_cpu(cpu) + dev_pm_opp_put_supported_hw(opp_tables[cpu]); + + kfree(opp_tables); + return 0; }