From nobody Sun Nov 24 16:37:45 2024 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E586418B473; Mon, 4 Nov 2024 11:36:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730720218; cv=none; b=hxiJSjSr5Nr+Cgi2kP0bCpOlQpdhTSbioo/0s1JsxBauHoLbtLkDZJFVoz57iK47hG7USu6xaSBazXO2diU3rpiSy2ekPFZC5oyCNld3rTv1oMVJWfXGkY/8l9mIZjIpSoHCdA4TexWe1X0MqG+OPK8WbYV3wIvxhebZNpmiQQg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730720218; c=relaxed/simple; bh=rWT/UhQK41/pl7QfPB/0KppNr9Y+HnzSSkK/w4+Rsxc=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=VXaxKdvGELQtqieWVz6IcYuj8OIQmHfxnVXy8hVAYzkhdQc+t4Gj7i6XEW/On205lCeA1FLKWAS1LS0QDp3fH5tfgQ6P26SfYKS+g+DVf4UhmXHiU3+pWIS8Wfcida6zg3zFOccHaCO+vLeVnyPGU2Bo6Q8Bw2QYmwVqVGQXC60= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4XhqC51bcnz2Fb27; Mon, 4 Nov 2024 19:35:13 +0800 (CST) Received: from kwepemg200008.china.huawei.com (unknown [7.202.181.35]) by mail.maildlp.com (Postfix) with ESMTPS id BEE361A0188; Mon, 4 Nov 2024 19:36:51 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemg200008.china.huawei.com (7.202.181.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 4 Nov 2024 19:36:51 +0800 From: Jinjie Ruan To: , , , , , , , , , , CC: Subject: [PATCH v2] PM: EM: Fix wrong return value in mtk_cpufreq_get_cpu_power() Date: Mon, 4 Nov 2024 19:36:15 +0800 Message-ID: <20241104113615.1397410-1-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemg200008.china.huawei.com (7.202.181.35) Content-Type: text/plain; charset="utf-8" mtk_cpufreq_get_cpu_power() return 0 if the policy is NULL. Then in em_create_perf_table(), the later zero check for power is not invalid as power is uninitialized. As Lukasz suggested, it must return -EINVAL when the 'policy' is not found. So return -EINVAL to fix it. Cc: stable@vger.kernel.org Fixes: 4855e26bcf4d ("cpufreq: mediatek-hw: Add support for CPUFREQ HW") Suggested-by: Lukasz Luba Signed-off-by: Jinjie Ruan Reviewed-by: Lukasz Luba --- v2: - Fix the driver instead of em_create_perf_table() as suggested. - Update the commit message. - Add Suggested-by. --- drivers/cpufreq/mediatek-cpufreq-hw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/cpufreq/mediatek-cpufreq-hw.c b/drivers/cpufreq/mediat= ek-cpufreq-hw.c index 8925e096d5b9..aeb5e6304542 100644 --- a/drivers/cpufreq/mediatek-cpufreq-hw.c +++ b/drivers/cpufreq/mediatek-cpufreq-hw.c @@ -62,7 +62,7 @@ mtk_cpufreq_get_cpu_power(struct device *cpu_dev, unsigne= d long *uW, =20 policy =3D cpufreq_cpu_get_raw(cpu_dev->id); if (!policy) - return 0; + return -EINVAL; =20 data =3D policy->driver_data; =20 --=20 2.34.1