From: Liao Chang Date: Wed, 16 Aug 2023 01:58:53 +0000 (+0000) Subject: cpufreq: Use clamp() helper macro to improve the code readability X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=a436ae9434ec491eefb4ed4c77bdb9c762925976;p=linux.git cpufreq: Use clamp() helper macro to improve the code readability The valid values of policy.{min, max} should be between 'min' and 'max', so use clamp() helper macro to makes cpufreq_verify_within_limits() easier to follow. Signed-off-by: Liao Chang [ rjw: Subject and changelog edits ] Signed-off-by: Rafael J. Wysocki --- diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 172ff51c1b2a4..9bf94ae081581 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -19,6 +19,7 @@ #include #include #include +#include /********************************************************************* * CPUFREQ INTERFACE * @@ -467,17 +468,8 @@ static inline void cpufreq_verify_within_limits(struct cpufreq_policy_data *poli unsigned int min, unsigned int max) { - if (policy->min < min) - policy->min = min; - if (policy->max < min) - policy->max = min; - if (policy->min > max) - policy->min = max; - if (policy->max > max) - policy->max = max; - if (policy->min > policy->max) - policy->min = policy->max; - return; + policy->max = clamp(policy->max, min, max); + policy->min = clamp(policy->min, min, policy->max); } static inline void