aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@free.fr>2011-03-26 22:06:07 +0100
committerAmit Kucheria <amit.kucheria@linaro.org>2011-04-04 02:49:04 +0300
commit6e0c9c87cf38301f8dbf0b0f1ec9bf97dcb5fff6 (patch)
tree473ca4cde4ed41defdf6541361304b1da95dd236
parent897f73360a471a12bc522fdd22832891294d1ac7 (diff)
downloadpowerdebug-6e0c9c87cf38301f8dbf0b0f1ec9bf97dcb5fff6.tar.gz
Remove duplicate findparent variable
If we allocate a clock name, that means we can just check with the clock name pointer, no need of the findparent boolean. Signed-off-by: Daniel Lezcano <daniel.lezcano@free.fr> Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
-rw-r--r--powerdebug.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/powerdebug.c b/powerdebug.c
index 3832da6..7ef0a22 100644
--- a/powerdebug.c
+++ b/powerdebug.c
@@ -74,14 +74,13 @@ static struct option long_options[] = {
struct powerdebug_options {
bool verbose;
- bool findparent;
bool regulators;
bool sensors;
bool clocks;
bool dump;
unsigned int ticktime;
int selectedwindow;
- char *clkarg;
+ char *clkname;
};
int getoptions(int argc, char *argv[], struct powerdebug_options *options)
@@ -114,9 +113,8 @@ int getoptions(int argc, char *argv[], struct powerdebug_options *options)
options->selectedwindow = CLOCK;
break;
case 'p':
- options->findparent = true;
- options->clkarg = strdup(optarg);
- if (!options->clkarg) {
+ options->clkname = strdup(optarg);
+ if (!options->clkname) {
fprintf(stderr, "failed to allocate memory");
return -1;
}
@@ -332,8 +330,8 @@ static int powerdebug_dump(struct powerdebug_options *options,
if (options->clocks) {
init_clock_details(options->dump, options->selectedwindow);
- if (options->findparent)
- read_and_dump_clock_info_one(options->clkarg,
+ if (options->clkname)
+ read_and_dump_clock_info_one(options->clkname,
options->dump);
else
read_and_dump_clock_info(options->verbose);
@@ -345,20 +343,28 @@ static int powerdebug_dump(struct powerdebug_options *options,
return 0;
}
+static struct powerdebug_options *powerdebug_init(void)
+{
+ struct powerdebug_options *options;
+
+ options = malloc(sizeof(*options));
+ if (!options)
+ return NULL;
+
+ memset(options, 0, sizeof(*options));
+
+ return options;
+}
+
int main(int argc, char **argv)
{
struct powerdebug_options *options;
struct regulator_info *regulators_info;
int numregulators;
- options = malloc(sizeof(*options));
+ options = powerdebug_init();
if (!options) {
- fprintf(stderr, "failed to allocated memory\n");
- return -1;
- }
-
- if (getoptions(argc, argv, options)) {
- usage();
+ fprintf(stderr, "not enough memory to allocate options\n");
return 1;
}
@@ -368,6 +374,11 @@ int main(int argc, char **argv)
return 1;
}
+ if (getoptions(argc, argv, options)) {
+ usage();
+ return 1;
+ }
+
/* we just dump the informations */
if (options->dump) {
if (powerdebug_dump(options, regulators_info, numregulators))