Skip to contentSkip to conversation

platform/x86: intel_pmc_core: Avoid a u32 overflow

PATCH In review Rajat Jain 3 participants 3 messages Feb 16, 2019 – Feb 22, 2019 x86 platform drivers

lore
Share & tools
lore

Rajat Jain

author
#0 lore raw

PATCH 1/1 platform/x86: intel_pmc_core: Avoid a u32 overflow

The register (SLP_S0_RES) at offset slp_s0_offset is a 32 bit register. The pmc_core_adjust_slp_s0_step() could overflow the u32 value while returning it after adjusting the step. Thus change to u64, this is already accounted for in debugfs attribute (that wants to output a 64 bit value).

---
 drivers/platform/x86/intel_pmc_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/intel_pmc_core.c +2 -2
index 22dbf115782e..f90f4dd25151 100644
@@ -328,9 +328,9 @@ static inline void pmc_core_reg_write(struct pmc_dev *pmcdev, int
 	writel(val, pmcdev->regbase + reg_offset);
 }
 
-static inline u32 pmc_core_adjust_slp_s0_step(u32 value)
+static inline u64 pmc_core_adjust_slp_s0_step(u32 value)
 {
-	return value * SPT_PMC_SLP_S0_RES_COUNTER_STEP;
+	return (u64)value * SPT_PMC_SLP_S0_RES_COUNTER_STEP;
 }
 
 static int pmc_core_dev_state_get(void *data, u64 *val)
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
#1 lore raw
Quoted 7 lines · Rajat Jain

The register (SLP_S0_RES) at offset slp_s0_offset is a 32 bit register. The pmc_core_adjust_slp_s0_step() could overflow the u32 value while returning it after adjusting the step. Thus change to u64, this is already accounted for in debugfs attribute (that wants to output a 64 bit value).

Pushed to my review and testing queue, thanks!

Quoted 24 lines
---
 drivers/platform/x86/intel_pmc_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/intel_pmc_core.c +2 -3
index 22dbf115782e..f90f4dd25151 100644
@@ -328,9 +328,9 @@ static inline void pmc_core_reg_write(struct pmc_dev *pmcdev, int
        writel(val, pmcdev->regbase + reg_offset);
 }
 
-static inline u32 pmc_core_adjust_slp_s0_step(u32 value)
+static inline u64 pmc_core_adjust_slp_s0_step(u32 value)
 {
-       return value * SPT_PMC_SLP_S0_RES_COUNTER_STEP;
+       return (u64)value * SPT_PMC_SLP_S0_RES_COUNTER_STEP;
 }
 
 static int pmc_core_dev_state_get(void *data, u64 *val)
--

2.21.0.rc0.258.g878e2cd30e-goog

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Acked-by on v1 1/1
#2 lore raw
In reply to Rajat Jain
Quoted 7 lines · Rajat Jain

The register (SLP_S0_RES) at offset slp_s0_offset is a 32 bit register. The pmc_core_adjust_slp_s0_step() could overflow the u32 value while returning it after adjusting the step. Thus change to u64, this is already accounted for in debugfs attribute (that wants to output a 64 bit value).

Quoted 22 lines
---
  drivers/platform/x86/intel_pmc_core.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/intel_pmc_core.c +2 -2
index 22dbf115782e..f90f4dd25151 100644
@@ -328,9 +328,9 @@ static inline void pmc_core_reg_write(struct pmc_dev *pmcdev, int
  	writel(val, pmcdev->regbase + reg_offset);
  }
 
-static inline u32 pmc_core_adjust_slp_s0_step(u32 value)
+static inline u64 pmc_core_adjust_slp_s0_step(u32 value)
  {
-	return value * SPT_PMC_SLP_S0_RES_COUNTER_STEP;
+	return (u64)value * SPT_PMC_SLP_S0_RES_COUNTER_STEP;
  }
 
  static int pmc_core_dev_state_get(void *data, u64 *val)