Skip to content

Commit

Permalink
Input: max77693-haptic - fix potential overflow
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Chanwoo Choi <[email protected]>
Signed-off-by: Dmitry Torokhov <[email protected]>
  • Loading branch information
dtor committed Oct 31, 2014
1 parent 185af4d commit fbefc5e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/input/misc/max77693-haptic.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static int max77693_haptic_play_effect(struct input_dev *dev, void *data,
struct ff_effect *effect)
{
struct max77693_haptic *haptic = input_get_drvdata(dev);
uint64_t period_mag_multi;
u64 period_mag_multi;

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

Expand Down

0 comments on commit fbefc5e

Please sign in to comment.