diff options
author | Palmer Cox <p@lmercox.com> | 2012-11-27 13:17:46 +0100 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2012-11-27 23:07:19 +0100 |
commit | 35a169737cdf9155e890d60eae2b8fffc16d16ba (patch) | |
tree | d119819f5ef7ae6af01cb7d931538b77b4c8bff4 /tools/power/cpupower/utils/helpers/topology.c | |
parent | 53d2000ebe0618219f73ac866701533237180044 (diff) | |
download | op-kernel-dev-35a169737cdf9155e890d60eae2b8fffc16d16ba.zip op-kernel-dev-35a169737cdf9155e890d60eae2b8fffc16d16ba.tar.gz |
cpupower tools: Fix malloc of cpu_info structure
The cpu_info member of cpupower_topology was being declared as an unnamed
structure. This member was then being malloced using the size of the
parent cpupower_topology * the number of cpus. This works
because cpu_info is smaller than cpupower_topology. However, there is
no guarantee that will always be the case. Making cpu_info its own
top level structure (named cpuid_core_info) allows for mallocing the actual
size of this structure. This also lets us get rid of a redefinition of
the structure in topology.c with slightly different field names.
Signed-off-by: Palmer Cox <p@lmercox.com>
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'tools/power/cpupower/utils/helpers/topology.c')
-rw-r--r-- | tools/power/cpupower/utils/helpers/topology.c | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/tools/power/cpupower/utils/helpers/topology.c b/tools/power/cpupower/utils/helpers/topology.c index 216f3e3..4e2b583 100644 --- a/tools/power/cpupower/utils/helpers/topology.c +++ b/tools/power/cpupower/utils/helpers/topology.c @@ -36,14 +36,6 @@ static int sysfs_topology_read_file(unsigned int cpu, const char *fname, int *re return 0; } -struct cpuid_core_info { - unsigned int pkg; - unsigned int thread; - unsigned int cpu; - /* flags */ - unsigned int is_online:1; -}; - static int __compare(const void *t1, const void *t2) { struct cpuid_core_info *top1 = (struct cpuid_core_info *)t1; @@ -52,9 +44,9 @@ static int __compare(const void *t1, const void *t2) return -1; else if (top1->pkg > top2->pkg) return 1; - else if (top1->thread < top2->thread) + else if (top1->core < top2->core) return -1; - else if (top1->thread > top2->thread) + else if (top1->core > top2->core) return 1; else if (top1->cpu < top2->cpu) return -1; @@ -74,7 +66,7 @@ int get_cpu_topology(struct cpupower_topology *cpu_top) { int cpu, cpus = sysconf(_SC_NPROCESSORS_CONF); - cpu_top->core_info = malloc(sizeof(struct cpupower_topology) * cpus); + cpu_top->core_info = malloc(sizeof(struct cpuid_core_info) * cpus); if (cpu_top->core_info == NULL) return -ENOMEM; cpu_top->pkgs = cpu_top->cores = 0; |