Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2082714rdh; Tue, 26 Sep 2023 11:48:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGPVpFBQCAIlQAu0YNulYMil2kMqtMfQNj3dd07UYcZ1PcZx0Qu+wjdk0dvnMBsup+eqEVi X-Received: by 2002:a05:6a20:9383:b0:15a:1817:c493 with SMTP id x3-20020a056a20938300b0015a1817c493mr9532013pzh.39.1695754093594; Tue, 26 Sep 2023 11:48:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695754093; cv=none; d=google.com; s=arc-20160816; b=mwYkk/6elP6EaIYSKsz7gt7J1x44l8qZgb1mWnFoFlFYFBc5DS8KvPTJriIgGWsx5v eWP8Bezv4EP7KTEwkC0kn5sdhOiEmP64EjgbKCLO4XXpCdMRAl1KLzruZGo4BpEljEOH Yvx5ObAWVKxYyQA6LOgCIWXk4Tdk6G5MCFDLYd5/E7C+uXrCFF63scoER7MVFmE6FoXz I6nNP7hYqik0jGwlkCdOaInhlSx1O+tc5kr/IPMwieH8yXC9yhEGLlqeu7dmMgPbsdU3 lCbDdKrhqWD81E8uC74lVa9vKPp1PAlDf52Wd15Z3ezivQq1tZzSI2st4xx4kAEwp5JF hPbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=nXxJ8l/lids+mR8XG0ZTbPJkntYawczisTnkNxSXqMw=; fh=O6YYF95gEoTquszwa1x1Mp3NZS9Am1klEUxdtkLeXmY=; b=Gq+KgnxKZC5nzm6dr2+lAlY9kk5mJ8aCqpmAbMcxuVh1xuT1oRwL+arum9dvlB9Jz9 MOEgIHPeIhfXL7q/HW9xZZ51F/sDLNZFQMdrzwolwKdxnS/wnOVvPgDZWvCUnninb6mc sPTsjns4Y2tYAQxVbF7eeiVTrreyWizIgTzGNWBBwhR4Xep1s5VMWIR+tXubP/6s/28/ 7PRVaGVTm+EQECdgYt5lWgbm0DYz5ZTkcKBSK7Am6SNK3MknfqATWsXV/DulpEYocfy8 QXUg+Q6f/ujuqihBQZ9fybZLdc/GWF2DmavzKMS8BHW1FLzlcWgShz3i8pid3qcsFOCj L+vg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id kh8-20020a170903064800b001c6223e5675si4024274plb.188.2023.09.26.11.48.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 11:48:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 5F4CE8098BB5; Tue, 26 Sep 2023 11:46:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235572AbjIZSqb convert rfc822-to-8bit (ORCPT + 99 others); Tue, 26 Sep 2023 14:46:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235395AbjIZSqa (ORCPT ); Tue, 26 Sep 2023 14:46:30 -0400 Received: from mail-oa1-f54.google.com (mail-oa1-f54.google.com [209.85.160.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E9A310A; Tue, 26 Sep 2023 11:46:24 -0700 (PDT) Received: by mail-oa1-f54.google.com with SMTP id 586e51a60fabf-1d542f05b9aso1069309fac.1; Tue, 26 Sep 2023 11:46:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695753983; x=1696358783; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fp43ADpVQE/LHvggziq02GgXbHTDklTFZf89WGvKd1k=; b=bCOs1/sIo/Q0pe5QRR0bTpCOOA382vxHk31uXS9HhLdLUotdo3xyJKMb79AkDLsUj7 13ITC6sN+LHyPcGVpuG9844XIUUwhEOJ4e5LFrXefgpoTN6YNvxKshtYbMbH5c6tCc4c UKDQQT1OQy9ZNaZJu4Fws1LG6sQDvs052Y2VeDS+UzlE2GNE92qtu58mo9Ca+izbomif 2yWZ/GRD4qvBltmRy/ZmTBpOMCJzuXEvTBakNnY9bONZvH/an0NHZrMcQAot+n/uD8bN XzqlOtlTwNJB836akBrYsuo7VYKBXBNBuVxLXW/YPCPyT4ZbH86r1sAJqmHq6M9lnTCU jdEQ== X-Gm-Message-State: AOJu0YxV0y7CkjnS3JqfKHHyIZKRorE/AXbN8yRxqEOWq7EvaYuN8PY9 uhqRT1MQETgY0qy1tSkXX3d7URueVmc0YlNGQ1M= X-Received: by 2002:a05:6870:3515:b0:1dc:6f5b:c0a0 with SMTP id k21-20020a056870351500b001dc6f5bc0a0mr9817179oah.4.1695753983646; Tue, 26 Sep 2023 11:46:23 -0700 (PDT) MIME-Version: 1.0 References: <20230925081139.1305766-1-lukasz.luba@arm.com> <20230925081139.1305766-7-lukasz.luba@arm.com> In-Reply-To: <20230925081139.1305766-7-lukasz.luba@arm.com> From: "Rafael J. Wysocki" Date: Tue, 26 Sep 2023 20:46:11 +0200 Message-ID: Subject: Re: [PATCH v4 06/18] PM: EM: Check if the get_cost() callback is present in em_compute_costs() To: Lukasz Luba Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org, 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email 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 (pete.vger.email [0.0.0.0]); Tue, 26 Sep 2023 11:46:34 -0700 (PDT) On Mon, Sep 25, 2023 at 10:11 AM Lukasz Luba wrote: > > 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(). I would just say something like this: "Subsequent changes will introduce a case in which cb->get_cost may not be set in em_compute_costs(), so add a check to ensure that it is not NULL before attempting to dereference it." The rest of the changelog is just redundant IMO. > > 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 >