From nobody Sat Sep 26 12:30:54 2026 Received: from mail-m49197.qiye.163.com (mail-m49197.qiye.163.com [45.254.49.197]) (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 D97EF220687; Tue, 1 Sep 2026 12:20:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.254.49.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788265205; cv=none; b=u8RkcO7Yd4jwNFL3X4VjSu6eH8nhHAsZhXWPNFjlJWgwgjI0VmtRzWHYcX3Dt/2XQ569q/p7MJm2Y0mUt61Iv1odcUcljk4BxKlH7CSESAyhxjRhxvz3uOlajlf2+wrxuD2/skfjRTLGn4oADKSMjXdmvILpMD6hPVq7nDrWNW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788265205; c=relaxed/simple; bh=M17vO7AFGVry5Sknf9jU79Up078a8AwEuDAbHXlkgrM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=G7qSlCnrY0nqOcfovf660uF304haToaLXXL0HeDvLrBIKUks/GcWlfDHMySgukCBFC5cQvJT2X7HU60wVmnmpZJyv2zeXQZoY+Dkbzn8UEZoZVu4XwAWxGZ1g/BC3KTywmJDGyxk91toAI95d4n1dWcQal5ISg4qoSsPd7HjwW4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn; spf=pass smtp.mailfrom=seu.edu.cn; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b=MvIqRahn; arc=none smtp.client-ip=45.254.49.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b="MvIqRahn" Received: from PC-202605011814.localdomain (unknown [223.112.146.162]) by smtp.qiye.163.com (Hmail) with ESMTP id 4c1e3810b; Tue, 1 Sep 2026 20:19:57 +0800 (GMT+08:00) From: Runyu Xiao To: "Rafael J . Wysocki" Cc: Viresh Kumar , Zhongqiu Han , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Runyu Xiao , Jianhao Xu Subject: [PATCH v2] cpufreq: initialize policy rwsem before sysfs publication Date: Tue, 1 Sep 2026 20:19:50 +0800 Message-Id: <20260901121950.3279176-1-runyu.xiao@seu.edu.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260830155301.2713780-1-runyu.xiao@seu.edu.cn> References: <20260830155301.2713780-1-runyu.xiao@seu.edu.cn> 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-HM-Tid: 0aa05ce9700503a1kunme032913116d054 X-HM-MType: 10 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWRgWCB1ZQUpXWS1ZQUlXWQ8JGhUIEh9ZQVlDTh1OVhlNGUxDSB0YTx1DSVYeHw 5VEwETFhoSFyQUDg9ZV1kYEgtZQVlJSUhVSkpJVUpPTVVKTUlZV1kWGg8SFR0UWUFZT0tIVUpLSE pPSExVSktLVUpCS0tZBg++ DKIM-Signature: a=rsa-sha256; b=MvIqRahngp4Zyn2FdQrpNs2+59kkmwrUKS5HgLEowOjz5F98r+1O8h0/LonyZoT6Er7hs/gYttHjmgSGFGOy3kj8382RzEsp1mRxWV1XKM0rwgkGv5dNr3MlF7iS4ZGWHBCjm3EjieFTOoW3Jd5W08rFfwL4/+pQmK9iSqNygN8=; s=default; c=relaxed/relaxed; d=seu.edu.cn; v=1; bh=YpZRmLswTmoGl6mUHCr2/I50lcY6GVVwevcgNvscOHo=; h=date:mime-version:subject:message-id:from; Content-Type: text/plain; charset="utf-8" cpufreq_policy_alloc() initializes policy->rwsem after kobject_init_and_add() has created the policy sysfs directory and its default attributes. A sysfs access can therefore reach a policy callback before the semaphore has been initialized. Initialize policy->rwsem before publishing the policy kobject so sysfs callbacks always see an initialized semaphore. Fixes: 2fc3384dc75b ("cpufreq: Initialize policy->kobj while allocating pol= icy") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/all/20260830155301.2713780-1-runyu.xiao@seu.e= du.cn/ Signed-off-by: Runyu Xiao Assisted-by: Codex:GPT-5 Reviewed-by: Zhongqiu Han --- v2: - Correct the Fixes tag to the commit that introduced policy kobject public= ation. --- drivers/cpufreq/cpufreq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 0d0df986f..9efbf5b17 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1258,6 +1258,8 @@ static struct cpufreq_policy *cpufreq_policy_alloc(un= signed int cpu) if (!zalloc_cpumask_var(&policy->real_cpus, GFP_KERNEL)) goto err_free_rcpumask; =20 + init_rwsem(&policy->rwsem); + init_completion(&policy->kobj_unregister); ret =3D kobject_init_and_add(&policy->kobj, &ktype_cpufreq, cpufreq_global_kobject, "policy%u", cpu); @@ -1272,8 +1274,6 @@ static struct cpufreq_policy *cpufreq_policy_alloc(un= signed int cpu) goto err_free_real_cpus; } =20 - init_rwsem(&policy->rwsem); - freq_constraints_init(&policy->constraints); =20 policy->nb_min.notifier_call =3D cpufreq_notifier_min; --=20 2.34.1