diff mbox series

[v3,04/21] selftests/resctrl: Declare global variables as extern

Message ID 20201020235126.1871815-5-fenghua.yu@intel.com
State New
Headers show
Series Miscellaneous fixes for resctrl selftests | expand

Commit Message

Fenghua Yu Oct. 20, 2020, 11:51 p.m. UTC
resctrl test suite uses global variables (E.g: bm_pid, ppid, llc_occup_path
and is_amd) that are used across .c files. These global variables are
defined in resctrl.h file and the header file is included in .c files where
needed. Sparse tool isn't very happy about defining global variables in .h
file and hence complains as below

resctrl.h:65:7: warning: symbol 'bm_pid' was not declared.
		Should it be static?
resctrl.h:65:15: warning: symbol 'ppid' was not declared.
		 Should it be static?
resctrl.h:66:5: warning: symbol 'tests_run' was not declared.
		Should it be static?
resctrl.h:68:6: warning: symbol 'llc_occup_path' was not declared.
		Should it be static?
resctrl.h:69:6: warning: symbol 'is_amd' was not declared.
		Should it be static?

Sparse tool thinks that since the variables are defined and not declared,
it assumes that the scope of these variables is limited to a .c file and
hence suggests making them static variables. But these variables are used
across .c files and hence cannot be static variables.

Fix these warnings by declaring the variables (i.e. use extern keyword)
rather than defining them in resctrl.h file.

Please note that sparse tool still complains about other issues and they
will be fixed in later patches.

Fixes: 591a6e8588fc ("selftests/resctrl: Add basic resctrl file
system operations and data")
Reported-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
---
 tools/testing/selftests/resctrl/resctrl.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h
index 68522b19b235..814d0dd517a4 100644
--- a/tools/testing/selftests/resctrl/resctrl.h
+++ b/tools/testing/selftests/resctrl/resctrl.h
@@ -62,11 +62,11 @@  struct resctrl_val_param {
 	int		(*setup)(int num, ...);
 };
 
-pid_t bm_pid, ppid;
-int tests_run;
+extern pid_t bm_pid, ppid;
+extern int tests_run;
 
-char llc_occup_path[1024];
-bool is_amd;
+extern char llc_occup_path[1024];
+extern bool is_amd;
 
 bool check_resctrlfs_support(void);
 int filter_dmesg(void);