From: Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
Date: Wed, 26 Mar 97 11:28:36 +0100
To: linux-m68k@phil.uni-sb.de
Subject: L68K: Fix atari joystick polling
X-Yow: I know th'MAMBO!!  I have a TWO-TONE CHEMISTRY SET!!
Sender: owner-linux-m68k@phil.uni-sb.de
Reply-To: linux-m68k@phil.uni-sb.de

Hi!

This really fixes the polling in the atari joystick driver, in the way i
have already reported it some time ago.  And it is tested.  I have also
changed the driver name so that it is recognized by MAKEDEV.

Andreas.

--- linux/arch/m68k/atari/joystick.c.~1~	Mon Mar 24 16:47:28 1997
+++ linux/arch/m68k/atari/joystick.c	Tue Mar 25 14:43:03 1997
@@ -10,6 +10,7 @@
 #include <linux/sched.h>
 #include <linux/errno.h>
 #include <linux/major.h>
+#include <linux/poll.h>
 
 #include <asm/atarikb.h>
 #include <asm/atari_joystick.h>
@@ -89,28 +90,28 @@
 			  char *buffer, unsigned long count)
 {
     int minor = DEVICE_NR(inode->i_rdev);
-    int i;
 
     if (count < 2)
 	return -EINVAL;
     if (!joystick[minor].ready)
 	return -EAGAIN;
-    put_user(joystick[minor].fire, buffer++);
-    put_user(joystick[minor].dir, buffer++);
-    for (i = 0; i < count; i++)
-	put_user(0, buffer++);
     joystick[minor].ready = 0;
-
-    return i;
+    if (put_user(joystick[minor].fire, buffer++) ||
+	put_user(joystick[minor].dir, buffer++))
+	return -EFAULT;
+    if (count > 2)
+	if (clear_user(buffer, count - 2))
+	    return -EFAULT;
+    return count;
 }
 
 static unsigned int joystick_poll(struct file *file, poll_table *wait)
 {
-    int minor = MINOR(file->f_inode->i_rdev);
+    int minor = DEVICE_NR(file->f_inode->i_rdev);
 
-    if (joystick[minor].ready)
-	return 1;
     poll_wait(&joystick[minor].wait, wait);
+    if (joystick[minor].ready)
+	return POLLIN | POLLRDNORM;
     return 0;
 }
 
@@ -132,7 +133,7 @@
     joystick[0].ready = joystick[1].ready = 0;
     joystick[0].wait = joystick[1].wait = NULL;
 
-    if (register_chrdev(MAJOR_NR, "joystick", &atari_joystick_fops))
+    if (register_chrdev(MAJOR_NR, "Joystick", &atari_joystick_fops))
 	printk("unable to get major %d for joystick devices\n", MAJOR_NR);
 
     return 0;
