Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp209900rdb; Thu, 8 Feb 2024 03:57:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvzvXMHpm0CSJtZhlLgEJj/SRQ7HIZxLTLJpeSkuyFgGZiSFINrjuS6N4mAJ/dIEv8A8c4 X-Received: by 2002:aa7:da98:0:b0:560:463:8cd7 with SMTP id q24-20020aa7da98000000b0056004638cd7mr5941305eds.34.1707393474949; Thu, 08 Feb 2024 03:57:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393474; cv=pass; d=google.com; s=arc-20160816; b=BXsoQm/kzu3bEbt0WIZ9X2CYLZWHgAFxJ+4zEWL9IYhlBRaR2mf8zguYiK4VrhBf/O 6+kv+XMA0gA68WLulcxuVXaPo4De0BzmDjAtppjQSrQs174B+cqfzaTE4OY+1I+iZIKA C4NU5MGj0h2WkvCUl6jD3dKyJXLw0vJLeVd7qeCBbM6EYVDyAWcPtRjtuv9tjnt4vJ/T bRcwu2Jr5z7uSQqDq/3xzGTLL3NfUgP+DY+rGrFO4zf3DW/kfII94QZGofkU9vB7aiTY 9p7SLwFztTyPG4JyQTZlbSj0kcbBjRsYrBmG+s99L8fwa9hGim99Ehvv9liBilGsxoRe cL/A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=pNudkuW67175AYZXExAU7FwVK78v0+Vc4RQALB3xfw8=; fh=tzsORTWD3fnN5etb4oqvzmoQTNlseg3UQbyvm7iLcH0=; b=F2BKYxt32hKJ2eJm0sVKOusQ+apfOvgi6PPbfEahvpuIq5DA/t1jsVJ4kyk7EnuJNr tkjuBb/lJ1ZrG5Jd2DZci68G8Eehd4wUtiO0nSHmZh3u7XUNdB5nhFoVob4xQbn8MOi4 5xb8Iqhe0zLCLAPSpXKhcRulweAicjFm/fiX0Rq3Cg9dK25zeYC2CvtyAk9d/55RX3LA 2nB2fBve9FuKCNOybMcB13JjzTDRFc7ApwHwha6+IMXKAE0DCcZZiBBPwZA4SGLHPHAO OGW7QzgjBOZSh/P9YUKec72nmipgjZfK4+2Wa90NI8yJ6dCR9HTfQ49ixMsoTRuuFREl 0pyQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-57999-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57999-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCWmMuyvXxNLlI1A1pMNCr/pE2xzE8CmYqoRjYhDFxqk2AJQdaSjTF4LkyZEFlYHXEnwQEjbN90gXa0tuxLhY+DEYVXtfNg4UmqU8jVWrA== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a20-20020aa7cf14000000b005607fcdfaf5si820623edy.668.2024.02.08.03.57.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 03:57:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57999-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-57999-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57999-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AD8521F212F4 for ; Thu, 8 Feb 2024 11:57:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA3EA76406; Thu, 8 Feb 2024 11:56:26 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7854B763EF; Thu, 8 Feb 2024 11:56:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393386; cv=none; b=phkc+KWI+3moz0NlZYszUOi3dfKU6NCR/11pAXqVZOBGdFCoop8jw9JVoNdZZBtu/tq6up2s9lnmu2+n+mNk6D/fWMGUhtOv/vEXfhuX6wao1ajA5eBmWKpXZHWYwZq0mNwN8Bdvii3aLc3Uk5++No2nrhmP5WTwr22dh9Ay0CY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393386; c=relaxed/simple; bh=Da4Wg14h1CcjXL0JhFy9dAEG/iSfGR93L/E4kBh6W60=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mwR4z9TQIJ3uYydZtMgCfMK2m2L6W/NoJ1I86THIWWBQ4j6Esf/UgqMqQPFzrFDT6RFjRDPlFvt25FkCISpLnfQWxUdpNn9tYxT/56aiEfhtvoDivpY2uyyBylIKF65sBQIoCcfkDZn7ABVb/8WJCaDvFj1HdEtkKbAUu5rwS4E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 2D2741FB; Thu, 8 Feb 2024 03:57:06 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 08FFE3F5A1; Thu, 8 Feb 2024 03:56:20 -0800 (PST) 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, xuewen.yan94@gmail.com Subject: [PATCH v8 06/23] PM: EM: Check if the get_cost() callback is present in em_compute_costs() Date: Thu, 8 Feb 2024 11:55:40 +0000 Message-Id: <20240208115557.1273962-7-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann 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 5c47caaf270e..21d761223255 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