Skip to content

Commit

Permalink
Input: ff-memless - another fix for signed to unsigned overflow
Browse files Browse the repository at this point in the history
The commit 9e68177 changed 'gain' from
signed to unsigned to fix an issue with rumble effect calculation, however
it introduced problems when calculating constant effects. Having 'gain'
being unsigned int was an unfortunate choice since it dominates all
implicit type conversions causing everything to be treated as unsigned
int.

Let's change it back to signed int and simply add proper casts to rumble
effect calculations.

Reported-by: Gary Stein <lordcnidarian@gmail.com>
Acked-by: Anssi Hannula <anssi.hannula@iki.fi>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
  • Loading branch information
Dmitry Torokhov committed Dec 25, 2009
1 parent 25ae083 commit 1b11c88
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/input/ff-memless.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ static int get_compatible_type(struct ff_device *ff, int effect_type)
*/
static void ml_combine_effects(struct ff_effect *effect,
struct ml_effect_state *state,
unsigned int gain)
int gain)
{
struct ff_effect *new = state->effect;
unsigned int strong, weak, i;
Expand All @@ -252,8 +252,8 @@ static void ml_combine_effects(struct ff_effect *effect,
break;

case FF_RUMBLE:
strong = new->u.rumble.strong_magnitude * gain / 0xffff;
weak = new->u.rumble.weak_magnitude * gain / 0xffff;
strong = (u32)new->u.rumble.strong_magnitude * gain / 0xffff;
weak = (u32)new->u.rumble.weak_magnitude * gain / 0xffff;
effect->u.rumble.strong_magnitude =
min(strong + effect->u.rumble.strong_magnitude,
0xffffU);
Expand Down

0 comments on commit 1b11c88

Please sign in to comment.