summaryrefslogtreecommitdiff
path: root/tools/power
diff options
context:
space:
mode:
authorZhang Rui <rui.zhang@intel.com>2022-08-20 23:58:24 +0800
committerSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>2022-09-15 11:16:05 -0700
commit3ba6a27566a53030b3013f9f841ba5889a344cb8 (patch)
tree86f1d5ca83d57e792b2c478d812800ef5a8a6e20 /tools/power
parente616059ee6830242ffc68adc91a5486ac957dc1b (diff)
tools/power/x86/intel-speed-select: Enforce isst_id value
Enforce the pkg/die value in struct isst_id are either -1 or a valid value. This helps avoid inconsistent or redundant checks. Signed-off-by: Zhang Rui <rui.zhang@intel.com> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Diffstat (limited to 'tools/power')
-rw-r--r--tools/power/x86/intel-speed-select/isst-config.c12
-rw-r--r--tools/power/x86/intel-speed-select/isst-daemon.c2
2 files changed, 10 insertions, 4 deletions
diff --git a/tools/power/x86/intel-speed-select/isst-config.c b/tools/power/x86/intel-speed-select/isst-config.c
index a60b0893b4dc..f02de7e112f7 100644
--- a/tools/power/x86/intel-speed-select/isst-config.c
+++ b/tools/power/x86/intel-speed-select/isst-config.c
@@ -362,8 +362,14 @@ static int get_physical_die_id(int cpu)
void set_isst_id(struct isst_id *id, int cpu)
{
id->cpu = cpu;
+
id->pkg = get_physical_package_id(cpu);
+ if (id < 0 || id->pkg >= MAX_PACKAGE_COUNT)
+ id->pkg = -1;
+
id->die = get_physical_die_id(cpu);
+ if (id < 0 || id->die >= MAX_DIE_PER_PACKAGE)
+ id->die = -1;
}
int is_cpu_in_power_domain(int cpu, struct isst_id *id)
@@ -614,10 +620,10 @@ int get_max_punit_core_id(struct isst_id *id)
int get_cpu_count(struct isst_id *id)
{
- if (id->pkg < MAX_PACKAGE_COUNT && id->die < MAX_DIE_PER_PACKAGE)
- return cpu_cnt[id->pkg][id->die];
+ if (id->pkg < 0 || id->die < 0)
+ return 0;
- return 0;
+ return cpu_cnt[id->pkg][id->die];
}
static void set_cpu_target_cpu_mask(void)
diff --git a/tools/power/x86/intel-speed-select/isst-daemon.c b/tools/power/x86/intel-speed-select/isst-daemon.c
index c5d978ecc443..0699137c0901 100644
--- a/tools/power/x86/intel-speed-select/isst-daemon.c
+++ b/tools/power/x86/intel-speed-select/isst-daemon.c
@@ -39,7 +39,7 @@ void process_level_change(struct isst_id *id)
time_t tm;
int ret;
- if (id->pkg >= MAX_PACKAGE_COUNT || id->die >= MAX_DIE_PER_PACKAGE) {
+ if (id->pkg < 0 || id->die < 0) {
debug_printf("Invalid package/die info for cpu:%d\n", id->cpu);
return;
}