lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240617060708.892981-4-tero.kristo@linux.intel.com>
Date: Mon, 17 Jun 2024 09:04:36 +0300
From: Tero Kristo <tero.kristo@...ux.intel.com>
To: hdegoede@...hat.com,
	srinivas.pandruvada@...ux.intel.com,
	ilpo.jarvinen@...ux.intel.com
Cc: linux-kernel@...r.kernel.org,
	platform-driver-x86@...r.kernel.org
Subject: [PATCH 3/7] platform/x86/intel-uncore-freq: Get rid of magic min_max argument

Get rid of the hardcoded / magic min_max argument from internal APIs.
Instead, use an enumerated index value for it.

No functional change intended.

Signed-off-by: Tero Kristo <tero.kristo@...ux.intel.com>
---
 .../uncore-frequency-common.c                 | 21 ++++++++++---------
 .../uncore-frequency-common.h                 |  8 ++++++-
 .../uncore-frequency/uncore-frequency-tpmi.c  | 18 +++++++++-------
 .../intel/uncore-frequency/uncore-frequency.c |  4 ++--
 4 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c
index 33bb58dc3f78..7daca46f9235 100644
--- a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c
+++ b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c
@@ -20,7 +20,7 @@ static DEFINE_IDA(intel_uncore_ida);
 
 /* callbacks for actual HW read/write */
 static int (*uncore_read)(struct uncore_data *data, unsigned int *min, unsigned int *max);
-static int (*uncore_write)(struct uncore_data *data, unsigned int input, unsigned int min_max);
+static int (*uncore_write)(struct uncore_data *data, unsigned int input, enum uncore_index index);
 static int (*uncore_read_freq)(struct uncore_data *data, unsigned int *freq);
 
 static ssize_t show_domain_id(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
@@ -45,7 +45,7 @@ static ssize_t show_package_id(struct kobject *kobj, struct kobj_attribute *attr
 }
 
 static ssize_t show_min_max_freq_khz(struct uncore_data *data,
-				      char *buf, int min_max)
+				      char *buf, enum uncore_index index)
 {
 	unsigned int min, max;
 	int ret;
@@ -56,7 +56,7 @@ static ssize_t show_min_max_freq_khz(struct uncore_data *data,
 	if (ret)
 		return ret;
 
-	if (min_max)
+	if (index == UNCORE_INDEX_MAX_FREQ)
 		return sprintf(buf, "%u\n", max);
 
 	return sprintf(buf, "%u\n", min);
@@ -64,7 +64,7 @@ static ssize_t show_min_max_freq_khz(struct uncore_data *data,
 
 static ssize_t store_min_max_freq_khz(struct uncore_data *data,
 				      const char *buf, ssize_t count,
-				      int min_max)
+				      enum uncore_index index)
 {
 	unsigned int input;
 	int ret;
@@ -73,7 +73,7 @@ static ssize_t store_min_max_freq_khz(struct uncore_data *data,
 		return -EINVAL;
 
 	mutex_lock(&uncore_lock);
-	ret = uncore_write(data, input, min_max);
+	ret = uncore_write(data, input, index);
 	mutex_unlock(&uncore_lock);
 
 	if (ret)
@@ -125,11 +125,11 @@ static ssize_t show_perf_status_freq_khz(struct uncore_data *data, char *buf)
 		return show_perf_status_freq_khz(data, buf); \
 	}
 
-store_uncore_min_max(min_freq_khz, 0);
-store_uncore_min_max(max_freq_khz, 1);
+store_uncore_min_max(min_freq_khz, UNCORE_INDEX_MIN_FREQ);
+store_uncore_min_max(max_freq_khz, UNCORE_INDEX_MAX_FREQ);
 
-show_uncore_min_max(min_freq_khz, 0);
-show_uncore_min_max(max_freq_khz, 1);
+show_uncore_min_max(min_freq_khz, UNCORE_INDEX_MIN_FREQ);
+show_uncore_min_max(max_freq_khz, UNCORE_INDEX_MAX_FREQ);
 
 show_uncore_perf_status(current_freq_khz);
 
@@ -270,7 +270,8 @@ void uncore_freq_remove_die_entry(struct uncore_data *data)
 EXPORT_SYMBOL_NS_GPL(uncore_freq_remove_die_entry, INTEL_UNCORE_FREQUENCY);
 
 int uncore_freq_common_init(int (*read_control_freq)(struct uncore_data *data, unsigned int *min, unsigned int *max),
-			     int (*write_control_freq)(struct uncore_data *data, unsigned int input, unsigned int set_max),
+			     int (*write_control_freq)(struct uncore_data *data, unsigned int input,
+						       enum uncore_index index),
 			     int (*read_freq)(struct uncore_data *data, unsigned int *freq))
 {
 	mutex_lock(&uncore_lock);
diff --git a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.h b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.h
index 0e5bf507e555..c6ceeda3f2bf 100644
--- a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.h
+++ b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.h
@@ -66,8 +66,14 @@ struct uncore_data {
 
 #define UNCORE_DOMAIN_ID_INVALID	-1
 
+enum uncore_index {
+	UNCORE_INDEX_MIN_FREQ,
+	UNCORE_INDEX_MAX_FREQ,
+};
+
 int uncore_freq_common_init(int (*read_control_freq)(struct uncore_data *data, unsigned int *min, unsigned int *max),
-			     int (*write_control_freq)(struct uncore_data *data, unsigned int input, unsigned int min_max),
+			     int (*write_control_freq)(struct uncore_data *data, unsigned int input,
+						       enum uncore_index index),
 			     int (*uncore_read_freq)(struct uncore_data *data, unsigned int *freq));
 void uncore_freq_common_exit(void);
 int uncore_freq_add_entry(struct uncore_data *data, int cpu);
diff --git a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-tpmi.c b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-tpmi.c
index b58294498921..c8e8c8087812 100644
--- a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-tpmi.c
+++ b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency-tpmi.c
@@ -130,13 +130,13 @@ static int uncore_read_control_freq(struct uncore_data *data, unsigned int *min,
 
 /* Helper function to write MMIO offset for max/min control frequency */
 static void write_control_freq(struct tpmi_uncore_cluster_info *cluster_info, unsigned int input,
-			      unsigned int min_max)
+			      unsigned int index)
 {
 	u64 control;
 
 	control = readq(cluster_info->cluster_base + UNCORE_CONTROL_INDEX);
 
-	if (min_max) {
+	if (index == UNCORE_INDEX_MAX_FREQ) {
 		control &= ~UNCORE_MAX_RATIO_MASK;
 		control |= FIELD_PREP(UNCORE_MAX_RATIO_MASK, input);
 	} else {
@@ -149,7 +149,7 @@ static void write_control_freq(struct tpmi_uncore_cluster_info *cluster_info, un
 
 /* Callback for sysfs write for max/min frequencies. Called under mutex locks */
 static int uncore_write_control_freq(struct uncore_data *data, unsigned int input,
-				     unsigned int min_max)
+				     enum uncore_index index)
 {
 	struct tpmi_uncore_cluster_info *cluster_info;
 	struct tpmi_uncore_struct *uncore_root;
@@ -174,10 +174,10 @@ static int uncore_write_control_freq(struct uncore_data *data, unsigned int inpu
 
 			for (j = 0; j < uncore_root->pd_info[i].cluster_count; ++j)
 				write_control_freq(&uncore_root->pd_info[i].cluster_infos[j],
-						  input, min_max);
+						  input, index);
 		}
 
-		if (min_max)
+		if (index == UNCORE_INDEX_MAX_FREQ)
 			uncore_root->max_ratio = input;
 		else
 			uncore_root->min_ratio = input;
@@ -185,13 +185,15 @@ static int uncore_write_control_freq(struct uncore_data *data, unsigned int inpu
 		return 0;
 	}
 
-	if (min_max && uncore_root->max_ratio && uncore_root->max_ratio < input)
+	if (index == UNCORE_INDEX_MAX_FREQ && uncore_root->max_ratio &&
+	    uncore_root->max_ratio < input)
 		return -EINVAL;
 
-	if (!min_max && uncore_root->min_ratio && uncore_root->min_ratio > input)
+	if (index == UNCORE_INDEX_MIN_FREQ && uncore_root->min_ratio &&
+	    uncore_root->min_ratio > input)
 		return -EINVAL;
 
-	write_control_freq(cluster_info, input, min_max);
+	write_control_freq(cluster_info, input, index);
 
 	return 0;
 }
diff --git a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c
index d3fdae695bbd..18ebd95080ed 100644
--- a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c
+++ b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c
@@ -62,7 +62,7 @@ static int uncore_read_control_freq(struct uncore_data *data, unsigned int *min,
 }
 
 static int uncore_write_control_freq(struct uncore_data *data, unsigned int input,
-				     unsigned int min_max)
+				     enum uncore_index index)
 {
 	int ret;
 	u64 cap;
@@ -78,7 +78,7 @@ static int uncore_write_control_freq(struct uncore_data *data, unsigned int inpu
 	if (ret)
 		return ret;
 
-	if (min_max) {
+	if (index == UNCORE_INDEX_MAX_FREQ) {
 		cap &= ~UNCORE_MAX_RATIO_MASK;
 		cap |= FIELD_PREP(UNCORE_MAX_RATIO_MASK, input);
 	} else  {
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ