Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1049403rdh; Mon, 25 Sep 2023 01:20:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFNCWDVGg8BwndLqlJPiz3GQpkLPds+h/mfDHewuypU+4K8sOf8xGmZyLzUs8yaMxUZD2qL X-Received: by 2002:a17:90a:f0ce:b0:277:4be4:7a84 with SMTP id fa14-20020a17090af0ce00b002774be47a84mr4544021pjb.19.1695630043485; Mon, 25 Sep 2023 01:20:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695630043; cv=none; d=google.com; s=arc-20160816; b=QahriGvzjAzrLZ2QMq8lutEbp4sUv89xSPRlXiHv9rAAHI2HpshBGoFr6nTJqwBr8c 3OLnU/ioPx2eaYdp5NouYUuVdCSLL0IJIpFSJY8mNSlox3SM4NsFcPffAlJT2Br6iZ9V jLkmGvdLf66NYDtbdEEwYpWptoEiCWuYfl0JenzZkGNog6hUWiPNxbbDNd2F4Don3MK4 tVpxnZNZDR5c2oWbNFGhSkJOGJO1q/fDLLGwfPFUObu2t8PkhEuGZUCWC5E1OtDy3HRW MyMYsJJhCz9NVMU8O9gP07YVJoxXykJ3O38VYsdLy7TkWhegcmbihlqXJ4Mp17cpmpOI GmtA== 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=wQ0gPwSOogTwDaTP/PQzByHSEzyoInUXuUiU4l+qyK8=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=gk6QHcPNfFB0UWSaRt99k4XsTdpgwocf+JTxX/pONsbWOhK6lorAVG2g7bycHUX/QJ NgH3vhHcQdP0kOrG/L57Zf7YFsbDEE9aDFS3AWP34cpp4q4KTxyfPJIZ3/4HxauPWmCn /kYoWfMftXDJCpAYEdnaVeX5gs3gcguQP95loZVKIsbGYk5+5vv9g2b44hMUludAysZL MdYVsDcDHq52JUhZfYXL+57ZWPmz30MyM15tggaLcVuESTKVvJ+/rdfhxQ82b8lPqgd2 ULqz0gbBrOQevog/R3MAD4wY7YNKEOhb/QwkobSNygD1KLLH6RkDrdK88KrmIdjlIHXR tWeg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id v70-20020a638949000000b0056cab36f3e1si9694573pgd.221.2023.09.25.01.20.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:20:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id F0D77801E13E; Mon, 25 Sep 2023 01:11:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232815AbjIYIL5 (ORCPT + 99 others); Mon, 25 Sep 2023 04:11:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232721AbjIYILg (ORCPT ); Mon, 25 Sep 2023 04:11:36 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 24452111; Mon, 25 Sep 2023 01:11:28 -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 B613FDA7; Mon, 25 Sep 2023 01:12:06 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.93.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 11E683F7BD; Mon, 25 Sep 2023 01:11:25 -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, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v4 06/18] PM: EM: Check if the get_cost() callback is present in em_compute_costs() Date: Mon, 25 Sep 2023 09:11:27 +0100 Message-Id: <20230925081139.1305766-7-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230925081139.1305766-1-lukasz.luba@arm.com> References: <20230925081139.1305766-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 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:11:58 -0700 (PDT) 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 7ea882401833..35e07933b34a 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