diff options
author | Jiri Slaby <jirislaby@gmail.com> | 2008-04-29 03:59:13 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-29 11:06:02 -0400 |
commit | 7e4e8e689fe90dd94bd76f9706d6cce580941ed5 (patch) | |
tree | e4ae62a26e891ca1f17740231a68541feda29eee /drivers/misc/phantom.c | |
parent | eb0f1c442d7cf1f7cb746c26c6120bb42e69c49c (diff) |
Misc: phantom, add compat ioctl
Openhaptics uses pointers in _IOC() macros, implement compat for them. Also
add _IOC alternatives which are not 32/64 bit dependent (structures
passed through aren't yet) -- libphantom will use them.
[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/misc/phantom.c')
-rw-r--r-- | drivers/misc/phantom.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/drivers/misc/phantom.c b/drivers/misc/phantom.c index 7fa61e907e1c..5447a603686a 100644 --- a/drivers/misc/phantom.c +++ b/drivers/misc/phantom.c | |||
@@ -12,6 +12,7 @@ | |||
12 | * or alternatively, you might use OpenHaptics provided by Sensable. | 12 | * or alternatively, you might use OpenHaptics provided by Sensable. |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <linux/compat.h> | ||
15 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
16 | #include <linux/module.h> | 17 | #include <linux/module.h> |
17 | #include <linux/device.h> | 18 | #include <linux/device.h> |
@@ -91,11 +92,8 @@ static long phantom_ioctl(struct file *file, unsigned int cmd, | |||
91 | unsigned long flags; | 92 | unsigned long flags; |
92 | unsigned int i; | 93 | unsigned int i; |
93 | 94 | ||
94 | if (_IOC_TYPE(cmd) != PH_IOC_MAGIC || | ||
95 | _IOC_NR(cmd) > PH_IOC_MAXNR) | ||
96 | return -ENOTTY; | ||
97 | |||
98 | switch (cmd) { | 95 | switch (cmd) { |
96 | case PHN_SETREG: | ||
99 | case PHN_SET_REG: | 97 | case PHN_SET_REG: |
100 | if (copy_from_user(&r, argp, sizeof(r))) | 98 | if (copy_from_user(&r, argp, sizeof(r))) |
101 | return -EFAULT; | 99 | return -EFAULT; |
@@ -126,6 +124,7 @@ static long phantom_ioctl(struct file *file, unsigned int cmd, | |||
126 | phantom_status(dev, dev->status & ~PHB_RUNNING); | 124 | phantom_status(dev, dev->status & ~PHB_RUNNING); |
127 | spin_unlock_irqrestore(&dev->regs_lock, flags); | 125 | spin_unlock_irqrestore(&dev->regs_lock, flags); |
128 | break; | 126 | break; |
127 | case PHN_SETREGS: | ||
129 | case PHN_SET_REGS: | 128 | case PHN_SET_REGS: |
130 | if (copy_from_user(&rs, argp, sizeof(rs))) | 129 | if (copy_from_user(&rs, argp, sizeof(rs))) |
131 | return -EFAULT; | 130 | return -EFAULT; |
@@ -143,6 +142,7 @@ static long phantom_ioctl(struct file *file, unsigned int cmd, | |||
143 | } | 142 | } |
144 | spin_unlock_irqrestore(&dev->regs_lock, flags); | 143 | spin_unlock_irqrestore(&dev->regs_lock, flags); |
145 | break; | 144 | break; |
145 | case PHN_GETREG: | ||
146 | case PHN_GET_REG: | 146 | case PHN_GET_REG: |
147 | if (copy_from_user(&r, argp, sizeof(r))) | 147 | if (copy_from_user(&r, argp, sizeof(r))) |
148 | return -EFAULT; | 148 | return -EFAULT; |
@@ -155,6 +155,7 @@ static long phantom_ioctl(struct file *file, unsigned int cmd, | |||
155 | if (copy_to_user(argp, &r, sizeof(r))) | 155 | if (copy_to_user(argp, &r, sizeof(r))) |
156 | return -EFAULT; | 156 | return -EFAULT; |
157 | break; | 157 | break; |
158 | case PHN_GETREGS: | ||
158 | case PHN_GET_REGS: { | 159 | case PHN_GET_REGS: { |
159 | u32 m; | 160 | u32 m; |
160 | 161 | ||
@@ -191,6 +192,20 @@ static long phantom_ioctl(struct file *file, unsigned int cmd, | |||
191 | return 0; | 192 | return 0; |
192 | } | 193 | } |
193 | 194 | ||
195 | #ifdef CONFIG_COMPAT | ||
196 | static long phantom_compat_ioctl(struct file *filp, unsigned int cmd, | ||
197 | unsigned long arg) | ||
198 | { | ||
199 | if (_IOC_NR(cmd) <= 3 && _IOC_SIZE(cmd) == sizeof(compat_uptr_t)) { | ||
200 | cmd &= ~(_IOC_SIZEMASK << _IOC_SIZESHIFT); | ||
201 | cmd |= sizeof(void *) << _IOC_SIZESHIFT; | ||
202 | } | ||
203 | return phantom_ioctl(filp, cmd, (unsigned long)compat_ptr(arg)); | ||
204 | } | ||
205 | #else | ||
206 | #define phantom_compat_ioctl NULL | ||
207 | #endif | ||
208 | |||
194 | static int phantom_open(struct inode *inode, struct file *file) | 209 | static int phantom_open(struct inode *inode, struct file *file) |
195 | { | 210 | { |
196 | struct phantom_device *dev = container_of(inode->i_cdev, | 211 | struct phantom_device *dev = container_of(inode->i_cdev, |
@@ -253,6 +268,7 @@ static struct file_operations phantom_file_ops = { | |||
253 | .open = phantom_open, | 268 | .open = phantom_open, |
254 | .release = phantom_release, | 269 | .release = phantom_release, |
255 | .unlocked_ioctl = phantom_ioctl, | 270 | .unlocked_ioctl = phantom_ioctl, |
271 | .compat_ioctl = phantom_compat_ioctl, | ||
256 | .poll = phantom_poll, | 272 | .poll = phantom_poll, |
257 | }; | 273 | }; |
258 | 274 | ||