From: Thomas Renninger <trenn@suse.de>
To: cpufreq@vger.kernel.org
Cc: Palmer Cox <p@lmercox.com>,
linux@dominikbrodowski.net, rjw@sisk.pl,
Thomas Renninger <trenn@suse.de>
Subject: [PATCH 5/8] cpupower tools: Fix malloc of cpu_info structure
Date: Tue, 9 Oct 2012 15:21:04 +0200 [thread overview]
Message-ID: <1349788867-65962-6-git-send-email-trenn@suse.de> (raw)
In-Reply-To: <1349788867-65962-1-git-send-email-trenn@suse.de>
From: Palmer Cox <p@lmercox.com>
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>
---
tools/power/cpupower/utils/helpers/helpers.h | 17 +++++++++--------
tools/power/cpupower/utils/helpers/topology.c | 14 +++-----------
2 files changed, 12 insertions(+), 19 deletions(-)
diff --git a/tools/power/cpupower/utils/helpers/helpers.h b/tools/power/cpupower/utils/helpers/helpers.h
index 2eb584c..f84985f 100644
--- a/tools/power/cpupower/utils/helpers/helpers.h
+++ b/tools/power/cpupower/utils/helpers/helpers.h
@@ -92,6 +92,14 @@ extern int get_cpu_info(unsigned int cpu, struct cpupower_cpu_info *cpu_info);
extern struct cpupower_cpu_info cpupower_cpu_info;
/* cpuid and cpuinfo helpers **************************/
+struct cpuid_core_info {
+ int pkg;
+ int core;
+ int cpu;
+
+ /* flags */
+ unsigned int is_online:1;
+};
/* CPU topology/hierarchy parsing ******************/
struct cpupower_topology {
@@ -101,14 +109,7 @@ struct cpupower_topology {
unsigned int threads; /* per core */
/* Array gets mallocated with cores entries, holding per core info */
- struct {
- int pkg;
- int core;
- int cpu;
-
- /* flags */
- unsigned int is_online:1;
- } *core_info;
+ struct cpuid_core_info *core_info;
};
extern int get_cpu_topology(struct cpupower_topology *cpu_top);
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;
--
1.7.6.1
next prev parent reply other threads:[~2012-10-09 13:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-09 13:20 [PATCH 0/8] cpupower enhancements for 3.7 Thomas Renninger
2012-10-09 13:21 ` [PATCH 1/8] cpupower tools: Remove brace expansion from clean target Thomas Renninger
2012-10-09 13:21 ` [PATCH 2/8] cpupower tools: Update .gitignore for files created in the debug directories Thomas Renninger
2012-10-09 13:21 ` [PATCH 3/8] cpupower tools: Fix minor warnings Thomas Renninger
2012-10-09 13:21 ` [PATCH 4/8] cpupower tools: Fix issues with sysfs_topology_read_file Thomas Renninger
2012-10-09 13:21 ` Thomas Renninger [this message]
2012-10-09 13:21 ` [PATCH 6/8] cpupower tools: Fix warning and a bug with the cpu package count Thomas Renninger
2012-10-09 13:21 ` [PATCH 7/8] cpupower: Provide -c param for cpupower monitor to schedule process on all cores Thomas Renninger
2012-10-09 13:21 ` [PATCH 8/8] patch cpupower_ivy_bridge_support.patch Thomas Renninger
2012-11-24 9:49 ` Rafael J. Wysocki
2012-11-26 15:46 ` Thomas Renninger
2012-11-26 20:49 ` Rafael J. Wysocki
-- strict thread matches above, loose matches on Subject: below --
2012-11-27 12:17 [PATCH 0/8] cpupower enhancements for 3.8 Thomas Renninger
2012-11-27 12:17 ` [PATCH 5/8] cpupower tools: Fix malloc of cpu_info structure Thomas Renninger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1349788867-65962-6-git-send-email-trenn@suse.de \
--to=trenn@suse.de \
--cc=cpufreq@vger.kernel.org \
--cc=linux@dominikbrodowski.net \
--cc=p@lmercox.com \
--cc=rjw@sisk.pl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).