Staging: comedi: cb_pcidio.c: Checkpatch cleanup
[safe/jmp/linux-2.6] / drivers / staging / comedi / comedi_compat32.c
index ef3caa9..581aa5f 100644 (file)
 
 #define __NO_VERSION__
 #include "comedi.h"
-#include <linux/smp_lock.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 
 #include "comedi_compat32.h"
 
 #ifdef CONFIG_COMPAT
 
-#ifndef HAVE_COMPAT_IOCTL
-#include <linux/ioctl32.h>     /* for (un)register_ioctl32_conversion */
-#endif
-
-#define COMEDI32_CHANINFO _IOR(CIO, 3, comedi32_chaninfo)
-#define COMEDI32_RANGEINFO _IOR(CIO, 8, (struct comedi32_rangeinfo_struct))
+#define COMEDI32_CHANINFO _IOR(CIO, 3, struct comedi32_chaninfo_struct)
+#define COMEDI32_RANGEINFO _IOR(CIO, 8, struct comedi32_rangeinfo_struct)
 /* N.B. COMEDI32_CMD and COMEDI_CMD ought to use _IOWR, not _IOR.
  * It's too late to change it now, but it only affects the command number. */
-#define COMEDI32_CMD _IOR(CIO, 9, (struct comedi32_cmd_struct))
+#define COMEDI32_CMD _IOR(CIO, 9, struct comedi32_cmd_struct)
 /* N.B. COMEDI32_CMDTEST and COMEDI_CMDTEST ought to use _IOWR, not _IOR.
  * It's too late to change it now, but it only affects the command number. */
-#define COMEDI32_CMDTEST _IOR(CIO, 10, (struct comedi32_cmd_struct))
-#define COMEDI32_INSNLIST _IOR(CIO, 11, (struct comedi32_insnlist_struct))
-#define COMEDI32_INSN _IOR(CIO, 12, (struct comedi32_insn_struct))
+#define COMEDI32_CMDTEST _IOR(CIO, 10, struct comedi32_cmd_struct)
+#define COMEDI32_INSNLIST _IOR(CIO, 11, struct comedi32_insnlist_struct)
+#define COMEDI32_INSN _IOR(CIO, 12, struct comedi32_insn_struct)
 
 struct comedi32_chaninfo_struct {
        unsigned int subdev;
        compat_uptr_t maxdata_list;     /* 32-bit 'unsigned int *' */
-       compat_uptr_t flaglist;         /* 32-bit 'unsigned int *' */
+       compat_uptr_t flaglist; /* 32-bit 'unsigned int *' */
        compat_uptr_t rangelist;        /* 32-bit 'unsigned int *' */
        unsigned int unused[4];
 };
@@ -74,16 +69,16 @@ struct comedi32_cmd_struct {
        unsigned int scan_end_arg;
        unsigned int stop_src;
        unsigned int stop_arg;
-       compat_uptr_t chanlist;         /* 32-bit 'unsigned int *' */
+       compat_uptr_t chanlist; /* 32-bit 'unsigned int *' */
        unsigned int chanlist_len;
-       compat_uptr_t data;             /* 32-bit 'short *' */
+       compat_uptr_t data;     /* 32-bit 'short *' */
        unsigned int data_len;
 };
 
 struct comedi32_insn_struct {
        unsigned int insn;
        unsigned int n;
-       compat_uptr_t data;             /* 32-bit 'unsigned int *' */
+       compat_uptr_t data;     /* 32-bit 'unsigned int *' */
        unsigned int subdev;
        unsigned int chanspec;
        unsigned int unused[3];
@@ -91,39 +86,26 @@ struct comedi32_insn_struct {
 
 struct comedi32_insnlist_struct {
        unsigned int n_insns;
-       compat_uptr_t insns;            /* 32-bit 'comedi_insn *' */
+       compat_uptr_t insns;    /* 32-bit 'struct comedi_insn *' */
 };
 
 /* Handle translated ioctl. */
 static int translated_ioctl(struct file *file, unsigned int cmd,
-               unsigned long arg)
+                           unsigned long arg)
 {
        if (!file->f_op)
                return -ENOTTY;
 
-#ifdef HAVE_UNLOCKED_IOCTL
-       if (file->f_op->unlocked_ioctl) {
-               int rc = (int)(*file->f_op->unlocked_ioctl)(file, cmd, arg);
-               if (rc == -ENOIOCTLCMD)
-                       rc = -ENOTTY;
-               return rc;
-       }
-#endif
-       if (file->f_op->ioctl) {
-               int rc;
-               lock_kernel();
-               rc = (*file->f_op->ioctl)(file->f_dentry->d_inode,
-                               file, cmd, arg);
-               unlock_kernel();
-               return rc;
-       }
+       if (file->f_op->unlocked_ioctl)
+               return file->f_op->unlocked_ioctl(file, cmd, arg);
+
        return -ENOTTY;
 }
 
 /* Handle 32-bit COMEDI_CHANINFO ioctl. */
 static int compat_chaninfo(struct file *file, unsigned long arg)
 {
-       struct comedi_chaninfo_struct __user *chaninfo;
+       struct comedi_chaninfo __user *chaninfo;
        struct comedi32_chaninfo_struct __user *chaninfo32;
        int err;
        union {
@@ -136,8 +118,7 @@ static int compat_chaninfo(struct file *file, unsigned long arg)
 
        /* Copy chaninfo structure.  Ignore unused members. */
        if (!access_ok(VERIFY_READ, chaninfo32, sizeof(*chaninfo32))
-                       || !access_ok(VERIFY_WRITE, chaninfo,
-                               sizeof(*chaninfo))) {
+           || !access_ok(VERIFY_WRITE, chaninfo, sizeof(*chaninfo))) {
                return -EFAULT;
        }
        err = 0;
@@ -158,7 +139,7 @@ static int compat_chaninfo(struct file *file, unsigned long arg)
 /* Handle 32-bit COMEDI_RANGEINFO ioctl. */
 static int compat_rangeinfo(struct file *file, unsigned long arg)
 {
-       comedi_rangeinfo __user *rangeinfo;
+       struct comedi_rangeinfo __user *rangeinfo;
        struct comedi32_rangeinfo_struct __user *rangeinfo32;
        int err;
        union {
@@ -171,8 +152,7 @@ static int compat_rangeinfo(struct file *file, unsigned long arg)
 
        /* Copy rangeinfo structure. */
        if (!access_ok(VERIFY_READ, rangeinfo32, sizeof(*rangeinfo32))
-                       || !access_ok(VERIFY_WRITE, rangeinfo,
-                               sizeof(*rangeinfo))) {
+           || !access_ok(VERIFY_WRITE, rangeinfo, sizeof(*rangeinfo))) {
                return -EFAULT;
        }
        err = 0;
@@ -184,12 +164,12 @@ static int compat_rangeinfo(struct file *file, unsigned long arg)
                return -EFAULT;
 
        return translated_ioctl(file, COMEDI_RANGEINFO,
-                       (unsigned long)rangeinfo);
+                               (unsigned long)rangeinfo);
 }
 
 /* Copy 32-bit cmd structure to native cmd structure. */
-static int get_compat_cmd(comedi_cmd __user *cmd,
-               struct comedi32_cmd_struct __user *cmd32)
+static int get_compat_cmd(struct comedi_cmd __user *cmd,
+                         struct comedi32_cmd_struct __user *cmd32)
 {
        int err;
        union {
@@ -199,7 +179,7 @@ static int get_compat_cmd(comedi_cmd __user *cmd,
 
        /* Copy cmd structure. */
        if (!access_ok(VERIFY_READ, cmd32, sizeof(*cmd32))
-                       || !access_ok(VERIFY_WRITE, cmd, sizeof(*cmd))) {
+           || !access_ok(VERIFY_WRITE, cmd, sizeof(*cmd))) {
                return -EFAULT;
        }
        err = 0;
@@ -239,7 +219,8 @@ static int get_compat_cmd(comedi_cmd __user *cmd,
 }
 
 /* Copy native cmd structure to 32-bit cmd structure. */
-static int put_compat_cmd(struct comedi32_cmd_struct __user *cmd32, comedi_cmd __user *cmd)
+static int put_compat_cmd(struct comedi32_cmd_struct __user *cmd32,
+                         struct comedi_cmd __user *cmd)
 {
        int err;
        unsigned int temp;
@@ -249,7 +230,7 @@ static int put_compat_cmd(struct comedi32_cmd_struct __user *cmd32, comedi_cmd _
        /* (Could use ptr_to_compat() to set them, but that wasn't implemented
         * until kernel version 2.6.11.) */
        if (!access_ok(VERIFY_READ, cmd, sizeof(*cmd))
-                       || !access_ok(VERIFY_WRITE, cmd32, sizeof(*cmd32))) {
+           || !access_ok(VERIFY_WRITE, cmd32, sizeof(*cmd32))) {
                return -EFAULT;
        }
        err = 0;
@@ -289,7 +270,7 @@ static int put_compat_cmd(struct comedi32_cmd_struct __user *cmd32, comedi_cmd _
 /* Handle 32-bit COMEDI_CMD ioctl. */
 static int compat_cmd(struct file *file, unsigned long arg)
 {
-       comedi_cmd __user *cmd;
+       struct comedi_cmd __user *cmd;
        struct comedi32_cmd_struct __user *cmd32;
        int rc;
 
@@ -306,7 +287,7 @@ static int compat_cmd(struct file *file, unsigned long arg)
 /* Handle 32-bit COMEDI_CMDTEST ioctl. */
 static int compat_cmdtest(struct file *file, unsigned long arg)
 {
-       comedi_cmd __user *cmd;
+       struct comedi_cmd __user *cmd;
        struct comedi32_cmd_struct __user *cmd32;
        int rc, err;
 
@@ -329,8 +310,8 @@ static int compat_cmdtest(struct file *file, unsigned long arg)
 }
 
 /* Copy 32-bit insn structure to native insn structure. */
-static int get_compat_insn(comedi_insn __user *insn,
-               struct comedi32_insn_struct __user *insn32)
+static int get_compat_insn(struct comedi_insn __user *insn,
+                          struct comedi32_insn_struct __user *insn32)
 {
        int err;
        union {
@@ -341,7 +322,7 @@ static int get_compat_insn(comedi_insn __user *insn,
        /* Copy insn structure.  Ignore the unused members. */
        err = 0;
        if (!access_ok(VERIFY_READ, insn32, sizeof(*insn32))
-                       || !access_ok(VERIFY_WRITE, insn, sizeof(*insn)))
+           || !access_ok(VERIFY_WRITE, insn, sizeof(*insn)))
                return -EFAULT;
 
        err |= __get_user(temp.uint, &insn32->insn);
@@ -361,8 +342,8 @@ static int get_compat_insn(comedi_insn __user *insn,
 static int compat_insnlist(struct file *file, unsigned long arg)
 {
        struct combined_insnlist {
-               comedi_insnlist insnlist;
-               comedi_insn insn[1];
+               struct comedi_insnlist insnlist;
+               struct comedi_insn insn[1];
        } __user *s;
        struct comedi32_insnlist_struct __user *insnlist32;
        struct comedi32_insn_struct __user *insn32;
@@ -373,9 +354,9 @@ static int compat_insnlist(struct file *file, unsigned long arg)
        insnlist32 = compat_ptr(arg);
 
        /* Get 32-bit insnlist structure.  */
-       if (!access_ok(VERIFY_READ, insnlist32, sizeof(*insnlist32))) {
+       if (!access_ok(VERIFY_READ, insnlist32, sizeof(*insnlist32)))
                return -EFAULT;
-       }
+
        err = 0;
        err |= __get_user(n_insns, &insnlist32->n_insns);
        err |= __get_user(uptr, &insnlist32->insns);
@@ -385,12 +366,12 @@ static int compat_insnlist(struct file *file, unsigned long arg)
 
        /* Allocate user memory to copy insnlist and insns into. */
        s = compat_alloc_user_space(offsetof(struct combined_insnlist,
-                               insn[n_insns]));
+                                            insn[n_insns]));
 
        /* Set native insnlist structure. */
-       if (!access_ok(VERIFY_WRITE, &s->insnlist, sizeof(s->insnlist))) {
+       if (!access_ok(VERIFY_WRITE, &s->insnlist, sizeof(s->insnlist)))
                return -EFAULT;
-       }
+
        err |= __put_user(n_insns, &s->insnlist.n_insns);
        err |= __put_user(&s->insn[0], &s->insnlist.insns);
        if (err)
@@ -404,13 +385,13 @@ static int compat_insnlist(struct file *file, unsigned long arg)
        }
 
        return translated_ioctl(file, COMEDI_INSNLIST,
-                       (unsigned long)&s->insnlist);
+                               (unsigned long)&s->insnlist);
 }
 
 /* Handle 32-bit COMEDI_INSN ioctl. */
 static int compat_insn(struct file *file, unsigned long arg)
 {
-       comedi_insn __user *insn;
+       struct comedi_insn __user *insn;
        struct comedi32_insn_struct __user *insn32;
        int rc;
 
@@ -427,7 +408,7 @@ static int compat_insn(struct file *file, unsigned long arg)
 /* Process untranslated ioctl. */
 /* Returns -ENOIOCTLCMD for unrecognised ioctl codes. */
 static inline int raw_ioctl(struct file *file, unsigned int cmd,
-               unsigned long arg)
+                           unsigned long arg)
 {
        int rc;
 
@@ -473,115 +454,11 @@ static inline int raw_ioctl(struct file *file, unsigned int cmd,
        return rc;
 }
 
-#ifdef HAVE_COMPAT_IOCTL       /* defined in <linux/fs.h> 2.6.11 onwards */
-
 /* compat_ioctl file operation. */
 /* Returns -ENOIOCTLCMD for unrecognised ioctl codes. */
-long comedi_compat_ioctl(struct file *file, unsigned int cmd,
-               unsigned long arg)
+long comedi_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
        return raw_ioctl(file, cmd, arg);
 }
 
-#else /* HAVE_COMPAT_IOCTL */
-
-/*
- * Brain-dead ioctl compatibility for 2.6.10 and earlier.
- *
- * It's brain-dead because cmd numbers need to be unique system-wide!
- * The comedi driver could end up attempting to execute ioctls for non-Comedi
- * devices because it registered the system-wide cmd code first.  Similarly,
- * another driver could end up attempting to execute ioctls for a Comedi
- * device because it registered the cmd code first.  Chaos ensues.
- */
-
-/* Handler for all 32-bit ioctl codes registered by this driver. */
-static int mapped_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg,
-               struct file *file)
-{
-       int rc;
-
-       /* Make sure we are dealing with a Comedi device. */
-       if (imajor(file->f_dentry->d_inode) != COMEDI_MAJOR)
-               return -ENOTTY;
-
-       rc = raw_ioctl(file, cmd, arg);
-       /* Do not return -ENOIOCTLCMD. */
-       if (rc == -ENOIOCTLCMD)
-               rc = -ENOTTY;
-
-       return rc;
-}
-
-struct ioctl32_map {
-       unsigned int cmd;
-       int (*handler)(unsigned int, unsigned int, unsigned long,
-                       struct file *);
-       int registered;
-};
-
-static struct ioctl32_map comedi_ioctl32_map[] = {
-       { COMEDI_DEVCONFIG, mapped_ioctl, 0 },
-       { COMEDI_DEVINFO, mapped_ioctl, 0 },
-       { COMEDI_SUBDINFO, mapped_ioctl, 0 },
-       { COMEDI_BUFCONFIG, mapped_ioctl, 0 },
-       { COMEDI_BUFINFO, mapped_ioctl, 0 },
-       { COMEDI_LOCK, mapped_ioctl, 0 },
-       { COMEDI_UNLOCK, mapped_ioctl, 0 },
-       { COMEDI_CANCEL, mapped_ioctl, 0 },
-       { COMEDI_POLL, mapped_ioctl, 0 },
-       { COMEDI32_CHANINFO, mapped_ioctl, 0 },
-       { COMEDI32_RANGEINFO, mapped_ioctl, 0 },
-       { COMEDI32_CMD, mapped_ioctl, 0 },
-       { COMEDI32_CMDTEST, mapped_ioctl, 0 },
-       { COMEDI32_INSNLIST, mapped_ioctl, 0 },
-       { COMEDI32_INSN, mapped_ioctl, 0 },
-};
-
-#define NUM_IOCTL32_MAPS ARRAY_SIZE(comedi_ioctl32_map)
-
-/* Register system-wide 32-bit ioctl handlers. */
-void comedi_register_ioctl32(void)
-{
-       int n, rc;
-
-       for (n = 0; n < NUM_IOCTL32_MAPS; n++) {
-               rc = register_ioctl32_conversion(comedi_ioctl32_map[n].cmd,
-                               comedi_ioctl32_map[n].handler);
-               if (rc) {
-                       printk(KERN_WARNING
-                                       "comedi: failed to register 32-bit "
-                                       "compatible ioctl handler for 0x%X - "
-                                       "expect bad things to happen!\n",
-                                       comedi_ioctl32_map[n].cmd);
-               }
-               comedi_ioctl32_map[n].registered = !rc;
-       }
-}
-
-/* Unregister system-wide 32-bit ioctl translations. */
-void comedi_unregister_ioctl32(void)
-{
-       int n, rc;
-
-       for (n = 0; n < NUM_IOCTL32_MAPS; n++) {
-               if (comedi_ioctl32_map[n].registered) {
-                       rc = unregister_ioctl32_conversion(
-                                       comedi_ioctl32_map[n].cmd,
-                                       comedi_ioctl32_map[n].handler);
-                       if (rc) {
-                               printk(KERN_ERR
-                                       "comedi: failed to unregister 32-bit "
-                                       "compatible ioctl handler for 0x%X - "
-                                       "expect kernel Oops!\n",
-                                       comedi_ioctl32_map[n].cmd);
-                       } else {
-                               comedi_ioctl32_map[n].registered = 0;
-                       }
-               }
-       }
-}
-
-#endif /* HAVE_COMPAT_IOCTL */
-
-#endif /* CONFIG_COMPAT */
+#endif /* CONFIG_COMPAT */