Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp11344pxb; Fri, 15 Jan 2021 04:37:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJywigWB6COq3d7w01l/jJDLjJBLQtzaOtUvr9CKbOOW3S5DV2oyblkQn0d7iTbKeH7hsSJx X-Received: by 2002:aa7:d1d4:: with SMTP id g20mr1816494edp.244.1610714253892; Fri, 15 Jan 2021 04:37:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610714253; cv=none; d=google.com; s=arc-20160816; b=HBxvRmAV6Yx+n7TSd4bMUwc/Y13rSwzupILt9coAOKu2Rm/A0DifvwZNVUTLMUEPaN 0y7jSINVxvyLpJGE3sjfJ+mRpbRK41pUgVh7blvOpjxORxhFpuTj4RbaqD7V2D/4BroC X1BLGrfuQYXyagVaiH6KMGJAtpKlOvVIcC+fcBuM0UVkR/ZqRaIwe8GmPxX3gFubeD8p 9mLMk8BM7IRV7lCfCuCbC76c5cvs8lV6v8vX+3cY0f941oYI0KB3gvQM4oppwQvRL37l 9XEW25iho1B+bX1zWk806544o904KzV+iB2J0apRjl1dYALiS9HOgovSCZwki7arjGvs pXtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GEzsN9T2nPBHzWXmdWE0QNsiI/Dgp5Jn7SPCXhlztHc=; b=QV6oxUVU+SdoXXAAlVbEcWkRQD5B5VbqtOFx14u0ENnGs8DAYQj3HkKrWMp8tNecRC xt5rz7JfW409VOwruDNC69ZBV3KB6QUXKR5CkRP/Y7vTCHUnNjhU+iebvDVfUZvBVOf7 KJzCCWTi3/O71kwmQQO3u+ayGv3abX92pR3yTyYXgbMFZFHEmv1YZLKpCV9xZqF8Inzf /JqD++siUxi1Mli+W3MaZMF24tNPBe0KI/6pUmRmwyEMtL4Ax4Xkv3cV8MKJNhzmB01U VMrXBib18UX60GUWUXal5aT+430bPN5UtZ8pt0xAIejaPnB0UWr/Q5iy9PwDzTTjBDzK Bifg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dXNmPg8m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v1si4144210edl.62.2021.01.15.04.37.09; Fri, 15 Jan 2021 04:37:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dXNmPg8m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387616AbhAOMfK (ORCPT + 99 others); Fri, 15 Jan 2021 07:35:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:41758 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387580AbhAOMfB (ORCPT ); Fri, 15 Jan 2021 07:35:01 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2697B207C4; Fri, 15 Jan 2021 12:34:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610714085; bh=+VgC4RuFlVvtY7YQhwl43Mq/hN6WhELEU5jkK0wrN88=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dXNmPg8mP+LnMzco2sL+ksWdnGK3utxLPWueO4HJbXc/vVtyEDPPCdC0B1ZdFvxnT FRHLJcw91aRa2g3vJPFuf3INe+JTjvRNJOE5EWBaTSrxIYspmUEZE6Lot085NmoGdK VUyx2uDRHy/stRI2DQmsLQeP1BrazUmPwh+mWutw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Viresh Kumar , Colin Ian King , "Rafael J. Wysocki" Subject: [PATCH 5.4 39/62] cpufreq: powernow-k8: pass policy rather than use cpufreq_cpu_get() Date: Fri, 15 Jan 2021 13:28:01 +0100 Message-Id: <20210115122000.285260060@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115121958.391610178@linuxfoundation.org> References: <20210115121958.391610178@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King commit 943bdd0cecad06da8392a33093230e30e501eccc upstream. 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 passing the policy to transition_frequency_fidvid() from the caller and hence eliminating the need for the cpufreq_cpu_get() and cpufreq_cpu_put(). Thanks to Viresh Kumar for suggesting the fix. Addresses-Coverity: ("Dereference null return") Fixes: b43a7ffbf33b ("cpufreq: Notify all policy->cpus in cpufreq_notify_transition()") Suggested-by: Viresh Kumar Signed-off-by: Colin Ian King Acked-by: Viresh Kumar Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- drivers/cpufreq/powernow-k8.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) --- a/drivers/cpufreq/powernow-k8.c +++ b/drivers/cpufreq/powernow-k8.c @@ -878,9 +878,9 @@ static int get_transition_latency(struct /* Take a frequency, and issue the fid/vid transition command */ static int transition_frequency_fidvid(struct powernow_k8_data *data, - unsigned int index) + unsigned int index, + struct cpufreq_policy *policy) { - struct cpufreq_policy *policy; u32 fid = 0; u32 vid = 0; int res; @@ -912,9 +912,6 @@ static int transition_frequency_fidvid(s freqs.old = find_khz_freq_from_fid(data->currfid); freqs.new = find_khz_freq_from_fid(fid); - policy = cpufreq_cpu_get(smp_processor_id()); - cpufreq_cpu_put(policy); - cpufreq_freq_transition_begin(policy, &freqs); res = transition_fid_vid(data, fid, vid); cpufreq_freq_transition_end(policy, &freqs, res); @@ -969,7 +966,7 @@ static long powernowk8_target_fn(void *a powernow_k8_acpi_pst_values(data, newstate); - ret = transition_frequency_fidvid(data, newstate); + ret = transition_frequency_fidvid(data, newstate, pol); if (ret) { pr_err("transition frequency failed\n");