Fix display error on screen
The previous patch was reverted and is replaced by this one.
Instead of dancing around with global flag telling if a subsys succeed
or not and write a error, let's try to initialize the subsystem each
time a display is requested and output an error occurs.
That makes the code a bit nicer and give the opportunity to fix the
problem at the system level (eg. mount debugfs) without restarting
powerdebug.
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
diff --git a/clocks.c b/clocks.c
index b57de3d..c115d8e 100644
--- a/clocks.c
+++ b/clocks.c
@@ -360,6 +360,39 @@
return 0;
}
+static int clock_info_load(void)
+{
+ char clk_dir_path[MAX+1][PATH_MAX];
+
+ if (clock_tree)
+ return 0;
+
+ if (locate_debugfs(clk_dir_path[CCF]) || locate_debugfs(clk_dir_path[OCF]))
+ return -1;
+
+ sprintf(clk_dir_path[CCF], "%s/clk", clk_dir_path[CCF]);
+ sprintf(clk_dir_path[OCF], "%s/clock", clk_dir_path[OCF]);
+ if (!access(clk_dir_path[CCF], F_OK)) {
+ clock_fw = CCF;
+ strcpy(clk_dir_path[MAX],clk_dir_path[CCF]);
+ }
+ else if(!access(clk_dir_path[OCF], F_OK)) {
+ clock_fw = OCF;
+ strcpy(clk_dir_path[MAX],clk_dir_path[OCF]);
+ }
+ else
+ return -1;
+
+ clock_tree = tree_load(clk_dir_path[MAX], NULL, false);
+ if (!clock_tree)
+ return -1;
+
+ if (fill_clock_tree())
+ return -1;
+
+ return 0;
+}
+
/*
* Read the clock information and fill the tree with the information
* found in the files. Then print the result to the text based interface
@@ -367,6 +400,12 @@
*/
static int clock_display(bool refresh)
{
+ if (clock_info_load()) {
+ display_print_error(CLOCK, 0, "Failed to read clock info");
+ return 0; /* we don't want this to be a critical error */
+ }
+
+
if (refresh && read_clock_info(clock_tree))
return -1;
@@ -449,33 +488,8 @@
*/
int clock_init(struct powerdebug_options *options)
{
- char clk_dir_path[MAX+1][PATH_MAX];
-
if (!(options->flags & CLOCK_OPTION))
return 0;
- if (locate_debugfs(clk_dir_path[CCF]) || locate_debugfs(clk_dir_path[OCF]))
- return -1;
-
- sprintf(clk_dir_path[CCF], "%s/clk", clk_dir_path[CCF]);
- sprintf(clk_dir_path[OCF], "%s/clock", clk_dir_path[OCF]);
- if (!access(clk_dir_path[CCF], F_OK)) {
- clock_fw = CCF;
- strcpy(clk_dir_path[MAX],clk_dir_path[CCF]);
- }
- else if(!access(clk_dir_path[OCF], F_OK)) {
- clock_fw = OCF;
- strcpy(clk_dir_path[MAX],clk_dir_path[OCF]);
- }
- else
- return -1;
-
- clock_tree = tree_load(clk_dir_path[MAX], NULL, false);
- if (!clock_tree)
- return -1;
-
- if (fill_clock_tree())
- return -1;
-
return display_register(CLOCK, &clock_ops);
}