Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / input / joydev.c
index 627d343..949bdce 100644 (file)
@@ -26,7 +26,6 @@
 #include <linux/init.h>
 #include <linux/smp_lock.h>
 #include <linux/device.h>
-#include <linux/devfs_fs_kernel.h>
 
 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
 MODULE_DESCRIPTION("Joystick device interfaces");
@@ -37,8 +36,6 @@ MODULE_LICENSE("GPL");
 #define JOYDEV_MINORS          16
 #define JOYDEV_BUFFER_SIZE     64
 
-#define MSECS(t)       (1000 * ((t) / HZ) + 1000 * ((t) % HZ) / HZ)
-
 struct joydev {
        int exist;
        int open;
@@ -117,7 +114,7 @@ static void joydev_event(struct input_handle *handle, unsigned int type, unsigne
                        return;
        }
 
-       event.time = MSECS(jiffies);
+       event.time = jiffies_to_msecs(jiffies);
 
        list_for_each_entry(list, &joydev->list, node) {
 
@@ -174,9 +171,8 @@ static int joydev_open(struct inode *inode, struct file *file)
        if (i >= JOYDEV_MINORS || !joydev_table[i])
                return -ENODEV;
 
-       if (!(list = kmalloc(sizeof(struct joydev_list), GFP_KERNEL)))
+       if (!(list = kzalloc(sizeof(struct joydev_list), GFP_KERNEL)))
                return -ENOMEM;
-       memset(list, 0, sizeof(struct joydev_list));
 
        list->joydev = joydev_table[i];
        list_add_tail(&list->node, &joydev_table[i]->list);
@@ -245,7 +241,7 @@ static ssize_t joydev_read(struct file *file, char __user *buf, size_t count, lo
 
                struct js_event event;
 
-               event.time = MSECS(jiffies);
+               event.time = jiffies_to_msecs(jiffies);
 
                if (list->startup < joydev->nkey) {
                        event.type = JS_EVENT_BUTTON | JS_EVENT_INIT;
@@ -285,48 +281,33 @@ static unsigned int joydev_poll(struct file *file, poll_table *wait)
                (POLLIN | POLLRDNORM) : 0) | (list->joydev->exist ? 0 : (POLLHUP | POLLERR));
 }
 
-static int joydev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
+static int joydev_ioctl_common(struct joydev *joydev, unsigned int cmd, void __user *argp)
 {
-       struct joydev_list *list = file->private_data;
-       struct joydev *joydev = list->joydev;
        struct input_dev *dev = joydev->handle.dev;
-       void __user *argp = (void __user *)arg;
        int i, j;
 
-       if (!joydev->exist) return -ENODEV;
-
        switch (cmd) {
 
                case JS_SET_CAL:
                        return copy_from_user(&joydev->glue.JS_CORR, argp,
-                               sizeof(struct JS_DATA_TYPE)) ? -EFAULT : 0;
+                               sizeof(joydev->glue.JS_CORR)) ? -EFAULT : 0;
                case JS_GET_CAL:
                        return copy_to_user(argp, &joydev->glue.JS_CORR,
-                               sizeof(struct JS_DATA_TYPE)) ? -EFAULT : 0;
+                               sizeof(joydev->glue.JS_CORR)) ? -EFAULT : 0;
                case JS_SET_TIMEOUT:
-                       return get_user(joydev->glue.JS_TIMEOUT, (int __user *) arg);
+                       return get_user(joydev->glue.JS_TIMEOUT, (s32 __user *) argp);
                case JS_GET_TIMEOUT:
-                       return put_user(joydev->glue.JS_TIMEOUT, (int __user *) arg);
-               case JS_SET_TIMELIMIT:
-                       return get_user(joydev->glue.JS_TIMELIMIT, (long __user *) arg);
-               case JS_GET_TIMELIMIT:
-                       return put_user(joydev->glue.JS_TIMELIMIT, (long __user *) arg);
-               case JS_SET_ALL:
-                       return copy_from_user(&joydev->glue, argp,
-                                               sizeof(struct JS_DATA_SAVE_TYPE)) ? -EFAULT : 0;
-               case JS_GET_ALL:
-                       return copy_to_user(argp, &joydev->glue,
-                                               sizeof(struct JS_DATA_SAVE_TYPE)) ? -EFAULT : 0;
+                       return put_user(joydev->glue.JS_TIMEOUT, (s32 __user *) argp);
 
                case JSIOCGVERSION:
-                       return put_user(JS_VERSION, (__u32 __user *) arg);
+                       return put_user(JS_VERSION, (__u32 __user *) argp);
                case JSIOCGAXES:
-                       return put_user(joydev->nabs, (__u8 __user *) arg);
+                       return put_user(joydev->nabs, (__u8 __user *) argp);
                case JSIOCGBUTTONS:
-                       return put_user(joydev->nkey, (__u8 __user *) arg);
+                       return put_user(joydev->nkey, (__u8 __user *) argp);
                case JSIOCSCORR:
                        if (copy_from_user(joydev->corr, argp,
-                                     sizeof(struct js_corr) * joydev->nabs))
+                                     sizeof(joydev->corr[0]) * joydev->nabs))
                            return -EFAULT;
                        for (i = 0; i < joydev->nabs; i++) {
                                j = joydev->abspam[i];
@@ -335,7 +316,7 @@ static int joydev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
                        return 0;
                case JSIOCGCORR:
                        return copy_to_user(argp, joydev->corr,
-                                               sizeof(struct js_corr) * joydev->nabs) ? -EFAULT : 0;
+                                               sizeof(joydev->corr[0]) * joydev->nabs) ? -EFAULT : 0;
                case JSIOCSAXMAP:
                        if (copy_from_user(joydev->abspam, argp, sizeof(__u8) * (ABS_MAX + 1)))
                                return -EFAULT;
@@ -371,6 +352,84 @@ static int joydev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
        return -EINVAL;
 }
 
+#ifdef CONFIG_COMPAT
+static long joydev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+{
+       struct joydev_list *list = file->private_data;
+       struct joydev *joydev = list->joydev;
+       void __user *argp = (void __user *)arg;
+       s32 tmp32;
+       struct JS_DATA_SAVE_TYPE_32 ds32;
+       int err;
+
+       if (!joydev->exist) return -ENODEV;
+       switch(cmd) {
+       case JS_SET_TIMELIMIT:
+               err = get_user(tmp32, (s32 __user *) arg);
+               if (err == 0)
+                       joydev->glue.JS_TIMELIMIT = tmp32;
+               break;
+       case JS_GET_TIMELIMIT:
+               tmp32 = joydev->glue.JS_TIMELIMIT;
+               err = put_user(tmp32, (s32 __user *) arg);
+               break;
+
+       case JS_SET_ALL:
+               err = copy_from_user(&ds32, argp,
+                                    sizeof(ds32)) ? -EFAULT : 0;
+               if (err == 0) {
+                       joydev->glue.JS_TIMEOUT    = ds32.JS_TIMEOUT;
+                       joydev->glue.BUSY          = ds32.BUSY;
+                       joydev->glue.JS_EXPIRETIME = ds32.JS_EXPIRETIME;
+                       joydev->glue.JS_TIMELIMIT  = ds32.JS_TIMELIMIT;
+                       joydev->glue.JS_SAVE       = ds32.JS_SAVE;
+                       joydev->glue.JS_CORR       = ds32.JS_CORR;
+               }
+               break;
+
+       case JS_GET_ALL:
+               ds32.JS_TIMEOUT    = joydev->glue.JS_TIMEOUT;
+               ds32.BUSY          = joydev->glue.BUSY;
+               ds32.JS_EXPIRETIME = joydev->glue.JS_EXPIRETIME;
+               ds32.JS_TIMELIMIT  = joydev->glue.JS_TIMELIMIT;
+               ds32.JS_SAVE       = joydev->glue.JS_SAVE;
+               ds32.JS_CORR       = joydev->glue.JS_CORR;
+
+               err = copy_to_user(argp, &ds32,
+                                         sizeof(ds32)) ? -EFAULT : 0;
+               break;
+
+       default:
+               err = joydev_ioctl_common(joydev, cmd, argp);
+       }
+       return err;
+}
+#endif /* CONFIG_COMPAT */
+
+static int joydev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
+{
+       struct joydev_list *list = file->private_data;
+       struct joydev *joydev = list->joydev;
+       void __user *argp = (void __user *)arg;
+
+       if (!joydev->exist) return -ENODEV;
+
+       switch(cmd) {
+               case JS_SET_TIMELIMIT:
+                       return get_user(joydev->glue.JS_TIMELIMIT, (long __user *) arg);
+               case JS_GET_TIMELIMIT:
+                       return put_user(joydev->glue.JS_TIMELIMIT, (long __user *) arg);
+               case JS_SET_ALL:
+                       return copy_from_user(&joydev->glue, argp,
+                                               sizeof(joydev->glue)) ? -EFAULT : 0;
+               case JS_GET_ALL:
+                       return copy_to_user(argp, &joydev->glue,
+                                               sizeof(joydev->glue)) ? -EFAULT : 0;
+               default:
+                       return joydev_ioctl_common(joydev, cmd, argp);
+       }
+}
+
 static struct file_operations joydev_fops = {
        .owner =        THIS_MODULE,
        .read =         joydev_read,
@@ -379,12 +438,16 @@ static struct file_operations joydev_fops = {
        .open =         joydev_open,
        .release =      joydev_release,
        .ioctl =        joydev_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl = joydev_compat_ioctl,
+#endif
        .fasync =       joydev_fasync,
 };
 
 static struct input_handle *joydev_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id)
 {
        struct joydev *joydev;
+       struct class_device *cdev;
        int i, j, t, minor;
 
        for (minor = 0; minor < JOYDEV_MINORS && joydev_table[minor]; minor++);
@@ -393,9 +456,8 @@ static struct input_handle *joydev_connect(struct input_handler *handler, struct
                return NULL;
        }
 
-       if (!(joydev = kmalloc(sizeof(struct joydev), GFP_KERNEL)))
+       if (!(joydev = kzalloc(sizeof(struct joydev), GFP_KERNEL)))
                return NULL;
-       memset(joydev, 0, sizeof(struct joydev));
 
        INIT_LIST_HEAD(&joydev->list);
        init_waitqueue_head(&joydev->wait);
@@ -450,11 +512,13 @@ static struct input_handle *joydev_connect(struct input_handler *handler, struct
 
        joydev_table[minor] = joydev;
 
-       devfs_mk_cdev(MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + minor),
-                       S_IFCHR|S_IRUGO|S_IWUSR, "input/js%d", minor);
-       class_simple_device_add(input_class,
-                               MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + minor),
-                               dev->dev, "js%d", minor);
+       cdev = class_device_create(&input_class, &dev->cdev,
+                       MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + minor),
+                       dev->cdev.dev, joydev->name);
+
+       /* temporary symlink to keep userspace happy */
+       sysfs_create_link(&input_class.subsys.kset.kobj, &cdev->kobj,
+                         joydev->name);
 
        return &joydev->handle;
 }
@@ -464,8 +528,8 @@ static void joydev_disconnect(struct input_handle *handle)
        struct joydev *joydev = handle->private;
        struct joydev_list *list;
 
-       class_simple_device_remove(MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + joydev->minor));
-       devfs_remove("input/js%d", joydev->minor);
+       sysfs_remove_link(&input_class.subsys.kset.kobj, joydev->name);
+       class_device_destroy(&input_class, MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + joydev->minor));
        joydev->exist = 0;
 
        if (joydev->open) {