diff mbox

[v2,10/21] cpufreq: intel_pstate: use match_string() helper

Message ID 1527765086-19873-11-git-send-email-xieyisheng1@huawei.com (mailing list archive)
State Mainlined
Delegated to: Rafael Wysocki
Headers show

Commit Message

Xie Yisheng May 31, 2018, 11:11 a.m. UTC
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Cc: Len Brown <lenb@kernel.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: linux-pm@vger.kernel.org
Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
---
v2:
 - add Reviewed-by tag.

 drivers/cpufreq/intel_pstate.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

Comments

Rafael J. Wysocki June 26, 2018, 3:23 p.m. UTC | #1
On Thursday, May 31, 2018 1:11:15 PM CEST Yisheng Xie wrote:
> match_string() returns the index of an array for a matching string,
> which can be used instead of open coded variant.
> 
> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> Cc: Len Brown <lenb@kernel.org>
> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> Cc: Viresh Kumar <viresh.kumar@linaro.org>
> Cc: linux-pm@vger.kernel.org
> Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
> ---
> v2:
>  - add Reviewed-by tag.
> 
>  drivers/cpufreq/intel_pstate.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
> index 17e566af..d701e26 100644
> --- a/drivers/cpufreq/intel_pstate.c
> +++ b/drivers/cpufreq/intel_pstate.c
> @@ -645,21 +645,18 @@ static ssize_t store_energy_performance_preference(
>  {
>  	struct cpudata *cpu_data = all_cpu_data[policy->cpu];
>  	char str_preference[21];
> -	int ret, i = 0;
> +	int ret;
>  
>  	ret = sscanf(buf, "%20s", str_preference);
>  	if (ret != 1)
>  		return -EINVAL;
>  
> -	while (energy_perf_strings[i] != NULL) {
> -		if (!strcmp(str_preference, energy_perf_strings[i])) {
> -			intel_pstate_set_energy_pref_index(cpu_data, i);
> -			return count;
> -		}
> -		++i;
> -	}
> +	ret = match_string(energy_perf_strings, -1, str_preference);
> +	if (ret < 0)
> +		return ret;
>  
> -	return -EINVAL;
> +	intel_pstate_set_energy_pref_index(cpu_data, ret);
> +	return count;
>  }
>  
>  static ssize_t show_energy_performance_preference(
> 

Srinivas, any concerns?
Srinivas Pandruvada June 26, 2018, 11:56 p.m. UTC | #2
On Tue, 2018-06-26 at 17:23 +0200, Rafael J. Wysocki wrote:
> On Thursday, May 31, 2018 1:11:15 PM CEST Yisheng Xie wrote:
> > match_string() returns the index of an array for a matching string,
> > which can be used instead of open coded variant.
> > 
> > Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>

> > Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> > Cc: Len Brown <lenb@kernel.org>
> > Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> > Cc: Viresh Kumar <viresh.kumar@linaro.org>
> > Cc: linux-pm@vger.kernel.org
> > Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
> > ---
> > v2:
> >  - add Reviewed-by tag.
> > 
> >  drivers/cpufreq/intel_pstate.c | 15 ++++++---------
> >  1 file changed, 6 insertions(+), 9 deletions(-)
> > performance
> > diff --git a/drivers/cpufreq/intel_pstate.c
> > b/drivers/cpufreq/intel_pstate.c
> > index 17e566af..d701e26 100644
> > --- a/drivers/cpufreq/intel_pstate.c
> > +++ b/drivers/cpufreq/intel_pstate.c
> > @@ -645,21 +645,18 @@ static ssize_t
> > store_energy_performance_preference(
> >  {
> >  	struct cpudata *cpu_data = all_cpu_data[policy->cpu];
> >  	char str_preference[21];
> > -	int ret, i = 0;
> > +	int ret;
> >  
> >  	ret = sscanf(buf, "%20s", str_preference);
> >  	if (ret != 1)
> >  		return -EINVAL;
> >  
> > -	while (energy_perf_strings[i] != NULL) {
> > -		if (!strcmp(str_preference,
> > energy_perf_strings[i])) {
> > -			intel_pstate_set_energy_pref_index(cpu_dat
> > a, i);
> > -			return count;
> > -		}
> > -		++i;
> > -	}
> > +	ret = match_string(energy_perf_strings, -1,
> > str_preference);
> > +	if (ret < 0)
> > +		return ret;
> >  
> > -	return -EINVAL;
> > +	intel_pstate_set_energy_pref_index(cpu_data, ret);
> > +	return count;
> >  }
> >  
> >  static ssize_t show_energy_performance_preference(
> > 
> 
> Srinivas, any concerns?
>
Rafael J. Wysocki July 4, 2018, 10:52 a.m. UTC | #3
On Wednesday, June 27, 2018 1:56:30 AM CEST Srinivas Pandruvada wrote:
> On Tue, 2018-06-26 at 17:23 +0200, Rafael J. Wysocki wrote:
> > On Thursday, May 31, 2018 1:11:15 PM CEST Yisheng Xie wrote:
> > > match_string() returns the index of an array for a matching string,
> > > which can be used instead of open coded variant.
> > > 
> > > Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>

Patch applied, thanks!
diff mbox

Patch

diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 17e566af..d701e26 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -645,21 +645,18 @@  static ssize_t store_energy_performance_preference(
 {
 	struct cpudata *cpu_data = all_cpu_data[policy->cpu];
 	char str_preference[21];
-	int ret, i = 0;
+	int ret;
 
 	ret = sscanf(buf, "%20s", str_preference);
 	if (ret != 1)
 		return -EINVAL;
 
-	while (energy_perf_strings[i] != NULL) {
-		if (!strcmp(str_preference, energy_perf_strings[i])) {
-			intel_pstate_set_energy_pref_index(cpu_data, i);
-			return count;
-		}
-		++i;
-	}
+	ret = match_string(energy_perf_strings, -1, str_preference);
+	if (ret < 0)
+		return ret;
 
-	return -EINVAL;
+	intel_pstate_set_energy_pref_index(cpu_data, ret);
+	return count;
 }
 
 static ssize_t show_energy_performance_preference(