Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp181165rwo; Fri, 21 Jul 2023 10:10:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlErbfim23pYbLoPU05Q5koT6jb+XTjCfoDodcDtQ4RwYWJmsPZrFLGEQPppqOEVM/ecg5ZN X-Received: by 2002:a17:906:20ce:b0:992:61c5:dab0 with SMTP id c14-20020a17090620ce00b0099261c5dab0mr1888195ejc.62.1689959422053; Fri, 21 Jul 2023 10:10:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689959422; cv=none; d=google.com; s=arc-20160816; b=LZVH7Nm19RULt7hYK41hHqAzXy/KeS5LuiRtNhRw/16GrsSKRZ3d8J+1bKkTPubjQZ aVspDFuVq3h5Wk0gp+mgRXO5YlHh87syFpyA4Gs15+D06FtpV6jm2Hq8nXB2F0gsfPtB 8+FA9FBEUFxx5UE4L8oar7dhhnlHE3KsTQ4nLDOIz/GN1KLVDymagB7rlaxvu9pdoDfF FzDtDRDQDTkK25OsFo5sM/K6HTZweHMETXNCMvM206JSgaW4FZU7KMneAvPW5O16YuYM y2jNWGJZW4kkG3KJZzdk4+gIYi7ESv3bsuxP4U9VpMTYgliFJqtonpGsv6sySbQa+04Y OKNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=gIog7Vqsz8TXg0sNd/WSlLFE2ysEP/QcCHQmhlg5s6k=; fh=X59gKo2bTEq2VHcwIFizOsXoeGl1m0HuKLr4L9qvQjg=; b=hLda3kefgLzjz2ASEMdlJBEFpFppCggGdSi0h5zTO6X9z9mjKDjok09p0yZIDno8b/ ErsUX+0qJcAaqN7cHpoZ7VZC1BNi+/8ef/HHCoMvm+2waIJV5eTQWYiywQtvF0n1BTjQ Y52K8A/wdiF2XuiR89/w/h0qny1eH7uGUTXoVQL7k1hwBMTF/2UFgdI2zxOHuGBuq7D4 TKbuT2xMGqCsV1Y/JHATp62G8RaQnfClfCY+iYhy+61wdTInpvCMgD955dswvcznlJ+3 /eh0ZstA7aK9RmpExIuLBJ70brZlvqYW8uTyPybquqUX9iRqgLToI8YXOa25xXR5RpS/ CJHw== 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 lc24-20020a170906f91800b0098dfec24292si2422079ejb.829.2023.07.21.10.09.56; Fri, 21 Jul 2023 10:10:22 -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 S232291AbjGUPub (ORCPT + 99 others); Fri, 21 Jul 2023 11:50:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232298AbjGUPuU (ORCPT ); Fri, 21 Jul 2023 11:50:20 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0A82C2D47; Fri, 21 Jul 2023 08:50:15 -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 DD68D2F4; Fri, 21 Jul 2023 08:50:58 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.0.79]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A69503F844; Fri, 21 Jul 2023 08:50:12 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, Pierre.Gondois@arm.com, ionela.voinescu@arm.com, mhiramat@kernel.org Subject: [PATCH v3 05/12] PM: EM: Check if the get_cost() callback is present in em_compute_costs() Date: Fri, 21 Jul 2023 16:50:15 +0100 Message-Id: <20230721155022.2339982-6-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230721155022.2339982-1-lukasz.luba@arm.com> References: <20230721155022.2339982-1-lukasz.luba@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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 The em_compute_cost() is going to be re-used in runtime modified EM code path. Thus, make sure that this common code is safe and won't try to use the NULL pointer. The former em_compute_cost() didn't have to care about runtime modification code path. The upcoming changes introduce such option, but with different callback. Those two paths which use get_cost() (during first EM registration) or update_power() (during runtime modification) need to be safely handled in em_compute_costs(). Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index fd1066dcf38b..5ecb73b36995 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -116,7 +116,7 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table, for (i = nr_states - 1; i >= 0; i--) { unsigned long power_res, cost; - if (flags & EM_PERF_DOMAIN_ARTIFICIAL) { + if (flags & EM_PERF_DOMAIN_ARTIFICIAL && cb->get_cost) { ret = cb->get_cost(dev, table[i].frequency, &cost); if (ret || !cost || cost > EM_MAX_POWER) { dev_err(dev, "EM: invalid cost %lu %d\n", -- 2.25.1