Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp1240913iol; Fri, 10 Jun 2022 03:26:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfIqXy9pspyb87cWNvUVWU+QP0xZYtkOhJHE/8/zRS925nUhC4GoEjbUi3Mf4RJz/0jU/E X-Received: by 2002:a17:906:5d0d:b0:711:d49f:e353 with SMTP id g13-20020a1709065d0d00b00711d49fe353mr22340791ejt.381.1654856763042; Fri, 10 Jun 2022 03:26:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654856763; cv=none; d=google.com; s=arc-20160816; b=XgBLiDFUooPU+pcwgIUYPc0dcPwoOLSrtlzsYndMXie3EjwRadvZwba+d3J3oEgzba HFdH1lVeuYe4Dc+KLCv31/e7cvKDLcPsBIhKIJpYUnWzPrSUI+nEHghQY5tYsDn047wS 0/E+pcVZw3DX3FSoAIo751A/B9fv7erhpsqO+qCSJ8ZojIprdE8sUKJmu+BMUlO+tJtQ gLKZT4CyqWDl36W/81914wB5B21VliyhHbnaGvdkRbwxGLOWL3uTKSgglI605YPRlrjv LY1dxk5ZmdT1xxolChSuxnmGqG/IpSH9wFrMfwbqp97R92Hq91zl7t+exxHSefK1IENS NHJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=17fg+jYWU3J3f3FCOfUq3tSqDuOvggwVESwm5R8WI+8=; b=BwGpoafrGIYPTHz3KHq2EEPtnEK1BQTuY0DaF2gsDDjBEEU4OqC4LeqRA1SDBtzpKg 0jJhehdTuIvJ0BCoWcGy96z4qHI5we0Gq3XJ2KdHkX/DBZAJVkssdw/8CaqMlbeqVdTk 5c0sOzkp8Gv3aWUx1RKGKchBJPjMTp7Fucr/+kypFa4o0HXtuWGPRKVjTZwmNl0vn0db aGchN9TA9ry/xm1oiYfGZJkhklH1JssyQX4WIjXtpbU+6YjJzkt4UcKIPJKKzQQpGAq9 kdwhVIjSiHZI4mCnE4FKaBWE3+9AKkWTWByxCYmEE7Ax5JCr0jqbwMsQ1Z5C1oaetIMF VaMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q1-20020a50aa81000000b00427ade6cd90si18031053edc.260.2022.06.10.03.25.37; Fri, 10 Jun 2022 03:26:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348298AbiFJKEB (ORCPT + 99 others); Fri, 10 Jun 2022 06:04:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347521AbiFJKD7 (ORCPT ); Fri, 10 Jun 2022 06:03:59 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5EC20B0A6E; Fri, 10 Jun 2022 03:03:56 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C8EE512FC; Fri, 10 Jun 2022 03:03:56 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.39.215]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 865873F766; Fri, 10 Jun 2022 03:03:54 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Cc: daniel.lezcano@linaro.org, amitk@kernel.org, rui.zhang@intel.com, lukasz.luba@arm.com, viresh.kumar@linaro.org, rafael@kernel.org, dietmar.eggemann@arm.com Subject: [PATCH 1/3] thermal: cpufreq_cooling: Use a copy of local ops for each cooling device Date: Fri, 10 Jun 2022 11:03:41 +0100 Message-Id: <20220610100343.32378-1-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is very unlikely that one CPU cluster would have the EM and some other won't have it (because EM registration failed or DT lacks needed entry). Although, we should avoid modifying global variable with callbacks anyway. Redesign this and add safety for such situation. Signed-off-by: Lukasz Luba --- drivers/thermal/cpufreq_cooling.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/cpufreq_cooling.c b/drivers/thermal/cpufreq_cooling.c index b8151d95a806..e33183785fac 100644 --- a/drivers/thermal/cpufreq_cooling.c +++ b/drivers/thermal/cpufreq_cooling.c @@ -554,7 +554,12 @@ __cpufreq_cooling_register(struct device_node *np, /* max_level is an index, not a counter */ cpufreq_cdev->max_level = i - 1; - cooling_ops = &cpufreq_cooling_ops; + cooling_ops = kmemdup(&cpufreq_cooling_ops, sizeof(*cooling_ops), + GFP_KERNEL); + if (!cooling_ops) { + cdev = ERR_PTR(-ENOMEM); + goto free_idle_time; + } #ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR if (em_is_sane(cpufreq_cdev, em)) { @@ -568,7 +573,7 @@ __cpufreq_cooling_register(struct device_node *np, pr_err("%s: unsorted frequency tables are not supported\n", __func__); cdev = ERR_PTR(-EINVAL); - goto free_idle_time; + goto free_cooling_ops; } ret = freq_qos_add_request(&policy->constraints, @@ -578,7 +583,7 @@ __cpufreq_cooling_register(struct device_node *np, pr_err("%s: Failed to add freq constraint (%d)\n", __func__, ret); cdev = ERR_PTR(ret); - goto free_idle_time; + goto free_cooling_ops; } cdev = ERR_PTR(-ENOMEM); @@ -597,6 +602,8 @@ __cpufreq_cooling_register(struct device_node *np, remove_qos_req: freq_qos_remove_request(&cpufreq_cdev->qos_req); +free_cooling_ops: + kfree(cooling_ops); free_idle_time: free_idle_time(cpufreq_cdev); free_cdev: @@ -677,16 +684,19 @@ EXPORT_SYMBOL_GPL(of_cpufreq_cooling_register); */ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) { + const struct thermal_cooling_device_ops *ops; struct cpufreq_cooling_device *cpufreq_cdev; if (!cdev) return; cpufreq_cdev = cdev->devdata; + ops = cdev->ops; thermal_cooling_device_unregister(cdev); freq_qos_remove_request(&cpufreq_cdev->qos_req); free_idle_time(cpufreq_cdev); kfree(cpufreq_cdev); + kfree(ops); } EXPORT_SYMBOL_GPL(cpufreq_cooling_unregister); -- 2.17.1