From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 90E7E27781E; Tue, 12 Aug 2025 19:06:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755025587; cv=none; b=IhDqaunb58qx2QJ0gaPizv3nqegYsh2DU2rOSHl0EDVeD/JIkMYOQyQPY4LZsyasbVG74rIk+w+8asfLn425ekQLcIqn+HCJJ2Awg8O3Fgv1L1kwIWaoGXmKkJKLTX2juSgRyFEBpsellMunO5H2Ra+lO8OvRWVpfSECYIsXHH0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755025587; c=relaxed/simple; bh=k08cjy0ZCpxg2lI3ZeK/JYMGxicfvzYzBLS7tJGdh+U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VTFl8sPhvJ/K0FngVAYNO7CexvauoKEkCcGWg7oR09/14eTjAaX4ginMkyerzv2t7w6F/5etkA8bBSqt6MvbdzB8NMpv7KzjGSSy2rdWMeds+91Df1YHOsxe2iA4/QVgAQ2SVA1Ein5RT5MaZyFBM7TkhhFD6YnAT95Y3/XMNMw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=U2CBxHSX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="U2CBxHSX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1896DC4CEF0; Tue, 12 Aug 2025 19:06:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1755025587; bh=k08cjy0ZCpxg2lI3ZeK/JYMGxicfvzYzBLS7tJGdh+U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U2CBxHSXEVwQJI8VgmsI3VxxRSAUTAnDZcNhC+BRbv5rrRzW/JlNSbp3UGc/kzeFk wNLd8QxfwHberybN7T/ATq8Iz8BfJn9MVNhXASAaNm9Dounle7Vho1GMuNIkQHrpSE 4UkBNf9KEwiIZU1K2bWlol/IT5QzcXhk6nDI4QKw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Lifeng Zheng , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 6.15 086/480] cpufreq: Init policy->rwsem before it may be possibly used Date: Tue, 12 Aug 2025 19:44:54 +0200 Message-ID: <20250812174400.996976600@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250812174357.281828096@linuxfoundation.org> References: <20250812174357.281828096@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lifeng Zheng [ Upstream commit d1378d1d7edb3a4c4935a44fe834ae135be03564 ] In cpufreq_policy_put_kobj(), policy->rwsem is used. But in cpufreq_policy_alloc(), if freq_qos_add_notifier() returns an error, error path via err_kobj_remove or err_min_qos_notifier will be reached and cpufreq_policy_put_kobj() will be called before policy->rwsem is initialized. Thus, the calling of init_rwsem() should be moved to where before these two error paths can be reached. Fixes: 67d874c3b2c6 ("cpufreq: Register notifiers with the PM QoS framework") Signed-off-by: Lifeng Zheng Link: https://patch.msgid.link/20250709104145.2348017-3-zhenglifeng1@huawei.com Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/cpufreq/cpufreq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index ea2a8d86d640..5c84d56341e2 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1323,6 +1323,8 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu) goto err_free_real_cpus; } + init_rwsem(&policy->rwsem); + freq_constraints_init(&policy->constraints); policy->nb_min.notifier_call = cpufreq_notifier_min; @@ -1345,7 +1347,6 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu) } INIT_LIST_HEAD(&policy->policy_list); - init_rwsem(&policy->rwsem); spin_lock_init(&policy->transition_lock); init_waitqueue_head(&policy->transition_wait); INIT_WORK(&policy->update, handle_update); -- 2.39.5