Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1732559rda; Tue, 24 Oct 2023 01:13:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHtW3OTfjzIk7uO84gHBzNBMDcjsKtxNmsOybBIQE/vRxfo0JcGV5N2WhqnubLrGul7sMEP X-Received: by 2002:a17:902:f54f:b0:1c5:c546:fece with SMTP id h15-20020a170902f54f00b001c5c546fecemr20099383plf.34.1698135229511; Tue, 24 Oct 2023 01:13:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698135229; cv=none; d=google.com; s=arc-20160816; b=avzSgnBOOw9A7nlNqI55t3iu1z4B7CyfGjJ7QQL9SLVq6RhUW75bZLHgAIHR8TuoXe YVxR/DLnCqqym9PCr/5gYsSnsAnaqOU0ihy0p+vwxzpfExGW2oQFrXG4Bllfmv/bHD5c ZEVx3/xOBm3FJZXfkC4JU89WidYmh/FA8HChycBUXyWsf1Y65DFTXjFHFJFGZTbMriPO LxJy3CPI1jELtJu4e2Otk1YhN66x8ZU9b3Irmz1Cn5n2+YvJkYhc2qy1SKKolG7T2IxQ HTvHd5C6lBAerQqnGmd0Sx7Gqy3j3B+s14Dy7QNepf027N0tTeNdSxI+ThLFpcanXHHF jpSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=A21lLFAFM/B3VOps/wSGHJ5mYvA2Xr7Q7FEdvMuuULs=; fh=1yH92kB6kssAYZtZ9Tpd7pDFbqEZBLu0YeO4kNJuZh8=; b=P0ARbMFuWBqxMRAwPCiC15/AbvVnxzZx971/XLTYsmpRH4RYNGIC3/MfKm0Bpj8UFN DAqivwuepuolJ83kg1Meh7AlDrSUTOUCOm4k17GnM+XgG0HEiQxuDmtGXT32dy10nczK rT5UuiRDBw82KibI2to1YMAX0jQS3w91mWbYjURuuHhvC1ukLptXnynIRJuzuRJNi+IG KpqeGlSL90XluiKldy8eXVmkLxZPJRCXZtfU5mhvnAeTqRTHgB7tQ0I8lFCR1Gwih+Zf otD4Ioeu6cX9GbOd7iC9RuZtZYgBrT4TBFqsCh27C4w2pfTqdSkompBsDDs9ic3t1ZW/ SEUA== 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:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id w63-20020a638242000000b005852a35aff4si8153935pgd.227.2023.10.24.01.13.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 01:13:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 361C7803BEF2; Tue, 24 Oct 2023 01:13:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233115AbjJXINg (ORCPT + 99 others); Tue, 24 Oct 2023 04:13:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233083AbjJXINb (ORCPT ); Tue, 24 Oct 2023 04:13:31 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A6EF2D7B; Tue, 24 Oct 2023 01:13: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 57E552F4; Tue, 24 Oct 2023 01:14:09 -0700 (PDT) Received: from [10.57.83.179] (unknown [10.57.83.179]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2D9DF3F762; Tue, 24 Oct 2023 01:13:26 -0700 (PDT) Message-ID: <2ed209ec-2eef-4a41-9591-275e7d8f7676@arm.com> Date: Tue, 24 Oct 2023 09:14:17 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 06/18] PM: EM: Check if the get_cost() callback is present in em_compute_costs() Content-Language: en-US To: Daniel Lezcano Cc: dietmar.eggemann@arm.com, rui.zhang@intel.com, linux-kernel@vger.kernel.org, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com, linux-pm@vger.kernel.org, rafael@kernel.org References: <20230925081139.1305766-1-lukasz.luba@arm.com> <20230925081139.1305766-7-lukasz.luba@arm.com> <3a70280b-8cc4-9f22-92b7-088fa9cb45df@linaro.org> From: Lukasz Luba In-Reply-To: <3a70280b-8cc4-9f22-92b7-088fa9cb45df@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, 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 morse.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 (morse.vger.email [0.0.0.0]); Tue, 24 Oct 2023 01:13:47 -0700 (PDT) On 10/23/23 19:23, Daniel Lezcano wrote: > On 25/09/2023 10:11, 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(). >> >> 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", > > I do believe & operator has lower precedence than && operator, thus the > test is actually: > >     (flags & (EM_PERF_DOMAIN_ARTIFICIAL && cb->get_cost)) > > but it should be > >     ((flags & EM_PERF_DOMAIN_ARTIFICIAL) && cb->get_cost) > > Right ? > The bitwise '&' is stronger than logical '&&', so the code will work as in your 2nd example. Although, I will change it and add parentheses for better reading. Thanks!