public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] *cpufreq: Use FIELD_MODIFY() for bitfield operations
@ 2026-04-30 16:32 Hans Zhang
  2026-04-30 16:32 ` [PATCH 1/2] cpufreq/amd-pstate: Use FIELD_MODIFY() Hans Zhang
  2026-04-30 16:32 ` [PATCH 2/2] cpufreq: apple-soc: " Hans Zhang
  0 siblings, 2 replies; 5+ messages in thread
From: Hans Zhang @ 2026-04-30 16:32 UTC (permalink / raw)
  To: ray.huang, mario.limonciello, rafael, viresh.kumar, sven, j
  Cc: perry.yuan, kprateek.nayak, neal, linux-pm, asahi, linux-kernel,
	Hans Zhang

Replace open-coded bitfield modifications with the standard FIELD_MODIFY()
macro. This improves code readability and safety without functional
changes.

FIELD_MODIFY() internally performs the same mask-clear + set operation but
adds type checking and compile-time field boundary verification.

Hans Zhang (2):
  cpufreq/amd-pstate: Use FIELD_MODIFY()
  cpufreq: apple-soc: Use FIELD_MODIFY()

 drivers/cpufreq/amd-pstate.c        | 26 ++++++++++----------------
 drivers/cpufreq/apple-soc-cpufreq.c |  6 ++----
 2 files changed, 12 insertions(+), 20 deletions(-)


base-commit: 3b3bea6d4b9c162f9e555905d96b8c1da67ecd5b
-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] cpufreq/amd-pstate: Use FIELD_MODIFY()
  2026-04-30 16:32 [PATCH 0/2] *cpufreq: Use FIELD_MODIFY() for bitfield operations Hans Zhang
@ 2026-04-30 16:32 ` Hans Zhang
  2026-05-01  5:27   ` K Prateek Nayak
  2026-04-30 16:32 ` [PATCH 2/2] cpufreq: apple-soc: " Hans Zhang
  1 sibling, 1 reply; 5+ messages in thread
From: Hans Zhang @ 2026-04-30 16:32 UTC (permalink / raw)
  To: ray.huang, mario.limonciello, rafael, viresh.kumar, sven, j
  Cc: perry.yuan, kprateek.nayak, neal, linux-pm, asahi, linux-kernel,
	Hans Zhang

Use FIELD_MODIFY() to remove open-coded bit manipulation.
No functional change intended.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
 drivers/cpufreq/amd-pstate.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 453084c67327..1037d1722263 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -246,12 +246,10 @@ static int msr_update_perf(struct cpufreq_policy *policy, u8 min_perf,
 
 	value = prev = READ_ONCE(cpudata->cppc_req_cached);
 
-	value &= ~(AMD_CPPC_MAX_PERF_MASK | AMD_CPPC_MIN_PERF_MASK |
-		   AMD_CPPC_DES_PERF_MASK | AMD_CPPC_EPP_PERF_MASK);
-	value |= FIELD_PREP(AMD_CPPC_MAX_PERF_MASK, max_perf);
-	value |= FIELD_PREP(AMD_CPPC_DES_PERF_MASK, des_perf);
-	value |= FIELD_PREP(AMD_CPPC_MIN_PERF_MASK, min_perf);
-	value |= FIELD_PREP(AMD_CPPC_EPP_PERF_MASK, epp);
+	FIELD_MODIFY(AMD_CPPC_MAX_PERF_MASK, &value, max_perf);
+	FIELD_MODIFY(AMD_CPPC_DES_PERF_MASK, &value, des_perf);
+	FIELD_MODIFY(AMD_CPPC_MIN_PERF_MASK, &value, min_perf);
+	FIELD_MODIFY(AMD_CPPC_EPP_PERF_MASK, &value, epp);
 
 	if (trace_amd_pstate_epp_perf_enabled()) {
 		union perf_cached perf = READ_ONCE(cpudata->perf);
@@ -300,8 +298,7 @@ static int msr_set_epp(struct cpufreq_policy *policy, u8 epp)
 	int ret;
 
 	value = prev = READ_ONCE(cpudata->cppc_req_cached);
-	value &= ~AMD_CPPC_EPP_PERF_MASK;
-	value |= FIELD_PREP(AMD_CPPC_EPP_PERF_MASK, epp);
+	FIELD_MODIFY(AMD_CPPC_EPP_PERF_MASK, &value, epp);
 
 	if (trace_amd_pstate_epp_perf_enabled()) {
 		union perf_cached perf = cpudata->perf;
@@ -441,8 +438,7 @@ static int shmem_set_epp(struct cpufreq_policy *policy, u8 epp)
 	}
 
 	value = READ_ONCE(cpudata->cppc_req_cached);
-	value &= ~AMD_CPPC_EPP_PERF_MASK;
-	value |= FIELD_PREP(AMD_CPPC_EPP_PERF_MASK, epp);
+	FIELD_MODIFY(AMD_CPPC_EPP_PERF_MASK, &value, epp);
 	WRITE_ONCE(cpudata->cppc_req_cached, value);
 
 	return ret;
@@ -575,12 +571,10 @@ static int shmem_update_perf(struct cpufreq_policy *policy, u8 min_perf,
 
 	value = prev = READ_ONCE(cpudata->cppc_req_cached);
 
-	value &= ~(AMD_CPPC_MAX_PERF_MASK | AMD_CPPC_MIN_PERF_MASK |
-		   AMD_CPPC_DES_PERF_MASK | AMD_CPPC_EPP_PERF_MASK);
-	value |= FIELD_PREP(AMD_CPPC_MAX_PERF_MASK, max_perf);
-	value |= FIELD_PREP(AMD_CPPC_DES_PERF_MASK, des_perf);
-	value |= FIELD_PREP(AMD_CPPC_MIN_PERF_MASK, min_perf);
-	value |= FIELD_PREP(AMD_CPPC_EPP_PERF_MASK, epp);
+	FIELD_MODIFY(AMD_CPPC_MAX_PERF_MASK, &value, max_perf);
+	FIELD_MODIFY(AMD_CPPC_DES_PERF_MASK, &value, des_perf);
+	FIELD_MODIFY(AMD_CPPC_MIN_PERF_MASK, &value, min_perf);
+	FIELD_MODIFY(AMD_CPPC_EPP_PERF_MASK, &value, epp);
 
 	if (trace_amd_pstate_epp_perf_enabled()) {
 		union perf_cached perf = READ_ONCE(cpudata->perf);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] cpufreq: apple-soc: Use FIELD_MODIFY()
  2026-04-30 16:32 [PATCH 0/2] *cpufreq: Use FIELD_MODIFY() for bitfield operations Hans Zhang
  2026-04-30 16:32 ` [PATCH 1/2] cpufreq/amd-pstate: Use FIELD_MODIFY() Hans Zhang
@ 2026-04-30 16:32 ` Hans Zhang
  2026-04-30 19:54   ` Joshua Peisach
  1 sibling, 1 reply; 5+ messages in thread
From: Hans Zhang @ 2026-04-30 16:32 UTC (permalink / raw)
  To: ray.huang, mario.limonciello, rafael, viresh.kumar, sven, j
  Cc: perry.yuan, kprateek.nayak, neal, linux-pm, asahi, linux-kernel,
	Hans Zhang

Use FIELD_MODIFY() to remove open-coded bit manipulation.
No functional change intended.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
 drivers/cpufreq/apple-soc-cpufreq.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/cpufreq/apple-soc-cpufreq.c b/drivers/cpufreq/apple-soc-cpufreq.c
index 9396034167e5..638e5bf72185 100644
--- a/drivers/cpufreq/apple-soc-cpufreq.c
+++ b/drivers/cpufreq/apple-soc-cpufreq.c
@@ -187,10 +187,8 @@ static int apple_soc_cpufreq_set_target(struct cpufreq_policy *policy,
 
 	reg &= ~priv->info->ps1_mask;
 	reg |= pstate << priv->info->ps1_shift;
-	if (priv->info->has_ps2) {
-		reg &= ~APPLE_DVFS_CMD_PS2;
-		reg |= FIELD_PREP(APPLE_DVFS_CMD_PS2, pstate);
-	}
+	if (priv->info->has_ps2)
+		FIELD_MODIFY(APPLE_DVFS_CMD_PS2, &reg, pstate);
 	reg |= APPLE_DVFS_CMD_SET;
 
 	writeq_relaxed(reg, priv->reg_base + APPLE_DVFS_CMD);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] cpufreq: apple-soc: Use FIELD_MODIFY()
  2026-04-30 16:32 ` [PATCH 2/2] cpufreq: apple-soc: " Hans Zhang
@ 2026-04-30 19:54   ` Joshua Peisach
  0 siblings, 0 replies; 5+ messages in thread
From: Joshua Peisach @ 2026-04-30 19:54 UTC (permalink / raw)
  To: Hans Zhang, ray.huang, mario.limonciello, rafael, viresh.kumar,
	sven, j
  Cc: perry.yuan, kprateek.nayak, neal, linux-pm, asahi, linux-kernel

On Thu Apr 30, 2026 at 12:32 PM EDT, Hans Zhang wrote:
> Use FIELD_MODIFY() to remove open-coded bit manipulation.
> No functional change intended.
>
> Signed-off-by: Hans Zhang <18255117159@163.com>
> ---
>  drivers/cpufreq/apple-soc-cpufreq.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/cpufreq/apple-soc-cpufreq.c b/drivers/cpufreq/apple-soc-cpufreq.c
> index 9396034167e5..638e5bf72185 100644
> --- a/drivers/cpufreq/apple-soc-cpufreq.c
> +++ b/drivers/cpufreq/apple-soc-cpufreq.c
> @@ -187,10 +187,8 @@ static int apple_soc_cpufreq_set_target(struct cpufreq_policy *policy,
>  
>  	reg &= ~priv->info->ps1_mask;
>  	reg |= pstate << priv->info->ps1_shift;
> -	if (priv->info->has_ps2) {
> -		reg &= ~APPLE_DVFS_CMD_PS2;
> -		reg |= FIELD_PREP(APPLE_DVFS_CMD_PS2, pstate);
> -	}
> +	if (priv->info->has_ps2)
> +		FIELD_MODIFY(APPLE_DVFS_CMD_PS2, &reg, pstate);
>  	reg |= APPLE_DVFS_CMD_SET;
>  
>  	writeq_relaxed(reg, priv->reg_base + APPLE_DVFS_CMD);

Looks okay.

Reviewed-by: Joshua Peisach <jpeisach@ubuntu.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] cpufreq/amd-pstate: Use FIELD_MODIFY()
  2026-04-30 16:32 ` [PATCH 1/2] cpufreq/amd-pstate: Use FIELD_MODIFY() Hans Zhang
@ 2026-05-01  5:27   ` K Prateek Nayak
  0 siblings, 0 replies; 5+ messages in thread
From: K Prateek Nayak @ 2026-05-01  5:27 UTC (permalink / raw)
  To: Hans Zhang, ray.huang, mario.limonciello, rafael, viresh.kumar,
	sven, j
  Cc: perry.yuan, neal, linux-pm, asahi, linux-kernel

Hello Hans,

On 4/30/2026 10:02 PM, Hans Zhang wrote:
> Use FIELD_MODIFY() to remove open-coded bit manipulation.
> No functional change intended.
> 
> Signed-off-by: Hans Zhang <18255117159@163.com>

Thank you for cleaning this up! Feel free to include:

Reviewed-by: K Prateek Nayak <kprateek.nayak@amd.com>

-- 
Thanks and Regards,
Prateek

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-05-01  5:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-30 16:32 [PATCH 0/2] *cpufreq: Use FIELD_MODIFY() for bitfield operations Hans Zhang
2026-04-30 16:32 ` [PATCH 1/2] cpufreq/amd-pstate: Use FIELD_MODIFY() Hans Zhang
2026-05-01  5:27   ` K Prateek Nayak
2026-04-30 16:32 ` [PATCH 2/2] cpufreq: apple-soc: " Hans Zhang
2026-04-30 19:54   ` Joshua Peisach

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox