diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2009-11-07 00:39:07 -0500 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2009-11-11 00:13:32 -0500 |
commit | bf3204cbff7d2606e758afb0994e8da6ae1c6c26 (patch) | |
tree | 01951b829d2af6a52b82bec35cc05261dcf77fe2 /drivers/input | |
parent | 558a5e296a02266ef43d6e933ee35df9976de987 (diff) |
Input: fix locking in memoryless force-feedback devices
Now that input core acquires dev->event_lock spinlock and disables
interrupts when propagating input events, using spin_lock_bh() in
ff-memless driver is not allowed. Actually, the timer_lock itself
is not needed anymore, we should simply use dev->event_lock
as well.
Also do a small cleanup in force-feedback core.
Reported-by: kerneloops.org
Reported-by: http://www.kerneloops.org/searchweek.php?search=ml_ff_set_gain
Reported-by: Arjan van de Ven <arjan@linux.intel.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/ff-core.c | 20 | ||||
-rw-r--r-- | drivers/input/ff-memless.c | 26 |
2 files changed, 22 insertions, 24 deletions
diff --git a/drivers/input/ff-core.c b/drivers/input/ff-core.c index 72c63e5dd630..38df81fcdc3a 100644 --- a/drivers/input/ff-core.c +++ b/drivers/input/ff-core.c | |||
@@ -337,16 +337,16 @@ int input_ff_create(struct input_dev *dev, int max_effects) | |||
337 | dev->ff = ff; | 337 | dev->ff = ff; |
338 | dev->flush = flush_effects; | 338 | dev->flush = flush_effects; |
339 | dev->event = input_ff_event; | 339 | dev->event = input_ff_event; |
340 | set_bit(EV_FF, dev->evbit); | 340 | __set_bit(EV_FF, dev->evbit); |
341 | 341 | ||
342 | /* Copy "true" bits into ff device bitmap */ | 342 | /* Copy "true" bits into ff device bitmap */ |
343 | for (i = 0; i <= FF_MAX; i++) | 343 | for (i = 0; i <= FF_MAX; i++) |
344 | if (test_bit(i, dev->ffbit)) | 344 | if (test_bit(i, dev->ffbit)) |
345 | set_bit(i, ff->ffbit); | 345 | __set_bit(i, ff->ffbit); |
346 | 346 | ||
347 | /* we can emulate RUMBLE with periodic effects */ | 347 | /* we can emulate RUMBLE with periodic effects */ |
348 | if (test_bit(FF_PERIODIC, ff->ffbit)) | 348 | if (test_bit(FF_PERIODIC, ff->ffbit)) |
349 | set_bit(FF_RUMBLE, dev->ffbit); | 349 | __set_bit(FF_RUMBLE, dev->ffbit); |
350 | 350 | ||
351 | return 0; | 351 | return 0; |
352 | } | 352 | } |
@@ -362,12 +362,14 @@ EXPORT_SYMBOL_GPL(input_ff_create); | |||
362 | */ | 362 | */ |
363 | void input_ff_destroy(struct input_dev *dev) | 363 | void input_ff_destroy(struct input_dev *dev) |
364 | { | 364 | { |
365 | clear_bit(EV_FF, dev->evbit); | 365 | struct ff_device *ff = dev->ff; |
366 | if (dev->ff) { | 366 | |
367 | if (dev->ff->destroy) | 367 | __clear_bit(EV_FF, dev->evbit); |
368 | dev->ff->destroy(dev->ff); | 368 | if (ff) { |
369 | kfree(dev->ff->private); | 369 | if (ff->destroy) |
370 | kfree(dev->ff); | 370 | ff->destroy(ff); |
371 | kfree(ff->private); | ||
372 | kfree(ff); | ||
371 | dev->ff = NULL; | 373 | dev->ff = NULL; |
372 | } | 374 | } |
373 | } | 375 | } |
diff --git a/drivers/input/ff-memless.c b/drivers/input/ff-memless.c index 2d1415e16834..b483b2995fa9 100644 --- a/drivers/input/ff-memless.c +++ b/drivers/input/ff-memless.c | |||
@@ -61,7 +61,6 @@ struct ml_device { | |||
61 | struct ml_effect_state states[FF_MEMLESS_EFFECTS]; | 61 | struct ml_effect_state states[FF_MEMLESS_EFFECTS]; |
62 | int gain; | 62 | int gain; |
63 | struct timer_list timer; | 63 | struct timer_list timer; |
64 | spinlock_t timer_lock; | ||
65 | struct input_dev *dev; | 64 | struct input_dev *dev; |
66 | 65 | ||
67 | int (*play_effect)(struct input_dev *dev, void *data, | 66 | int (*play_effect)(struct input_dev *dev, void *data, |
@@ -368,38 +367,38 @@ static void ml_effect_timer(unsigned long timer_data) | |||
368 | { | 367 | { |
369 | struct input_dev *dev = (struct input_dev *)timer_data; | 368 | struct input_dev *dev = (struct input_dev *)timer_data; |
370 | struct ml_device *ml = dev->ff->private; | 369 | struct ml_device *ml = dev->ff->private; |
370 | unsigned long flags; | ||
371 | 371 | ||
372 | debug("timer: updating effects"); | 372 | debug("timer: updating effects"); |
373 | 373 | ||
374 | spin_lock(&ml->timer_lock); | 374 | spin_lock_irqsave(&dev->event_lock, flags); |
375 | ml_play_effects(ml); | 375 | ml_play_effects(ml); |
376 | spin_unlock(&ml->timer_lock); | 376 | spin_unlock_irqrestore(&dev->event_lock, flags); |
377 | } | 377 | } |
378 | 378 | ||
379 | /* | ||
380 | * Sets requested gain for FF effects. Called with dev->event_lock held. | ||
381 | */ | ||
379 | static void ml_ff_set_gain(struct input_dev *dev, u16 gain) | 382 | static void ml_ff_set_gain(struct input_dev *dev, u16 gain) |
380 | { | 383 | { |
381 | struct ml_device *ml = dev->ff->private; | 384 | struct ml_device *ml = dev->ff->private; |
382 | int i; | 385 | int i; |
383 | 386 | ||
384 | spin_lock_bh(&ml->timer_lock); | ||
385 | |||
386 | ml->gain = gain; | 387 | ml->gain = gain; |
387 | 388 | ||
388 | for (i = 0; i < FF_MEMLESS_EFFECTS; i++) | 389 | for (i = 0; i < FF_MEMLESS_EFFECTS; i++) |
389 | __clear_bit(FF_EFFECT_PLAYING, &ml->states[i].flags); | 390 | __clear_bit(FF_EFFECT_PLAYING, &ml->states[i].flags); |
390 | 391 | ||
391 | ml_play_effects(ml); | 392 | ml_play_effects(ml); |
392 | |||
393 | spin_unlock_bh(&ml->timer_lock); | ||
394 | } | 393 | } |
395 | 394 | ||
395 | /* | ||
396 | * Start/stop specified FF effect. Called with dev->event_lock held. | ||
397 | */ | ||
396 | static int ml_ff_playback(struct input_dev *dev, int effect_id, int value) | 398 | static int ml_ff_playback(struct input_dev *dev, int effect_id, int value) |
397 | { | 399 | { |
398 | struct ml_device *ml = dev->ff->private; | 400 | struct ml_device *ml = dev->ff->private; |
399 | struct ml_effect_state *state = &ml->states[effect_id]; | 401 | struct ml_effect_state *state = &ml->states[effect_id]; |
400 | unsigned long flags; | ||
401 | |||
402 | spin_lock_irqsave(&ml->timer_lock, flags); | ||
403 | 402 | ||
404 | if (value > 0) { | 403 | if (value > 0) { |
405 | debug("initiated play"); | 404 | debug("initiated play"); |
@@ -425,8 +424,6 @@ static int ml_ff_playback(struct input_dev *dev, int effect_id, int value) | |||
425 | ml_play_effects(ml); | 424 | ml_play_effects(ml); |
426 | } | 425 | } |
427 | 426 | ||
428 | spin_unlock_irqrestore(&ml->timer_lock, flags); | ||
429 | |||
430 | return 0; | 427 | return 0; |
431 | } | 428 | } |
432 | 429 | ||
@@ -436,7 +433,7 @@ static int ml_ff_upload(struct input_dev *dev, | |||
436 | struct ml_device *ml = dev->ff->private; | 433 | struct ml_device *ml = dev->ff->private; |
437 | struct ml_effect_state *state = &ml->states[effect->id]; | 434 | struct ml_effect_state *state = &ml->states[effect->id]; |
438 | 435 | ||
439 | spin_lock_bh(&ml->timer_lock); | 436 | spin_lock_irq(&dev->event_lock); |
440 | 437 | ||
441 | if (test_bit(FF_EFFECT_STARTED, &state->flags)) { | 438 | if (test_bit(FF_EFFECT_STARTED, &state->flags)) { |
442 | __clear_bit(FF_EFFECT_PLAYING, &state->flags); | 439 | __clear_bit(FF_EFFECT_PLAYING, &state->flags); |
@@ -448,7 +445,7 @@ static int ml_ff_upload(struct input_dev *dev, | |||
448 | ml_schedule_timer(ml); | 445 | ml_schedule_timer(ml); |
449 | } | 446 | } |
450 | 447 | ||
451 | spin_unlock_bh(&ml->timer_lock); | 448 | spin_unlock_irq(&dev->event_lock); |
452 | 449 | ||
453 | return 0; | 450 | return 0; |
454 | } | 451 | } |
@@ -482,7 +479,6 @@ int input_ff_create_memless(struct input_dev *dev, void *data, | |||
482 | ml->private = data; | 479 | ml->private = data; |
483 | ml->play_effect = play_effect; | 480 | ml->play_effect = play_effect; |
484 | ml->gain = 0xffff; | 481 | ml->gain = 0xffff; |
485 | spin_lock_init(&ml->timer_lock); | ||
486 | setup_timer(&ml->timer, ml_effect_timer, (unsigned long)dev); | 482 | setup_timer(&ml->timer, ml_effect_timer, (unsigned long)dev); |
487 | 483 | ||
488 | set_bit(FF_GAIN, dev->ffbit); | 484 | set_bit(FF_GAIN, dev->ffbit); |