cpufreq: Use clamp() helper macro to improve the code readability
authorLiao Chang <liaochang1@huawei.com>
Wed, 16 Aug 2023 01:58:53 +0000 (01:58 +0000)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 22 Aug 2023 20:10:10 +0000 (22:10 +0200)
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>
include/linux/cpufreq.h

index 172ff51c1b2a4b9f310943e78c44793ec5bd4f34..9bf94ae0815812c5cbd008790cde4feb150e9f1b 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/pm_qos.h>
 #include <linux/spinlock.h>
 #include <linux/sysfs.h>
+#include <linux/minmax.h>
 
 /*********************************************************************
  *                        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