create a specific function for display
In order to have the code more clear, let's create a function for the
display like what we did with the dump function.
Signed-off-by: Daniel Lezcano <daniel.lezcano@free.fr>
Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
diff --git a/powerdebug.c b/powerdebug.c
index 9874f5a..230155b 100644
--- a/powerdebug.c
+++ b/powerdebug.c
@@ -330,6 +330,20 @@
return 0;
}
+static int powerdebug_display(struct powerdebug_options *options,
+ struct regulator_info *reg_info, int nr_reg)
+{
+ if (display_init()) {
+ printf("failed to initialize display\n");
+ return -1;
+ }
+
+ if (mainloop(options, reg_info, nr_reg))
+ return -1;
+
+ return 0;
+}
+
static struct powerdebug_options *powerdebug_init(void)
{
struct powerdebug_options *options;
@@ -347,7 +361,7 @@
{
struct powerdebug_options *options;
struct regulator_info *regulators_info;
- int numregulators;
+ int numregulators, ret;
options = powerdebug_init();
if (!options) {
@@ -355,36 +369,25 @@
return 1;
}
+ if (getoptions(argc, argv, options)) {
+ usage();
+ return 1;
+ }
+
regulators_info = regulator_init(&numregulators);
if (!regulators_info) {
printf("not enough memory to allocate regulators info\n");
return 1;
}
- if (getoptions(argc, argv, options)) {
- usage();
- return 1;
- }
-
if (clock_init()) {
printf("failed to initialize clock details (check debugfs)\n");
options->clocks = false;
}
- /* we just dump the informations */
- if (options->dump) {
- if (powerdebug_dump(options, regulators_info, numregulators))
- return 1;
- return 0;
- }
+ ret = options->dump ?
+ powerdebug_dump(options, regulators_info, numregulators) :
+ powerdebug_display(options, regulators_info, numregulators);
- if (display_init()) {
- printf("failed to initialize display\n");
- return 1;
- }
-
- if (mainloop(options, regulators_info, numregulators))
- return 1;
-
- return 0;
+ return ret < 0;
}