Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1402787rda; Mon, 23 Oct 2023 11:24:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWLZiqrZ1f12ap2Vp92rSnXTqY4px5SvaPYqWsgoTh5eNrngUZ/g0zjSZgOb5+Ks5li/xq X-Received: by 2002:a17:90a:e409:b0:27d:1126:1ff6 with SMTP id hv9-20020a17090ae40900b0027d11261ff6mr18861628pjb.8.1698085451174; Mon, 23 Oct 2023 11:24:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698085451; cv=none; d=google.com; s=arc-20160816; b=JcaJyQsSRa/Mui6Rw2NyjYZEv1p4h4cSE6wlHtJOPlARWhzzsffWdfebcPfYOU2rEc ECcX4jWIWtfXVxvnu6vhCIaAj/KFKjfCtptn2ea//HbxJw7sFUv7sFCqYWH0DW4HRapJ 2t2JYjZhrxZE4R3CEuX6yTxOq8+V5WDMpoCNdlXPp7XCStb9rMVV3hg6eTan73bjlRT9 PN4CUdbgdmSt4CJl7ShRgrwg653sRFn9ITDRFDfWU59XgRHfpgLeGXzs7KbtmsIRCr3p bX7abOg52p4zx7GEgRlKmXRkuCU8V2AdFA7OitVVoOS/t72jDFKh5y7TmrHYdGXqulGq c7AA== 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:dkim-signature; bh=jH+xgTdGBybTpfmszxd0jH64ej1Z8AlGRUmXL3RZD+E=; fh=QJuY8+zxrkMd3cgKvCdr6Bf20f7nJzeDcOkNXeH+l1I=; b=QpmYrTdA5BigbJA6mUj1INMUZ46aWz/o2DCzyTWjxXlFnYc74s9QuybhLEuzsq9EfO VzhErRi3PW0MWrt0FvW0iIRJ8dDikEHx6jzF3dWQtW1uRDjJZZa9kcZTpuu0rVbafCel YXI3SDQt4Yu4UA70Bo93p4nlmxtJZIL77Mc627NcuqvHSCH2tc2Us3TC2LFnWixycto/ OreXDhztsZE7ZJAr+URsgPrIV/rdjNvVlZNkYRtLJnBAUItNylkfnNTsWEF/+IXAXW7y ErAfOK2JJlxZBmgVQmhI2z8Na/5hBllN1TkWQqgtiA8DuKhCGyitGn9hXZPCWJH6Wy8G Ouog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TfLYPjNT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id em16-20020a17090b015000b00279016a2a2asi6812675pjb.135.2023.10.23.11.24.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 11:24:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TfLYPjNT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 644478078313; Mon, 23 Oct 2023 11:24:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233247AbjJWSX7 (ORCPT + 99 others); Mon, 23 Oct 2023 14:23:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233708AbjJWSX5 (ORCPT ); Mon, 23 Oct 2023 14:23:57 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 685389D for ; Mon, 23 Oct 2023 11:23:54 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2bb9a063f26so53131331fa.2 for ; Mon, 23 Oct 2023 11:23:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698085432; x=1698690232; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=jH+xgTdGBybTpfmszxd0jH64ej1Z8AlGRUmXL3RZD+E=; b=TfLYPjNTO5DE3b2oOAeEdyXA6CjpxzFgEVtoXNy3TaUkCjIUIbI8KMANDCl+iK3hqv tI3PbDj5gYEXZN9dJ5cuJnBmE+xCXOllS/ddUX4zUNTuDOVtCwSwHhEJ+qee61F5fvEK ytSTfwad+RnSCxbmxIw8n+ZvgFomeML0+EzukGUZ9F5D3NcYEQMAQEjKKitPJlBcb37V FmtN9/CnpakyiOMdo1EGQWkygA67yK1SQTaGj24tbXGK8BBR5g24dGo8Qtu8gYpADxvL iYIAfTyGeFklyPyg2Z58tsmp6xgjpn/p6rey/dO23jtAOozZmbcNnw5G/j2QhUSC9ND8 odnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698085432; x=1698690232; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jH+xgTdGBybTpfmszxd0jH64ej1Z8AlGRUmXL3RZD+E=; b=X3g3Ng8X9FOiRS5wqL7f8Ntj1wt6yJzxK2LCDwsRcMOnlwNpeKys4J9bTHRJBixMrJ T+CaBOwkEeknCjIFzMYv1tJgZglQY/GN/8kpV4aBA2pMwDepOGEv0aiYO2jskcSDT68p 5mjz2rX8JyPwhw2/qsSExmIe1RTyy3Jd8gGP1SRFUDL1SLQXys8WKG/XJtFjj7ZrXf8u /HeEoqWboZTRKzq4k1pPXY2BtjHk4JPYWu9q4qF9YJBtpupPMwU4VJ3dj16qKSJjxVnz u8CfiN2ii7DkMp338ZVi6xaxJrytu+O2+2Zi/ZmgvpkvUzHZi8kUJf/9U1wAw7yPiEtL fSFw== X-Gm-Message-State: AOJu0YwfxPCLAVuQn0GvPjt9aFWymfBSB4eoP6i2/9Km+7TOUpp1aifU ECypV0m4aVQORu7wB/4mX9M27IkycDmdJTqd4cN+zA== X-Received: by 2002:a2e:b00d:0:b0:2c5:260:1026 with SMTP id y13-20020a2eb00d000000b002c502601026mr6726112ljk.12.1698085432161; Mon, 23 Oct 2023 11:23:52 -0700 (PDT) Received: from [192.168.198.23] ([37.166.19.143]) by smtp.googlemail.com with ESMTPSA id m15-20020a7bcb8f000000b0040523bef620sm5242731wmi.0.2023.10.23.11.23.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 23 Oct 2023 11:23:51 -0700 (PDT) Message-ID: <3a70280b-8cc4-9f22-92b7-088fa9cb45df@linaro.org> Date: Mon, 23 Oct 2023 20:23:49 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 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: Lukasz Luba , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: dietmar.eggemann@arm.com, rui.zhang@intel.com, 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 References: <20230925081139.1305766-1-lukasz.luba@arm.com> <20230925081139.1305766-7-lukasz.luba@arm.com> From: Daniel Lezcano In-Reply-To: <20230925081139.1305766-7-lukasz.luba@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,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 groat.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 (groat.vger.email [0.0.0.0]); Mon, 23 Oct 2023 11:24:08 -0700 (PDT) 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 ? -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog