Skip to content

Commit fbefc5e

Browse files
committed
Input: max77693-haptic - fix potential overflow
Expression haptic->pwm_dev->period * haptic->magnitude is of type 'unsigned int' and may overflow. We need to convert one of the operands to u64 before multiplying, instead of casting result (potentially overflown) to u64. Reported by Coverity: CID 1248753 Acked-by : Jaewon Kim <jaewon02.kim@samsung.com> Reviewed-by: Chanwoo Choi <cw00.choi@samsung.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 185af4d commit fbefc5e

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/input/misc/max77693-haptic.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static int max77693_haptic_play_effect(struct input_dev *dev, void *data,
194194
struct ff_effect *effect)
195195
{
196196
struct max77693_haptic *haptic = input_get_drvdata(dev);
197-
uint64_t period_mag_multi;
197+
u64 period_mag_multi;
198198

199199
haptic->magnitude = effect->u.rumble.strong_magnitude;
200200
if (!haptic->magnitude)
@@ -205,8 +205,7 @@ static int max77693_haptic_play_effect(struct input_dev *dev, void *data,
205205
* The formula to convert magnitude to pwm_duty as follows:
206206
* - pwm_duty = (magnitude * pwm_period) / MAX_MAGNITUDE(0xFFFF)
207207
*/
208-
period_mag_multi = (int64_t)(haptic->pwm_dev->period *
209-
haptic->magnitude);
208+
period_mag_multi = (u64)haptic->pwm_dev->period * haptic->magnitude;
210209
haptic->pwm_duty = (unsigned int)(period_mag_multi >>
211210
MAX_MAGNITUDE_SHIFT);
212211

0 commit comments

Comments
 (0)