[PATCH] cpufreq: Replace magic number

Bowen Yu posted 1 patch 7 months ago
drivers/cpufreq/cpufreq.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] cpufreq: Replace magic number
Posted by Bowen Yu 7 months ago
Setting the length of str_governor with a magic number could cause
overflow when max length increases, it is better to use the defined
macro in this case.

Signed-off-by: Bowen Yu <yubowen8@huawei.com>
---
 drivers/cpufreq/cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 0c842edd1a76..a3a376f030f0 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -809,7 +809,7 @@ static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
 static ssize_t store_scaling_governor(struct cpufreq_policy *policy,
 					const char *buf, size_t count)
 {
-	char str_governor[16];
+	char str_governor[CPUFREQ_NAME_LEN];
 	int ret;
 
 	ret = sscanf(buf, "%15s", str_governor);
-- 
2.33.0
Re: [PATCH] cpufreq: Replace magic number
Posted by Viresh Kumar 7 months ago
On 19-05-25, 15:09, Bowen Yu wrote:
> Setting the length of str_governor with a magic number could cause
> overflow when max length increases, it is better to use the defined
> macro in this case.
> 
> Signed-off-by: Bowen Yu <yubowen8@huawei.com>
> ---
>  drivers/cpufreq/cpufreq.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 0c842edd1a76..a3a376f030f0 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -809,7 +809,7 @@ static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
>  static ssize_t store_scaling_governor(struct cpufreq_policy *policy,
>  					const char *buf, size_t count)
>  {
> -	char str_governor[16];
> +	char str_governor[CPUFREQ_NAME_LEN];
>  	int ret;
>  
>  	ret = sscanf(buf, "%15s", str_governor);

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh
Re: [PATCH] cpufreq: Replace magic number
Posted by Rafael J. Wysocki 7 months ago
On Mon, May 19, 2025 at 12:02 PM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> On 19-05-25, 15:09, Bowen Yu wrote:
> > Setting the length of str_governor with a magic number could cause
> > overflow when max length increases, it is better to use the defined
> > macro in this case.
> >
> > Signed-off-by: Bowen Yu <yubowen8@huawei.com>
> > ---
> >  drivers/cpufreq/cpufreq.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> > index 0c842edd1a76..a3a376f030f0 100644
> > --- a/drivers/cpufreq/cpufreq.c
> > +++ b/drivers/cpufreq/cpufreq.c
> > @@ -809,7 +809,7 @@ static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
> >  static ssize_t store_scaling_governor(struct cpufreq_policy *policy,
> >                                       const char *buf, size_t count)
> >  {
> > -     char str_governor[16];
> > +     char str_governor[CPUFREQ_NAME_LEN];
> >       int ret;
> >
> >       ret = sscanf(buf, "%15s", str_governor);
>
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

Applied as 6.16 material, thanks!