All of lore.kernel.org
 help / color / mirror / Atom feed
* Restoring joydev BTNMAP ioctl compatibility
@ 2009-08-10  6:52 Stephen Kitt
  2009-08-10  8:14 ` Dmitry Torokhov
  0 siblings, 1 reply; 11+ messages in thread
From: Stephen Kitt @ 2009-08-10  6:52 UTC (permalink / raw)
  To: linux-input

Hi,

The KEY_MAX change in 2.6.28 changed the definitions of the button map
joydev ioctls (JSIOCSBTNMAP and JSIOCGBTNMAP). Thus software built using
pre-2.6.28 headers fails when retrieving or setting the button map on 2.6.28
and greater kernels.

The attached patch reintroduced the old ioctl definitions to restore
compatibility. It only copies as much information as was supported in
previous versions, but since this still allows for devices with 256 buttons I
doubt there's much chance of losing information, hence the lack of a printk()
warning.

Signed-off-by: Stephen Kitt <steve@sk2.org>

 joydev.c |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index 4cfd084..764700e 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -35,6 +35,11 @@ MODULE_LICENSE("GPL");
 #define JOYDEV_MINORS		16
 #define JOYDEV_BUFFER_SIZE	64
 
+/* Support for old ioctls using the old value of KEY_MAX. */
+#define OLD_KEY_MAX		0x1ff
+#define OLD_JSIOCSBTNMAP	_IOW('j', 0x33, __u16[OLD_KEY_MAX - BTN_MISC + 1])
+#define OLD_JSIOCGBTNMAP	_IOR('j', 0x34, __u16[OLD_KEY_MAX - BTN_MISC + 1])
+
 struct joydev {
 	int exist;
 	int open;
@@ -529,10 +534,28 @@ static int joydev_ioctl_common(struct joydev *joydev,
 
 		return 0;
 
+	case OLD_JSIOCSBTNMAP:
+		if (copy_from_user(joydev->keypam, argp,
+				   sizeof(__u16) * (OLD_KEY_MAX - BTN_MISC + 1)))
+			return -EFAULT;
+
+		for (i = 0; i < joydev->nkey && i < OLD_KEY_MAX - BTN_MISC + 1; i++) {
+			if (joydev->keypam[i] > KEY_MAX ||
+			    joydev->keypam[i] < BTN_MISC)
+				return -EINVAL;
+			joydev->keymap[joydev->keypam[i] - BTN_MISC] = i;
+		}
+
+		return 0;
+
 	case JSIOCGBTNMAP:
 		return copy_to_user(argp, joydev->keypam,
 			sizeof(__u16) * (KEY_MAX - BTN_MISC + 1)) ? -EFAULT : 0;
 
+	case OLD_JSIOCGBTNMAP:
+		return copy_to_user(argp, joydev->keypam,
+				    sizeof(__u16) * (OLD_KEY_MAX - BTN_MISC + 1)) ? -EFAULT : 0;
+
 	default:
 		if ((cmd & ~IOCSIZE_MASK) == JSIOCGNAME(0)) {
 			int len;

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2009-08-19  6:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-10  6:52 Restoring joydev BTNMAP ioctl compatibility Stephen Kitt
2009-08-10  8:14 ` Dmitry Torokhov
2009-08-10 11:29   ` Stephen Kitt
2009-08-10 19:12     ` Stephen Kitt
2009-08-10 20:27       ` Dmitry Torokhov
2009-08-11  6:20         ` Stephen Kitt
2009-08-11  7:26           ` Dmitry Torokhov
2009-08-11 22:00             ` Stephen Kitt
2009-08-17 19:24             ` Stephen Kitt
2009-08-18  5:25               ` Dmitry Torokhov
2009-08-19  6:24                 ` Stephen Kitt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.