Skip to content

Commit 25e713c

Browse files
Patryk Wlazlynlenb
authored andcommitted
tools/power turbostat: Add ZERO_ARRAY for zero initializing builtin array
It makes it harder to shoot yourself in the foot, by using additional __must_be_array() check. Signed-off-by: Patryk Wlazlyn <[email protected]> Signed-off-by: Len Brown <[email protected]>
1 parent 73ed3c9 commit 25e713c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

tools/power/x86/turbostat/turbostat.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,8 @@ size_t cpu_present_setsize, cpu_effective_setsize, cpu_allowed_setsize, cpu_affi
10601060
#define MAX_ADDED_PACKAGE_COUNTERS 16
10611061
#define BITMASK_SIZE 32
10621062

1063+
#define ZERO_ARRAY(arr) (memset(arr, 0, sizeof(arr)) + __must_be_array(arr))
1064+
10631065
/* Indexes used to map data read from perf and MSRs into global variables */
10641066
enum rapl_rci_index {
10651067
RAPL_RCI_INDEX_ENERGY_PKG = 0,
@@ -3733,9 +3735,9 @@ int get_cstate_counters(unsigned int cpu, struct thread_data *t, struct core_dat
37333735
assert(ccstate_counter_info);
37343736
assert(cpu <= ccstate_counter_info_size);
37353737

3736-
memset(perf_data, 0, sizeof(perf_data));
3737-
memset(perf_data_core, 0, sizeof(perf_data_core));
3738-
memset(perf_data_pkg, 0, sizeof(perf_data_pkg));
3738+
ZERO_ARRAY(perf_data);
3739+
ZERO_ARRAY(perf_data_core);
3740+
ZERO_ARRAY(perf_data_pkg);
37393741

37403742
cci = &ccstate_counter_info[cpu];
37413743

0 commit comments

Comments
 (0)