Skip to content

Commit 656acd2

Browse files
committed
Input: fix locking in force-feedback core
The newly added event_lock spinlock in the input core disallows sleeping and therefore using mutexes in event handlers. Convert force-feedback core to rely on event_lock instead of mutex to protect slots allocated for fore-feedback effects. The original mutex is still used to serialize uploading and erasing of effects. Reported-by: Anssi Hannula <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 4bbff7e commit 656acd2

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

drivers/input/ff-core.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,10 @@ int input_ff_upload(struct input_dev *dev, struct ff_effect *effect,
166166
if (ret)
167167
goto out;
168168

169+
spin_lock_irq(&dev->event_lock);
169170
ff->effects[id] = *effect;
170171
ff->effect_owners[id] = file;
172+
spin_unlock_irq(&dev->event_lock);
171173

172174
out:
173175
mutex_unlock(&ff->mutex);
@@ -189,16 +191,22 @@ static int erase_effect(struct input_dev *dev, int effect_id,
189191
if (error)
190192
return error;
191193

194+
spin_lock_irq(&dev->event_lock);
192195
ff->playback(dev, effect_id, 0);
196+
ff->effect_owners[effect_id] = NULL;
197+
spin_unlock_irq(&dev->event_lock);
193198

194199
if (ff->erase) {
195200
error = ff->erase(dev, effect_id);
196-
if (error)
201+
if (error) {
202+
spin_lock_irq(&dev->event_lock);
203+
ff->effect_owners[effect_id] = file;
204+
spin_unlock_irq(&dev->event_lock);
205+
197206
return error;
207+
}
198208
}
199209

200-
ff->effect_owners[effect_id] = NULL;
201-
202210
return 0;
203211
}
204212

@@ -263,8 +271,6 @@ int input_ff_event(struct input_dev *dev, unsigned int type,
263271
if (type != EV_FF)
264272
return 0;
265273

266-
mutex_lock(&ff->mutex);
267-
268274
switch (code) {
269275
case FF_GAIN:
270276
if (!test_bit(FF_GAIN, dev->ffbit) || value > 0xffff)
@@ -286,7 +292,6 @@ int input_ff_event(struct input_dev *dev, unsigned int type,
286292
break;
287293
}
288294

289-
mutex_unlock(&ff->mutex);
290295
return 0;
291296
}
292297
EXPORT_SYMBOL_GPL(input_ff_event);

0 commit comments

Comments
 (0)