Input: uinput - add compat ioctl number translation for UI_*_FF_UPLOAD
[sfrench/cifs-2.6.git] / drivers / input / misc / uinput.c
index 8ec483e8688be194078d07f3b47fa40d7f75e9ac..83d1499fe02152cfa75e8d097f6432d50632a6cc 100644 (file)
@@ -39,6 +39,7 @@
 #include <linux/init.h>
 #include <linux/fs.h>
 #include <linux/miscdevice.h>
+#include <linux/overflow.h>
 #include <linux/input/mt.h>
 #include "../input-compat.h"
 
@@ -405,7 +406,7 @@ static int uinput_open(struct inode *inode, struct file *file)
 static int uinput_validate_absinfo(struct input_dev *dev, unsigned int code,
                                   const struct input_absinfo *abs)
 {
-       int min, max;
+       int min, max, range;
 
        min = abs->minimum;
        max = abs->maximum;
@@ -417,7 +418,7 @@ static int uinput_validate_absinfo(struct input_dev *dev, unsigned int code,
                return -EINVAL;
        }
 
-       if (abs->flat > max - min) {
+       if (!check_sub_overflow(max, min, &range) && abs->flat > range) {
                printk(KERN_DEBUG
                       "%s: abs_flat #%02x out of range: %d (min:%d/max:%d)\n",
                       UINPUT_NAME, code, abs->flat, min, max);
@@ -1050,13 +1051,31 @@ static long uinput_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 
 #ifdef CONFIG_COMPAT
 
-#define UI_SET_PHYS_COMPAT     _IOW(UINPUT_IOCTL_BASE, 108, compat_uptr_t)
+/*
+ * These IOCTLs change their size and thus their numbers between
+ * 32 and 64 bits.
+ */
+#define UI_SET_PHYS_COMPAT             \
+       _IOW(UINPUT_IOCTL_BASE, 108, compat_uptr_t)
+#define UI_BEGIN_FF_UPLOAD_COMPAT      \
+       _IOWR(UINPUT_IOCTL_BASE, 200, struct uinput_ff_upload_compat)
+#define UI_END_FF_UPLOAD_COMPAT                \
+       _IOW(UINPUT_IOCTL_BASE, 201, struct uinput_ff_upload_compat)
 
 static long uinput_compat_ioctl(struct file *file,
                                unsigned int cmd, unsigned long arg)
 {
-       if (cmd == UI_SET_PHYS_COMPAT)
+       switch (cmd) {
+       case UI_SET_PHYS_COMPAT:
                cmd = UI_SET_PHYS;
+               break;
+       case UI_BEGIN_FF_UPLOAD_COMPAT:
+               cmd = UI_BEGIN_FF_UPLOAD;
+               break;
+       case UI_END_FF_UPLOAD_COMPAT:
+               cmd = UI_END_FF_UPLOAD;
+               break;
+       }
 
        return uinput_ioctl_handler(file, cmd, arg, compat_ptr(arg));
 }