public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cpufreq/amd-pstate: Use sysfs_match_string() for epp
@ 2025-09-24 17:50 Mario Limonciello (AMD)
  2025-10-09  4:32 ` Gautham R. Shenoy
  0 siblings, 1 reply; 2+ messages in thread
From: Mario Limonciello (AMD) @ 2025-09-24 17:50 UTC (permalink / raw)
  To: Gautham R . Shenoy
  Cc: Perry Yuan, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:CPU FREQUENCY SCALING FRAMEWORK, Mario Limonciello

Rather than scanning the buffer and manually matching the string
use the sysfs macros.

Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
---
 drivers/cpufreq/amd-pstate.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index ba2adea03db1..b8af6cad9e2c 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -1157,15 +1157,10 @@ static ssize_t store_energy_performance_preference(
 		struct cpufreq_policy *policy, const char *buf, size_t count)
 {
 	struct amd_cpudata *cpudata = policy->driver_data;
-	char str_preference[21];
 	ssize_t ret;
 	u8 epp;
 
-	ret = sscanf(buf, "%20s", str_preference);
-	if (ret != 1)
-		return -EINVAL;
-
-	ret = match_string(energy_perf_strings, -1, str_preference);
+	ret = sysfs_match_string(energy_perf_strings, buf);
 	if (ret < 0)
 		return -EINVAL;
 
-- 
2.51.0


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

* Re: [PATCH] cpufreq/amd-pstate: Use sysfs_match_string() for epp
  2025-09-24 17:50 [PATCH] cpufreq/amd-pstate: Use sysfs_match_string() for epp Mario Limonciello (AMD)
@ 2025-10-09  4:32 ` Gautham R. Shenoy
  0 siblings, 0 replies; 2+ messages in thread
From: Gautham R. Shenoy @ 2025-10-09  4:32 UTC (permalink / raw)
  To: Mario Limonciello (AMD)
  Cc: Perry Yuan, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:CPU FREQUENCY SCALING FRAMEWORK

Hello Mario,

On Wed, Sep 24, 2025 at 12:50:16PM -0500, Mario Limonciello (AMD) wrote:
> Rather than scanning the buffer and manually matching the string
> use the sysfs macros.

This is a nice optimization.

While at it, would it be possible to get rid of the "NULL" entry from
the energy_perf_strings array ?

Something like the following in addition to the change in your patch?

--------------x8---------------------------x8----------------------------
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 34835681be92..bd022dd21a4a 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -117,8 +117,7 @@ static const char * const energy_perf_strings[] = {
        [EPP_INDEX_PERFORMANCE] = "performance",
        [EPP_INDEX_BALANCE_PERFORMANCE] = "balance_performance",
        [EPP_INDEX_BALANCE_POWERSAVE] = "balance_power",
-       [EPP_INDEX_POWERSAVE] = "power",
-       NULL
+       [EPP_INDEX_POWERSAVE] = "power"
 };
 
 static unsigned int epp_values[] = {
@@ -1180,7 +1179,7 @@ static ssize_t show_energy_performance_available_preferences(
                return sysfs_emit_at(buf, offset, "%s\n",
                                energy_perf_strings[EPP_INDEX_PERFORMANCE]);
 
-       while (energy_perf_strings[i] != NULL)
+       for (i = 0; i < ARRAY_SIZE(energy_perf_strings); i++)
                offset += sysfs_emit_at(buf, offset, "%s ", energy_perf_strings[i++]);
 
        offset += sysfs_emit_at(buf, offset, "\n");
--------------x8---------------------------x8----------------------------

> 
> Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
> ---
>  drivers/cpufreq/amd-pstate.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index ba2adea03db1..b8af6cad9e2c 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -1157,15 +1157,10 @@ static ssize_t store_energy_performance_preference(
>  		struct cpufreq_policy *policy, const char *buf, size_t count)
>  {
>  	struct amd_cpudata *cpudata = policy->driver_data;
> -	char str_preference[21];
>  	ssize_t ret;
>  	u8 epp;
>  
> -	ret = sscanf(buf, "%20s", str_preference);
> -	if (ret != 1)
> -		return -EINVAL;
> -
> -	ret = match_string(energy_perf_strings, -1, str_preference);
> +	ret = sysfs_match_string(energy_perf_strings, buf);
>  	if (ret < 0)
>  		return -EINVAL;
>  
> -- 
> 2.51.0
> 

-- 
Thanks and Regards
gautham.

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

end of thread, other threads:[~2025-10-09  4:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-24 17:50 [PATCH] cpufreq/amd-pstate: Use sysfs_match_string() for epp Mario Limonciello (AMD)
2025-10-09  4:32 ` Gautham R. Shenoy

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