From patchwork Wed Oct 30 01:20:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13855817 X-Patchwork-Delegate: viresh.linux@gmail.com Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (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 6DACA13774B; Wed, 30 Oct 2024 01:20:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730251261; cv=none; b=CUqS9a/RQeKJqzNIvx7y4UWdm/NjXInzMInuEZgxrg3Ue2YADCHbSG+aOwHV5KgXwVgtdeEQn1PULhH4tD8LpkS3F3Yto2hbf/apXU2B5FY82KBS4ZkaFA4mengTevQ1p3tK++53MUbqpeMpnaICTwQM1rL/Ns/AmqRe93ksmw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730251261; c=relaxed/simple; bh=fme0YyjHgadUvFsmVz/SikUmPufmMWN90T1PJ9hi5+c=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=CZ7STTO81SSw7OsvuCYsq+gxSTDW2Gj+P43kvrTqHV9/kp1/lqfHpKoAz/2x1JPOaW3CyN0mHsM+tZ0EGNk+Xvw3m/9wLfR8NeiLNTVR6d4q4vjFa+eL2Pv+PqV9+4HQdZ9t4DLV1Gfj3g50QSNPwyF0oPWmcKWNYZwHHltdgzA= 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.32 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.44]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4XdTpf1szDz1ynhZ; Wed, 30 Oct 2024 09:20:58 +0800 (CST) Received: from kwepemg200008.china.huawei.com (unknown [7.202.181.35]) by mail.maildlp.com (Postfix) with ESMTPS id 9C7B91400D3; Wed, 30 Oct 2024 09:20:49 +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; Wed, 30 Oct 2024 09:20:49 +0800 From: Jinjie Ruan To: , , , , CC: Subject: [PATCH] cpufreq: CPPC: Fix possible null-ptr-deref for cpufreq_cpu_get_raw() Date: Wed, 30 Oct 2024 09:20:19 +0800 Message-ID: <20241030012019.357039-1-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemg200008.china.huawei.com (7.202.181.35) cpufreq_cpu_get_raw() may return NULL if the cpu is not in policy->cpus cpu mask and it will cause null pointer dereference. Fixes: 740fcdc2c20e ("cpufreq: CPPC: Register EM based on efficiency class information") Signed-off-by: Jinjie Ruan --- drivers/cpufreq/cppc_cpufreq.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 2b8708475ac7..01c24c0ee9b3 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -420,6 +420,9 @@ static int cppc_get_cpu_power(struct device *cpu_dev, struct cppc_cpudata *cpu_data; policy = cpufreq_cpu_get_raw(cpu_dev->id); + if (!policy) + return 0; + cpu_data = policy->driver_data; perf_caps = &cpu_data->perf_caps; max_cap = arch_scale_cpu_capacity(cpu_dev->id);