From patchwork Mon Dec 30 09:01:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles Han X-Patchwork-Id: 13923105 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 53E4BE77188 for ; Mon, 30 Dec 2024 09:03:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:CC:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=IGfy9avmke4l07b7P6Z8js6mtCsKIUYHWXKM/9fif2A=; b=V12Na9UTDwZbvW0R2x3BSa1QUg 9PlxpjtHyWMduq2sHjGBFsTONkugeINHlhih2Z15n2Bws2O2rofcM2mHuhOwkfgt9oKW25txgMiOm YUxlzDFHJSd5aHcLgBMt6deuDYPH2ABePkey1scbApL0QIbeNBxN9Bz4S4kcgE6ivjVJR/oOMaixD H4Im0LZZ5pfNIDmiYM/FoKTwl8wxif/TbYS1Pgz2yTAuQZY3EpkTZjgzHThDssdC24lum3MM1roLR TFOXmi/Y2p8mGJ7v/xBzhSjwyeabTYHC2THa/kcLlINqWJt7dYZ+aYLV/p5t/NVAlljEpSPBZGiL3 y3xLuh5g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tSBg1-00000004rCT-0niu; Mon, 30 Dec 2024 09:03:05 +0000 Received: from ssh247.corpemail.net ([210.51.61.247]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tSBen-00000004r92-3Kpg for linux-arm-kernel@lists.infradead.org; Mon, 30 Dec 2024 09:01:51 +0000 Received: from ssh247.corpemail.net by ssh247.corpemail.net ((D)) with ASMTP (SSL) id BNG00142; Mon, 30 Dec 2024 17:01:42 +0800 Received: from jtjnmail201607.home.langchao.com (10.100.2.7) by jtjnmail201603.home.langchao.com (10.100.2.3) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 30 Dec 2024 17:01:41 +0800 Received: from localhost.localdomain (10.94.16.130) by jtjnmail201607.home.langchao.com (10.100.2.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 30 Dec 2024 17:01:40 +0800 From: Charles Han To: , , , , , , CC: , , , Charles Han Subject: [PATCH v2] cpufreq: apple-soc: Prevent null pointer dereference in apple_soc_cpufreq_get_rate() Date: Mon, 30 Dec 2024 17:01:37 +0800 Message-ID: <20241230090137.243825-1-hanchunchao@inspur.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Originating-IP: [10.94.16.130] X-ClientProxiedBy: Jtjnmail201615.home.langchao.com (10.100.2.15) To jtjnmail201607.home.langchao.com (10.100.2.7) tUid: 20241230170142493d58637f608581f9d59fb39e6fbd50 X-Abuse-Reports-To: service@corp-email.com Abuse-Reports-To: service@corp-email.com X-Complaints-To: service@corp-email.com X-Report-Abuse-To: service@corp-email.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241230_010150_163376_AE54D411 X-CRM114-Status: UNSURE ( 9.78 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org cpufreq_cpu_get_raw() may return NULL if the cpu is not in policy->cpus cpu mask and it will cause null pointer dereference. Prevent null pointer dereference in apple_soc_cpufreq_get_rate(). Fixes: 6286bbb40576 ("cpufreq: apple-soc: Add new driver to control Apple SoC CPU P-states") Signed-off-by: Charles Han --- drivers/cpufreq/apple-soc-cpufreq.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/cpufreq/apple-soc-cpufreq.c b/drivers/cpufreq/apple-soc-cpufreq.c index 4dcacab9b4bf..1c6d81355b41 100644 --- a/drivers/cpufreq/apple-soc-cpufreq.c +++ b/drivers/cpufreq/apple-soc-cpufreq.c @@ -104,6 +104,9 @@ static const struct of_device_id apple_soc_cpufreq_of_match[] __maybe_unused = { static unsigned int apple_soc_cpufreq_get_rate(unsigned int cpu) { struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu); + if (unlikely(!policy)) + return 0; + struct apple_cpu_priv *priv = policy->driver_data; struct cpufreq_frequency_table *p; unsigned int pstate;