Re: linux-next: Tree for July 30

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linus Torvalds
Date: Friday, August 1, 2008 - 12:12 pm

Ok, I apparently missed this whole subthread yesterday, only getting back 
to it when going over my old queues.

On Thu, 31 Jul 2008, Dmitry Torokhov wrote:

Yeah, it's not pretty, but how about moving that EV_KEY thing into the 
switch() statement? Also, the printk could certainly be a bit more useful.

But before doing _any_ of that, the first thing to do should be to not 
have that four-deep indentation by just splitting that horrible function 
up a bit.

IOW, start off with a patch like the appended, and _then_ add the special 
case handling to the EV_KEY thing. It would probably be most easily done 
by just literally limiting "len" to OLD_KEY_MAX. Something like

   #define OLD_KEY_MAX 0x1ff
   ...
	case EV_KEY:
		bits = dev->keybit;
		len = KEY_MAX;
		/* Hacky workaround for old bug in Xorg */
		if (buf_len == OLD_KEY_MAX) 
			len = OLD_KEY_MAX;
		break;
  ...

or similar.

Yeah, it's not pretty, but pragmatism before beauty.

		Linus
---
 drivers/input/evdev.c |   44 ++++++++++++++++++++++++--------------------
 1 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 2d65411..ef8c2ed 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -647,6 +647,28 @@ static int str_to_user(const char *str, unsigned int maxlen, void __user *p)
 	return copy_to_user(p, str, len) ? -EFAULT : len;
 }
 
+static int handle_eviocgbit(struct input_dev *dev, unsigned int cmd, void __user *p, int compat_mode)
+{
+	unsigned long *bits;
+	int len;
+
+	switch (_IOC_NR(cmd) & EV_MAX) {
+
+	case      0: bits = dev->evbit;  len = EV_MAX;  break;
+	case EV_KEY: bits = dev->keybit; len = KEY_MAX; break;
+	case EV_REL: bits = dev->relbit; len = REL_MAX; break;
+	case EV_ABS: bits = dev->absbit; len = ABS_MAX; break;
+	case EV_MSC: bits = dev->mscbit; len = MSC_MAX; break;
+	case EV_LED: bits = dev->ledbit; len = LED_MAX; break;
+	case EV_SND: bits = dev->sndbit; len = SND_MAX; break;
+	case EV_FF:  bits = dev->ffbit;  len = FF_MAX;  break;
+	case EV_SW:  bits = dev->swbit;  len = SW_MAX;  break;
+	default: return -EINVAL;
+	}
+	return bits_to_user(bits, len, _IOC_SIZE(cmd), p, compat_mode);
+}
+
+
 static long evdev_do_ioctl(struct file *file, unsigned int cmd,
 			   void __user *p, int compat_mode)
 {
@@ -733,26 +755,8 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
 
 		if (_IOC_DIR(cmd) == _IOC_READ) {
 
-			if ((_IOC_NR(cmd) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0, 0))) {
-
-				unsigned long *bits;
-				int len;
-
-				switch (_IOC_NR(cmd) & EV_MAX) {
-
-				case      0: bits = dev->evbit;  len = EV_MAX;  break;
-				case EV_KEY: bits = dev->keybit; len = KEY_MAX; break;
-				case EV_REL: bits = dev->relbit; len = REL_MAX; break;
-				case EV_ABS: bits = dev->absbit; len = ABS_MAX; break;
-				case EV_MSC: bits = dev->mscbit; len = MSC_MAX; break;
-				case EV_LED: bits = dev->ledbit; len = LED_MAX; break;
-				case EV_SND: bits = dev->sndbit; len = SND_MAX; break;
-				case EV_FF:  bits = dev->ffbit;  len = FF_MAX;  break;
-				case EV_SW:  bits = dev->swbit;  len = SW_MAX;  break;
-				default: return -EINVAL;
-				}
-				return bits_to_user(bits, len, _IOC_SIZE(cmd), p, compat_mode);
-			}
+			if ((_IOC_NR(cmd) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0, 0)))
+				return handle_eviocgbit(dev, cmd, p, compat_mode);
 
 			if (_IOC_NR(cmd) == _IOC_NR(EVIOCGKEY(0)))
 				return bits_to_user(dev->key, KEY_MAX, _IOC_SIZE(cmd),
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
linux-next: Tree for July 30, Stephen Rothwell, (Wed Jul 30, 12:06 am)
Re: linux-next: Tree for July 30, Takashi Iwai, (Wed Jul 30, 7:47 am)
Re: linux-next: Tree for July 30, Andrew Morton, (Wed Jul 30, 11:10 pm)
Re: linux-next: Tree for July 30, Dmitry Torokhov, (Thu Jul 31, 7:07 am)
Re: linux-next: Tree for July 30, Bartlomiej Zolnierki ..., (Thu Jul 31, 8:36 am)
Re: linux-next: Tree for July 30, Dmitry Torokhov, (Thu Jul 31, 8:56 am)
Re: linux-next: Tree for July 30, Andrew Morton, (Thu Jul 31, 10:44 am)
Re: linux-next: Tree for July 30, Dmitry Torokhov, (Thu Jul 31, 11:17 am)
Re: linux-next: Tree for July 30, Andrew Morton, (Thu Jul 31, 11:26 am)
Re: linux-next: Tree for July 30, Dmitry Torokhov, (Thu Jul 31, 11:34 am)
Re: linux-next: Tree for July 30, Rafael J. Wysocki, (Thu Jul 31, 11:48 am)
Re: linux-next: Tree for July 30, Dmitry Torokhov, (Thu Jul 31, 11:54 am)
Re: linux-next: Tree for July 30, Andrew Morton, (Thu Jul 31, 11:55 am)
Re: linux-next: Tree for July 30, Dmitry Torokhov, (Thu Jul 31, 12:03 pm)
Re: linux-next: Tree for July 30, Linus Torvalds, (Thu Jul 31, 12:10 pm)
Re: linux-next: Tree for July 30, Andrew Morton, (Thu Jul 31, 12:13 pm)
Re: linux-next: Tree for July 30, Hugh Dickins, (Thu Jul 31, 12:20 pm)
Re: linux-next: Tree for July 30, Dmitry Torokhov, (Thu Jul 31, 12:24 pm)
Re: linux-next: Tree for July 30, Dmitry Torokhov, (Thu Jul 31, 12:42 pm)
Re: linux-next: Tree for July 30, Linus Torvalds, (Thu Jul 31, 12:44 pm)
Re: linux-next: Tree for July 30, Rafael J. Wysocki, (Thu Jul 31, 12:57 pm)
Re: linux-next: Tree for July 30, Dmitry Torokhov, (Thu Jul 31, 1:05 pm)
Re: linux-next: Tree for July 30, Andrew Morton, (Thu Jul 31, 1:10 pm)
Re: linux-next: Tree for July 30, Linus Torvalds, (Thu Jul 31, 1:16 pm)
Re: linux-next: Tree for July 30, Linus Torvalds, (Thu Jul 31, 1:28 pm)
Re: linux-next: Tree for July 30, Dmitry Torokhov, (Thu Jul 31, 1:28 pm)
Re: linux-next: Tree for July 30, Dmitry Torokhov, (Thu Jul 31, 1:39 pm)
Re: linux-next: Tree for July 30, Linus Torvalds, (Fri Aug 1, 12:12 pm)
Re: linux-next: Tree for July 30, Dmitry Torokhov, (Fri Aug 1, 12:23 pm)
Re: linux-next: Tree for July 30, Linus Torvalds, (Fri Aug 1, 12:26 pm)
Re: linux-next: Tree for July 30, Stephen Rothwell, (Sun Aug 3, 10:47 pm)
Re: linux-next: Tree for July 30, Dmitry Torokhov, (Thu Aug 7, 11:11 am)
Re: linux-next: Tree for July 30, Andrew Morton, (Thu Aug 7, 11:50 am)
Re: linux-next: Tree for July 30, Rafael J. Wysocki, (Thu Aug 7, 11:55 am)
Re: linux-next: Tree for July 30, Dmitry Torokhov, (Thu Aug 7, 12:06 pm)