From nobody Sun Nov 24 08:05:42 2024 Received: from mx.astralinux.ru (mx.astralinux.ru [89.232.161.68]) (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 1EFAF56B72; Mon, 26 Aug 2024 14:11:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=89.232.161.68 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724681471; cv=none; b=IO1LQ7iOUI4bCyeUMo55bMF2vZG+8MR8fyvoJsMn2JZFwd1qSMZcurixvXVBHZXeB0qqCX6JZ43yAoRXofAHDgX6dgb6jaRo7B+Qqv7x2sFD9i0OVKw8C59YTwgVPNc0Da710maqMxOHqinf05x/ckhJOz/aX8uSVUePiwqq9Ss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724681471; c=relaxed/simple; bh=n9kWJiaDHqQ8bH60oDWuOkc32z384dbouLbtbCZjEgg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=lMLMg0BticHeGG3oaN5pqRVCpRXSlSY+GwYgTm65SezIdET3SpZAm+CaOaXoqsTHivrM3dsb04Szc2I5TxDpFMCXwLGvA/Av77+hg11PYzwMW8m/FdQBnwOhxH4SVtWoFgPdGz7uDoX9Jf3+8mEm3c8WSfX3/fnjrV8V7tn12w0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=astralinux.ru; spf=pass smtp.mailfrom=astralinux.ru; arc=none smtp.client-ip=89.232.161.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=astralinux.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=astralinux.ru Received: from [10.177.185.111] (helo=new-mail.astralinux.ru) by mx.astralinux.ru with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1siZwH-0089b0-5y; Mon, 26 Aug 2024 16:39:21 +0300 Received: from rbta-msk-lt-106062.astralinux.ru (unknown [10.177.20.58]) by new-mail.astralinux.ru (Postfix) with ESMTPA id 4WssHf0G0lz1c066; Mon, 26 Aug 2024 16:40:13 +0300 (MSK) From: Anastasia Belova To: Huang Rui Cc: Anastasia Belova , "Gautham R. Shenoy" , Mario Limonciello , Perry Yuan , "Rafael J. Wysocki" , Viresh Kumar , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: [PATCH v2] cpufreq: amd-pstate: add check for cpufreq_cpu_get's return value Date: Mon, 26 Aug 2024 16:38:41 +0300 Message-Id: <20240826133842.5519-1-abelova@astralinux.ru> X-Mailer: git-send-email 2.30.2 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-DrWeb-SpamScore: 0 X-DrWeb-SpamState: legit X-DrWeb-SpamDetail: gggruggvucftvghtrhhoucdtuddrgedvfedrvdehuddgtddvucetufdoteggodetrfcurfhrohhfihhlvgemucfftfghgfeunecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffoggfgsedtkeertdertddtnecuhfhrohhmpeetnhgrshhtrghsihgruceuvghlohhvrgcuoegrsggvlhhovhgrsegrshhtrhgrlhhinhhugidrrhhuqeenucggtffrrghtthgvrhhnpeffvddvueehvedvgfeivdeuvdduteeulefgfeehieffgfehtedutdfgveefvdeiheenucffohhmrghinheplhhinhhugihtvghsthhinhhgrdhorhhgnecukfhppedutddrudejjedrvddtrdehkeenucfrrghrrghmpehhvghloheprhgsthgrqdhmshhkqdhlthdquddtiedtiedvrdgrshhtrhgrlhhinhhugidrrhhupdhinhgvthepuddtrddujeejrddvtddrheekmeehfeeiledvpdhmrghilhhfrhhomheprggsvghlohhvrgesrghsthhrrghlihhnuhigrdhruhdpnhgspghrtghpthhtohepuddtpdhrtghpthhtoheprhgrhidrhhhurghnghesrghmugdrtghomhdprhgtphhtthhopegrsggvlhhovhgrsegrshhtrhgrlhhinhhugidrrhhupdhrtghpthhtohepghgruhhthhgrmhdrshhhvghnohihsegrmhgurdgtohhmpdhrtghpthhtohepmhgrrhhiohdrlhhimhhonhgtihgvlhhlohesrghmugdrtghomhdprhgtphhtthhopehpvghrrhihrdihuhgrnhesrg hmugdrtghomhdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepvhhirhgvshhhrdhkuhhmrghrsehlihhnrghrohdrohhrghdprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlvhgtqdhprhhojhgvtghtsehlihhnuhigthgvshhtihhnghdrohhrghenucffrhdrhggvsgcutehnthhishhprghmmecunecuvfgrghhsme X-DrWeb-SpamVersion: Dr.Web Antispam 1.0.7.202406240#1724674093#02 X-AntiVirus: Checked by Dr.Web [MailD: 11.1.19.2307031128, SE: 11.1.12.2210241838, Core engine: 7.00.65.05230, Virus records: 12138139, Updated: 2024-Aug-26 11:54:02 UTC] Content-Type: text/plain; charset="utf-8" cpufreq_cpu_get may return NULL. To avoid NULL-dereference check it and return in case of error. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Anastasia Belova --- v2: remove mixing code and declarations drivers/cpufreq/amd-pstate.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 68c616b572f2..f8d474168430 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -656,7 +656,12 @@ static void amd_pstate_adjust_perf(unsigned int cpu, unsigned long max_perf, min_perf, des_perf, cap_perf, lowest_nonlinear_perf; struct cpufreq_policy *policy =3D cpufreq_cpu_get(cpu); - struct amd_cpudata *cpudata =3D policy->driver_data; + struct amd_cpudata *cpudata; + + if (!policy) + return; + + cpudata =3D policy->driver_data; =20 if (policy->min !=3D cpudata->min_limit_freq || policy->max !=3D cpudata-= >max_limit_freq) amd_pstate_update_min_max_limit(policy); @@ -870,11 +875,16 @@ static void amd_pstate_init_prefcore(struct amd_cpuda= ta *cpudata) static void amd_pstate_update_limits(unsigned int cpu) { struct cpufreq_policy *policy =3D cpufreq_cpu_get(cpu); - struct amd_cpudata *cpudata =3D policy->driver_data; + struct amd_cpudata *cpudata; u32 prev_high =3D 0, cur_high =3D 0; int ret; bool highest_perf_changed =3D false; =20 + if (!policy) + return; + + cpudata =3D policy->driver_data; + mutex_lock(&amd_pstate_driver_lock); if ((!amd_pstate_prefcore) || (!cpudata->hw_prefcore)) goto free_cpufreq_put; --=20 2.30.2