platform/x86/intel: pmc: fix ltr decode in pmc_core_ltr_show()
Subsystems (2)
PATCH 1/1 platform/x86/intel: pmc: fix ltr decode in pmc_core_ltr_show()
In pmc_core_ltr_show(), promote 'val' to 'u64' to avoid possible integer overflow. Values (10 bit) are multiplied by the scale, the result of expression is in a range from 1 to 34,326,183,936 which is bigger then UINT32_MAX. Compile tested only.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/platform/x86/intel/pmc/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/intel/pmc/core.c +2 -2
@@ -660,12 +660,12 @@ static int pmc_core_ltr_show(struct seq_file *s, void *unused)if (FIELD_GET (LTR_REQ_NONSNOOP , ltr_raw_data)) { scale =FIELD_GET (LTR_DECODED_SCALE , nonsnoop_ltr); val =FIELD_GET (LTR_DECODED_VAL , nonsnoop_ltr); - decoded_non_snoop_ltr = val *convert_ltr_scale (scale); + decoded_non_snoop_ltr = (u64 )val *convert_ltr_scale (scale); }if (FIELD_GET (LTR_REQ_SNOOP , ltr_raw_data)) { scale =FIELD_GET (LTR_DECODED_SCALE , snoop_ltr); val =FIELD_GET (LTR_DECODED_VAL , snoop_ltr); - decoded_snoop_ltr = val *convert_ltr_scale (scale); + decoded_snoop_ltr = (u64 )val *convert_ltr_scale (scale); } seq_printf(s, "%d\tPMC%d:%-32s\tLTR: RAW: 0x%-16x\tNon-Snoop(ns): %-16llu\tSnoop(ns): %-16llu\tLTR_IGNORE: %d\n",
Signature · 1 line
2.47.1
Ilpo Järvinen
maintainerQuoted 18 lines · Dmitry Kandybka
In
pmc_core_ltr_show(), promote 'val' to 'u64' to avoid possible integer overflow. Values (10 bit) are multiplied by the scale, the result of expression is in a range from 1 to 34,326,183,936 which is bigger thenUINT32_MAX. Compile tested only.Found by Linux Verification Center (linuxtesting.org) with SVACE.
Signed-off-by Dmitry Kandybka <[email protected]>--- drivers/platform/x86/intel/pmc/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/platform/x86/intel/pmc/core.c +0
-0@@ -660,12 +660,12 @@ static int pmc_core_ltr_show(struct seq_file *s, void *unused)if (FIELD_GET (LTR_REQ_NONSNOOP , ltr_raw_data)) {
drivers/platform/x86/intel/pmc/core.c static int pmc_core_ltr_show(struct seq_file *s, void *unused) · line 668
Quoted 10 lines
drivers/platform/x86/intel/pmc/core.c +2
-2scale =FIELD_GET (LTR_DECODED_SCALE , nonsnoop_ltr); val =FIELD_GET (LTR_DECODED_VAL , nonsnoop_ltr); - decoded_non_snoop_ltr = val *convert_ltr_scale (scale); + decoded_non_snoop_ltr = (u64 )val *convert_ltr_scale (scale); }if (FIELD_GET (LTR_REQ_SNOOP , ltr_raw_data)) { scale =FIELD_GET (LTR_DECODED_SCALE , snoop_ltr); val =FIELD_GET (LTR_DECODED_VAL , snoop_ltr); - decoded_snoop_ltr = val *convert_ltr_scale (scale); + decoded_snoop_ltr = (u64 )val *convert_ltr_scale (scale);
Please change val to u64 instead so casting won't be necessary.
Signature · 1 line
i.