Skip to content

Commit a436ae9

Browse files
Liao Changrafaeljw
authored andcommitted
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 <liaochang1@huawei.com> [ rjw: Subject and changelog edits ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent d51847a commit a436ae9

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

include/linux/cpufreq.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/pm_qos.h>
2020
#include <linux/spinlock.h>
2121
#include <linux/sysfs.h>
22+
#include <linux/minmax.h>
2223

2324
/*********************************************************************
2425
* CPUFREQ INTERFACE *
@@ -467,17 +468,8 @@ static inline void cpufreq_verify_within_limits(struct cpufreq_policy_data *poli
467468
unsigned int min,
468469
unsigned int max)
469470
{
470-
if (policy->min < min)
471-
policy->min = min;
472-
if (policy->max < min)
473-
policy->max = min;
474-
if (policy->min > max)
475-
policy->min = max;
476-
if (policy->max > max)
477-
policy->max = max;
478-
if (policy->min > policy->max)
479-
policy->min = policy->max;
480-
return;
471+
policy->max = clamp(policy->max, min, max);
472+
policy->min = clamp(policy->min, min, policy->max);
481473
}
482474

483475
static inline void

0 commit comments

Comments
 (0)