aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2014-10-28 12:27:58 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2014-10-31 12:30:44 -0400
commitfbefc5e7e63228d56963eeb0db10209ea0fafe9d (patch)
treeac7352b6a72cbc78768fd16294c330a57249bd19 /drivers/input
parent185af4d6668e4805d18d1bdf21dfec89d680fee3 (diff)
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>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/misc/max77693-haptic.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/drivers/input/misc/max77693-haptic.c b/drivers/input/misc/max77693-haptic.c
index 7b1fde93799e..ef6a9d650d69 100644
--- a/drivers/input/misc/max77693-haptic.c
+++ b/drivers/input/misc/max77693-haptic.c
@@ -194,7 +194,7 @@ static int max77693_haptic_play_effect(struct input_dev *dev, void *data,
194 struct ff_effect *effect) 194 struct ff_effect *effect)
195{ 195{
196 struct max77693_haptic *haptic = input_get_drvdata(dev); 196 struct max77693_haptic *haptic = input_get_drvdata(dev);
197 uint64_t period_mag_multi; 197 u64 period_mag_multi;
198 198
199 haptic->magnitude = effect->u.rumble.strong_magnitude; 199 haptic->magnitude = effect->u.rumble.strong_magnitude;
200 if (!haptic->magnitude) 200 if (!haptic->magnitude)
@@ -205,8 +205,7 @@ static int max77693_haptic_play_effect(struct input_dev *dev, void *data,
205 * The formula to convert magnitude to pwm_duty as follows: 205 * The formula to convert magnitude to pwm_duty as follows:
206 * - pwm_duty = (magnitude * pwm_period) / MAX_MAGNITUDE(0xFFFF) 206 * - pwm_duty = (magnitude * pwm_period) / MAX_MAGNITUDE(0xFFFF)
207 */ 207 */
208 period_mag_multi = (int64_t)(haptic->pwm_dev->period * 208 period_mag_multi = (u64)haptic->pwm_dev->period * haptic->magnitude;
209 haptic->magnitude);
210 haptic->pwm_duty = (unsigned int)(period_mag_multi >> 209 haptic->pwm_duty = (unsigned int)(period_mag_multi >>
211 MAX_MAGNITUDE_SHIFT); 210 MAX_MAGNITUDE_SHIFT);
212 211