diff options
author | Andy Shevchenko <andriy.shevchenko@linux.intel.com> | 2017-01-28 10:10:39 -0500 |
---|---|---|
committer | Thierry Reding <thierry.reding@gmail.com> | 2017-01-30 02:13:19 -0500 |
commit | 684309e5043efaaa94d9b4e65f53f7fdde1f6675 (patch) | |
tree | 8f25bbc38fbe2e2c2ecb2c3f8b11aca68404853b /drivers/pwm/pwm-lpss.c | |
parent | 8d254a340efb12b40c4c1ff25a48a4f48f7bbd6b (diff) |
pwm: lpss: Avoid potential overflow of base_unit
The resolution of base_unit is derived from base_unit_bits and thus must be
equal to (2^base_unit_bits - 1). Otherwise frequency and therefore base_unit
might potentially overflow.
Prevent the above by substracting 1 in all cases where base_unit_bits or
derivative is used.
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'drivers/pwm/pwm-lpss.c')
-rw-r--r-- | drivers/pwm/pwm-lpss.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/pwm/pwm-lpss.c b/drivers/pwm/pwm-lpss.c index 72c0bce5a75c..8642feeb8abd 100644 --- a/drivers/pwm/pwm-lpss.c +++ b/drivers/pwm/pwm-lpss.c | |||
@@ -102,7 +102,7 @@ static int pwm_lpss_config(struct pwm_chip *chip, struct pwm_device *pwm, | |||
102 | * The equation is: | 102 | * The equation is: |
103 | * base_unit = round(base_unit_range * freq / c) | 103 | * base_unit = round(base_unit_range * freq / c) |
104 | */ | 104 | */ |
105 | base_unit_range = BIT(lpwm->info->base_unit_bits); | 105 | base_unit_range = BIT(lpwm->info->base_unit_bits) - 1; |
106 | freq *= base_unit_range; | 106 | freq *= base_unit_range; |
107 | 107 | ||
108 | base_unit = DIV_ROUND_CLOSEST_ULL(freq, c); | 108 | base_unit = DIV_ROUND_CLOSEST_ULL(freq, c); |
@@ -117,8 +117,8 @@ static int pwm_lpss_config(struct pwm_chip *chip, struct pwm_device *pwm, | |||
117 | 117 | ||
118 | ctrl = pwm_lpss_read(pwm); | 118 | ctrl = pwm_lpss_read(pwm); |
119 | ctrl &= ~PWM_ON_TIME_DIV_MASK; | 119 | ctrl &= ~PWM_ON_TIME_DIV_MASK; |
120 | ctrl &= ~((base_unit_range - 1) << PWM_BASE_UNIT_SHIFT); | 120 | ctrl &= ~(base_unit_range << PWM_BASE_UNIT_SHIFT); |
121 | base_unit &= (base_unit_range - 1); | 121 | base_unit &= base_unit_range; |
122 | ctrl |= (u32) base_unit << PWM_BASE_UNIT_SHIFT; | 122 | ctrl |= (u32) base_unit << PWM_BASE_UNIT_SHIFT; |
123 | ctrl |= on_time_div; | 123 | ctrl |= on_time_div; |
124 | pwm_lpss_write(pwm, ctrl); | 124 | pwm_lpss_write(pwm, ctrl); |