patch-2.4.21 linux-2.4.21/drivers/input/joydev.c
Next file: linux-2.4.21/drivers/input/keybdev.c
Previous file: linux-2.4.21/drivers/input/input.c
Back to the patch index
Back to the overall index
- Lines: 82
- Date:
2003-06-13 07:51:34.000000000 -0700
- Orig file:
linux-2.4.20/drivers/input/joydev.c
- Orig date:
2002-08-02 17:39:44.000000000 -0700
diff -urN linux-2.4.20/drivers/input/joydev.c linux-2.4.21/drivers/input/joydev.c
@@ -50,6 +50,8 @@
#define JOYDEV_MINORS 32
#define JOYDEV_BUFFER_SIZE 64
+#define MSECS(t) (1000 * ((t) / HZ) + 1000 * ((t) % HZ) / HZ)
+
struct joydev {
int exist;
int open;
@@ -134,7 +136,7 @@
return;
}
- event.time = jiffies * (1000 / HZ);
+ event.time = MSECS(jiffies);
while (list) {
@@ -229,6 +231,9 @@
if (count < sizeof(struct js_event))
return -EINVAL;
+
+ if (!joydev->exist)
+ return -ENODEV;
if (count == sizeof(struct JS_DATA_TYPE)) {
@@ -256,6 +261,10 @@
while (list->head == list->tail) {
+ if (!joydev->exist) {
+ retval = -ENODEV;
+ break;
+ }
if (file->f_flags & O_NONBLOCK) {
retval = -EAGAIN;
break;
@@ -279,7 +288,7 @@
struct js_event event;
- event.time = jiffies * (1000/HZ);
+ event.time = MSECS(jiffies);
if (list->startup < joydev->nkey) {
event.type = JS_EVENT_BUTTON | JS_EVENT_INIT;
@@ -327,6 +336,9 @@
struct input_dev *dev = joydev->handle.dev;
int i;
+ if (!joydev->exist)
+ return -ENODEV;
+
switch (cmd) {
case JS_SET_CAL:
@@ -365,7 +377,7 @@
case JSIOCSAXMAP:
if (copy_from_user(joydev->abspam, (__u8 *) arg, sizeof(__u8) * ABS_MAX))
return -EFAULT;
- for (i = 0; i < ABS_MAX; i++) {
+ for (i = 0; i < joydev->nabs; i++) {
if (joydev->abspam[i] > ABS_MAX) return -EINVAL;
joydev->absmap[joydev->abspam[i]] = i;
}
@@ -374,11 +386,11 @@
return copy_to_user((__u8 *) arg, joydev->abspam,
sizeof(__u8) * ABS_MAX) ? -EFAULT : 0;
case JSIOCSBTNMAP:
- if (copy_from_user(joydev->absmap, (__u16 *) arg, sizeof(__u16) * (KEY_MAX - BTN_MISC)))
+ if (copy_from_user(joydev->keypam, (__u16 *) arg, sizeof(__u16) * (KEY_MAX - BTN_MISC)))
return -EFAULT;
- for (i = 0; i < KEY_MAX - BTN_MISC; i++); {
+ for (i = 0; i < joydev->nkey; i++) {
if (joydev->keypam[i] > KEY_MAX || joydev->keypam[i] < BTN_MISC) return -EINVAL;
- joydev->keymap[joydev->abspam[i - BTN_MISC]] = i;
+ joydev->keymap[joydev->keypam[i] - BTN_MISC] = i;
}
return 0;
case JSIOCGBTNMAP:
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)