From patchwork Mon Jan 4 13:02:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 356581 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B63EC433E0 for ; Mon, 4 Jan 2021 13:03:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F38A521BE5 for ; Mon, 4 Jan 2021 13:03:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726691AbhADNDL (ORCPT ); Mon, 4 Jan 2021 08:03:11 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:46334 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726657AbhADNDK (ORCPT ); Mon, 4 Jan 2021 08:03:10 -0500 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kwPVD-00014n-SD; Mon, 04 Jan 2021 13:02:27 +0000 From: Colin King To: "Rafael J . Wysocki" , Viresh Kumar , Stephen Warren , linux-pm@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] cpufreq: powernow-k8: add null check to policy to avoid null pointer dereference Date: Mon, 4 Jan 2021 13:02:27 +0000 Message-Id: <20210104130227.35354-1-colin.king@canonical.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Colin Ian King Currently there is an unlikely case where cpufreq_cpu_get returns a null policy and this will cause a null pointer dereference later on. Fix this by adding a null check and adding an error return. Addresses-Coverity: ("Dereference null return") Fixes: b43a7ffbf33b ("cpufreq: Notify all policy->cpus in cpufreq_notify_transition()") Signed-off-by: Colin Ian King --- drivers/cpufreq/powernow-k8.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c index 0acc9e241cd7..c5368545ba1f 100644 --- a/drivers/cpufreq/powernow-k8.c +++ b/drivers/cpufreq/powernow-k8.c @@ -913,6 +913,8 @@ static int transition_frequency_fidvid(struct powernow_k8_data *data, freqs.new = find_khz_freq_from_fid(fid); policy = cpufreq_cpu_get(smp_processor_id()); + if (!policy) + return 1; cpufreq_cpu_put(policy); cpufreq_freq_transition_begin(policy, &freqs);