diff options
author | Elias Vanderstuyft <elias.vds@gmail.com> | 2015-10-14 20:29:37 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2015-10-16 18:32:16 -0400 |
commit | 33b96d934902f96e901b72ac18bbc47afad1ac20 (patch) | |
tree | 5dcd2df3497f413de865e0f219905021effd49d7 | |
parent | 52a9266788324edbbfd45f02cf23440c01ee0432 (diff) |
Input: document and check on implicitly defined FF_MAX_EFFECTS
There is an undocumented upper bound for the total number of ff effects:
FF_GAIN (= 96).
This can be found as follows:
- user: write(EV_FF, effect_id, iterations)
calls kernel: ff->playback(effect_id, ...): starts effect "effect_id"
- user: write(EV_FF, FF_GAIN, gain)
calls kernel: ff->set_gain(gain, ...): sets gain
A collision occurs when effect_id equals FF_GAIN.
According to input_ff_event(),
FF_GAIN is the smallest value where a collision occurs.
Therefore the greatest safe value for effect_id is FF_GAIN - 1,
and thus the total number of effects should never exceed FF_GAIN.
Define FF_MAX_EFFECTS as FF_GAIN and check on this limit in ff-core.
Signed-off-by: Elias Vanderstuyft <elias.vds@gmail.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
-rw-r--r-- | drivers/input/ff-core.c | 5 | ||||
-rw-r--r-- | include/uapi/linux/input.h | 8 |
2 files changed, 13 insertions, 0 deletions
diff --git a/drivers/input/ff-core.c b/drivers/input/ff-core.c index eab56c0aacd5..8f2042432c85 100644 --- a/drivers/input/ff-core.c +++ b/drivers/input/ff-core.c | |||
@@ -318,6 +318,11 @@ int input_ff_create(struct input_dev *dev, unsigned int max_effects) | |||
318 | return -EINVAL; | 318 | return -EINVAL; |
319 | } | 319 | } |
320 | 320 | ||
321 | if (max_effects > FF_MAX_EFFECTS) { | ||
322 | dev_err(&dev->dev, "cannot allocate more than FF_MAX_EFFECTS effects\n"); | ||
323 | return -EINVAL; | ||
324 | } | ||
325 | |||
321 | ff_dev_size = sizeof(struct ff_device) + | 326 | ff_dev_size = sizeof(struct ff_device) + |
322 | max_effects * sizeof(struct file *); | 327 | max_effects * sizeof(struct file *); |
323 | if (ff_dev_size < max_effects) /* overflow */ | 328 | if (ff_dev_size < max_effects) /* overflow */ |
diff --git a/include/uapi/linux/input.h b/include/uapi/linux/input.h index a8e74b45dbe2..4f9f2a0f5573 100644 --- a/include/uapi/linux/input.h +++ b/include/uapi/linux/input.h | |||
@@ -414,6 +414,14 @@ struct ff_effect { | |||
414 | #define FF_GAIN 0x60 | 414 | #define FF_GAIN 0x60 |
415 | #define FF_AUTOCENTER 0x61 | 415 | #define FF_AUTOCENTER 0x61 |
416 | 416 | ||
417 | /* | ||
418 | * ff->playback(effect_id = FF_GAIN) is the first effect_id to | ||
419 | * cause a collision with another ff method, in this case ff->set_gain(). | ||
420 | * Therefore the greatest safe value for effect_id is FF_GAIN - 1, | ||
421 | * and thus the total number of effects should never exceed FF_GAIN. | ||
422 | */ | ||
423 | #define FF_MAX_EFFECTS FF_GAIN | ||
424 | |||
417 | #define FF_MAX 0x7f | 425 | #define FF_MAX 0x7f |
418 | #define FF_CNT (FF_MAX+1) | 426 | #define FF_CNT (FF_MAX+1) |
419 | 427 | ||