tools/power turbostat: Fix offset overflow issue in index converting
authorCalvin Walton <calvin.walton@kepstin.ca>
Wed, 28 Apr 2021 09:09:16 +0000 (17:09 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 11 May 2021 12:47:40 +0000 (14:47 +0200)
commitea6803ff2cd1a2d7d880256bf562172b708a76ff
treed064aa32aeabe1262abe4d0110e408055880b5ba
parentb84c57762cef3267e4639e88cadf06c2ab6bc106
tools/power turbostat: Fix offset overflow issue in index converting

commit 13a779de4175df602366d129e41782ad7168cef0 upstream.

The idx_to_offset() function returns type int (32-bit signed), but
MSR_PKG_ENERGY_STAT is u32 and would be interpreted as a negative number.
The end result is that it hits the if (offset < 0) check in update_msr_sum()
which prevents the timer callback from updating the stat in the background when
long durations are used. The similar issue exists in offset_to_idx() and
update_msr_sum(). Fix this issue by converting the 'int' to 'off_t' accordingly.

Fixes: 9972d5d84d76 ("tools/power turbostat: Enable accumulate RAPL display")
Signed-off-by: Calvin Walton <calvin.walton@kepstin.ca>
Signed-off-by: Len Brown <len.brown@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/power/x86/turbostat/turbostat.c