* [PATCH v3 0/2] cpufreq: Cleanups and minor fixes
@ 2025-08-22 7:04 Zihuan Zhang
2025-08-22 7:04 ` [PATCH v3 1/2] cpufreq: use strlen() for governor name comparison Zihuan Zhang
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Zihuan Zhang @ 2025-08-22 7:04 UTC (permalink / raw)
To: rafael J . wysocki, Viresh Kumar
Cc: zhenglifeng, linux-pm, linux-kernel, Zihuan Zhang
This series contains two small cpufreq cleanups:
1) Use strlen() as the length argument for strncasecmp() in
cpufreq_parse_policy(). This makes comparison more permissive
(prefix match), which is consistent with the intention in our
deployment and improves readability over using CPUFREQ_NAME_LEN.
2) The second patch is new in this version. It simplifies the validation
logic in cpufreq_register_driver().This makes the registration code
more straightforward without changing functionality.
Changes since v2:
- Fix code suggested by Viresh Kumar
Changes since v1:
- Dropped the second patch from v1, which was not needed.
- Kept the first patch as-is (already Acked).
- Added a new second patch to simplify driver registration checks
Zihuan Zhang (2):
cpufreq: use strlen() for governor name comparison
cpufreq: simplify setpolicy/target check in driver verification
drivers/cpufreq/cpufreq.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 1/2] cpufreq: use strlen() for governor name comparison
2025-08-22 7:04 [PATCH v3 0/2] cpufreq: Cleanups and minor fixes Zihuan Zhang
@ 2025-08-22 7:04 ` Zihuan Zhang
2025-08-22 7:04 ` [PATCH v3 2/2] cpufreq: simplify setpolicy/target check in driver verification Zihuan Zhang
2025-08-22 19:35 ` [PATCH v3 0/2] cpufreq: Cleanups and minor fixes Rafael J. Wysocki
2 siblings, 0 replies; 5+ messages in thread
From: Zihuan Zhang @ 2025-08-22 7:04 UTC (permalink / raw)
To: rafael J . wysocki, Viresh Kumar
Cc: zhenglifeng, linux-pm, linux-kernel, Zihuan Zhang
Most kernel code using strncasecmp()/strncmp() passes strlen("xxx")
as the length argument. cpufreq_parse_policy() previously used
CPUFREQ_NAME_LEN (16), which is longer than the actual strings
("performance" is 11 chars, "powersave" is 9 chars).
This patch switches to strlen() for the comparison, making the
matching slightly more permissive (e.g., "powersavexxx" will now
also match "powersave"). While this is unlikely to cause functional
issues, it aligns cpufreq with common kernel style and makes the
behavior more intuitive.
Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
---
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 fc7eace8b65b..a067b5447fe8 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -664,10 +664,10 @@ static struct cpufreq_governor *get_governor(const char *str_governor)
static unsigned int cpufreq_parse_policy(char *str_governor)
{
- if (!strncasecmp(str_governor, "performance", CPUFREQ_NAME_LEN))
+ if (!strncasecmp(str_governor, "performance", strlen("performance")))
return CPUFREQ_POLICY_PERFORMANCE;
- if (!strncasecmp(str_governor, "powersave", CPUFREQ_NAME_LEN))
+ if (!strncasecmp(str_governor, "powersave", strlen("powersave")))
return CPUFREQ_POLICY_POWERSAVE;
return CPUFREQ_POLICY_UNKNOWN;
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 2/2] cpufreq: simplify setpolicy/target check in driver verification
2025-08-22 7:04 [PATCH v3 0/2] cpufreq: Cleanups and minor fixes Zihuan Zhang
2025-08-22 7:04 ` [PATCH v3 1/2] cpufreq: use strlen() for governor name comparison Zihuan Zhang
@ 2025-08-22 7:04 ` Zihuan Zhang
2025-08-22 7:16 ` Viresh Kumar
2025-08-22 19:35 ` [PATCH v3 0/2] cpufreq: Cleanups and minor fixes Rafael J. Wysocki
2 siblings, 1 reply; 5+ messages in thread
From: Zihuan Zhang @ 2025-08-22 7:04 UTC (permalink / raw)
To: rafael J . wysocki, Viresh Kumar
Cc: zhenglifeng, linux-pm, linux-kernel, Zihuan Zhang
Cpufreq drivers are supposed to use either ->setpolicy or
->target/->target_index. This patch simplifies the existing check by
collapsing it into a single boolean expression:
(!!driver->setpolicy == (driver->target_index || driver->target))
This is a readability/maintainability cleanup and keeps the semantics
unchanged.
No functional change intended.
Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>
---
drivers/cpufreq/cpufreq.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index a067b5447fe8..633be16297d6 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2921,10 +2921,7 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
return -EPROBE_DEFER;
if (!driver_data || !driver_data->verify || !driver_data->init ||
- !(driver_data->setpolicy || driver_data->target_index ||
- driver_data->target) ||
- (driver_data->setpolicy && (driver_data->target_index ||
- driver_data->target)) ||
+ (!!driver_data->setpolicy == (driver_data->target_index || driver_data->target)) ||
(!driver_data->get_intermediate != !driver_data->target_intermediate) ||
(!driver_data->online != !driver_data->offline) ||
(driver_data->adjust_perf && !driver_data->fast_switch))
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 2/2] cpufreq: simplify setpolicy/target check in driver verification
2025-08-22 7:04 ` [PATCH v3 2/2] cpufreq: simplify setpolicy/target check in driver verification Zihuan Zhang
@ 2025-08-22 7:16 ` Viresh Kumar
0 siblings, 0 replies; 5+ messages in thread
From: Viresh Kumar @ 2025-08-22 7:16 UTC (permalink / raw)
To: Zihuan Zhang; +Cc: rafael J . wysocki, zhenglifeng, linux-pm, linux-kernel
On 22-08-25, 15:04, Zihuan Zhang wrote:
> Cpufreq drivers are supposed to use either ->setpolicy or
> ->target/->target_index. This patch simplifies the existing check by
> collapsing it into a single boolean expression:
>
> (!!driver->setpolicy == (driver->target_index || driver->target))
>
> This is a readability/maintainability cleanup and keeps the semantics
> unchanged.
>
> No functional change intended.
>
> Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>
> ---
> drivers/cpufreq/cpufreq.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index a067b5447fe8..633be16297d6 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -2921,10 +2921,7 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
> return -EPROBE_DEFER;
>
> if (!driver_data || !driver_data->verify || !driver_data->init ||
> - !(driver_data->setpolicy || driver_data->target_index ||
> - driver_data->target) ||
> - (driver_data->setpolicy && (driver_data->target_index ||
> - driver_data->target)) ||
> + (!!driver_data->setpolicy == (driver_data->target_index || driver_data->target)) ||
> (!driver_data->get_intermediate != !driver_data->target_intermediate) ||
> (!driver_data->online != !driver_data->offline) ||
> (driver_data->adjust_perf && !driver_data->fast_switch))
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
--
viresh
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 0/2] cpufreq: Cleanups and minor fixes
2025-08-22 7:04 [PATCH v3 0/2] cpufreq: Cleanups and minor fixes Zihuan Zhang
2025-08-22 7:04 ` [PATCH v3 1/2] cpufreq: use strlen() for governor name comparison Zihuan Zhang
2025-08-22 7:04 ` [PATCH v3 2/2] cpufreq: simplify setpolicy/target check in driver verification Zihuan Zhang
@ 2025-08-22 19:35 ` Rafael J. Wysocki
2 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2025-08-22 19:35 UTC (permalink / raw)
To: Zihuan Zhang
Cc: rafael J . wysocki, Viresh Kumar, zhenglifeng, linux-pm,
linux-kernel
On Fri, Aug 22, 2025 at 9:04 AM Zihuan Zhang <zhangzihuan@kylinos.cn> wrote:
>
> This series contains two small cpufreq cleanups:
>
> 1) Use strlen() as the length argument for strncasecmp() in
> cpufreq_parse_policy(). This makes comparison more permissive
> (prefix match), which is consistent with the intention in our
> deployment and improves readability over using CPUFREQ_NAME_LEN.
>
> 2) The second patch is new in this version. It simplifies the validation
> logic in cpufreq_register_driver().This makes the registration code
> more straightforward without changing functionality.
>
> Changes since v2:
> - Fix code suggested by Viresh Kumar
>
> Changes since v1:
> - Dropped the second patch from v1, which was not needed.
> - Kept the first patch as-is (already Acked).
> - Added a new second patch to simplify driver registration checks
>
> Zihuan Zhang (2):
> cpufreq: use strlen() for governor name comparison
> cpufreq: simplify setpolicy/target check in driver verification
>
> drivers/cpufreq/cpufreq.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
>
> --
Both patches applied as 6.18 material, thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-22 19:35 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-22 7:04 [PATCH v3 0/2] cpufreq: Cleanups and minor fixes Zihuan Zhang
2025-08-22 7:04 ` [PATCH v3 1/2] cpufreq: use strlen() for governor name comparison Zihuan Zhang
2025-08-22 7:04 ` [PATCH v3 2/2] cpufreq: simplify setpolicy/target check in driver verification Zihuan Zhang
2025-08-22 7:16 ` Viresh Kumar
2025-08-22 19:35 ` [PATCH v3 0/2] cpufreq: Cleanups and minor fixes Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).