]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Input: document and check on implicitly defined FF_MAX_EFFECTS
authorElias Vanderstuyft <elias.vds@gmail.com>
Thu, 15 Oct 2015 00:29:37 +0000 (17:29 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Fri, 16 Oct 2015 22:32:16 +0000 (15:32 -0700)
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>
drivers/input/ff-core.c
include/uapi/linux/input.h

index eab56c0aacd5d9433338341b731a242c9370e1bd..8f2042432c85151b25fab1e885fe321e1563d641 100644 (file)
@@ -318,6 +318,11 @@ int input_ff_create(struct input_dev *dev, unsigned int max_effects)
                return -EINVAL;
        }
 
+       if (max_effects > FF_MAX_EFFECTS) {
+               dev_err(&dev->dev, "cannot allocate more than FF_MAX_EFFECTS effects\n");
+               return -EINVAL;
+       }
+
        ff_dev_size = sizeof(struct ff_device) +
                                max_effects * sizeof(struct file *);
        if (ff_dev_size < max_effects) /* overflow */
index a8e74b45dbe2cafc28561deb2e4061cde147fdf6..4f9f2a0f55730939ee0f10a280c1db3ff9faeb7a 100644 (file)
@@ -414,6 +414,14 @@ struct ff_effect {
 #define FF_GAIN                0x60
 #define FF_AUTOCENTER  0x61
 
+/*
+ * ff->playback(effect_id = FF_GAIN) is the first effect_id to
+ * cause a collision with another ff method, in this case ff->set_gain().
+ * 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 FF_GAIN
+
 #define FF_MAX         0x7f
 #define FF_CNT         (FF_MAX+1)