These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / input / ff-core.c
index b81c88c..8f20424 100644 (file)
@@ -70,7 +70,7 @@ static int compat_effect(struct ff_device *ff, struct ff_effect *effect)
                        return -EINVAL;
 
                /*
-                * calculate manginude of sine wave as average of rumble's
+                * calculate magnitude of sine wave as average of rumble's
                 * 2/3 of strong magnitude and 1/3 of weak magnitude
                 */
                magnitude = effect->u.rumble.strong_magnitude / 3 +
@@ -213,7 +213,7 @@ static int erase_effect(struct input_dev *dev, int effect_id,
 /**
  * input_ff_erase - erase a force-feedback effect from device
  * @dev: input device to erase effect from
- * @effect_id: id of the ffect to be erased
+ * @effect_id: id of the effect to be erased
  * @file: purported owner of the request
  *
  * This function erases a force-feedback effect from specified device.
@@ -273,14 +273,14 @@ int input_ff_event(struct input_dev *dev, unsigned int type,
 
        switch (code) {
        case FF_GAIN:
-               if (!test_bit(FF_GAIN, dev->ffbit) || value > 0xffff)
+               if (!test_bit(FF_GAIN, dev->ffbit) || value > 0xffffU)
                        break;
 
                ff->set_gain(dev, value);
                break;
 
        case FF_AUTOCENTER:
-               if (!test_bit(FF_AUTOCENTER, dev->ffbit) || value > 0xffff)
+               if (!test_bit(FF_AUTOCENTER, dev->ffbit) || value > 0xffffU)
                        break;
 
                ff->set_autocenter(dev, value);
@@ -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 */
@@ -343,9 +348,8 @@ int input_ff_create(struct input_dev *dev, unsigned int max_effects)
        __set_bit(EV_FF, dev->evbit);
 
        /* Copy "true" bits into ff device bitmap */
-       for (i = 0; i <= FF_MAX; i++)
-               if (test_bit(i, dev->ffbit))
-                       __set_bit(i, ff->ffbit);
+       for_each_set_bit(i, dev->ffbit, FF_CNT)
+               __set_bit(i, ff->ffbit);
 
        /* we can emulate RUMBLE with periodic effects */
        if (test_bit(FF_PERIODIC, ff->ffbit))