Skip to contentSkip to conversation

Checking keycodesize when adjusting keymaps breaks my IR remote

PATCH Ian Campbell 1 participant 1 message Aug 30, 2005 Input drivers

lore
Share & tools
lore
#0 lore raw

Hi Gents,

This patch:
http://marc.theaimsgroup.com/?l=linux-kernel&m=112227485202277&w=2
seems to break the remote control on my PVR-350 using ir-kbd-i2c.c.

The check "if (v >> (dev->keycodesize * 8))" in evdev_ioctl:EVIOCSKEYCODE prevents me from loading the keymap. This is because dev->keycodesize=4 so the size of the shift is 32 and the size of v is also 32. For example it is called with v == 82 which gives v >> (dev->keycodesize * 8) == 82 >> 32 which comes out as 82!

I think when the size of the shift is the size of the type, the result of the shift is either undefined or triggers a bug in gcc (most likely the former IMHO, but I don't have a reference to check).

There are no warnings when compiling the kernel because the shift size is unknown at compile time, but if I explicitly write "v >> 32" then I get:

warning: right shift count >= width of type

I think the solution (workaround?) is to only perform this check if keycodesize is less than sizeof(v). I'm unsure about adding a separate check for keycodesize > sizeof(v). Casting v to a type > 32 bits also does the trick if you prefer.

I wonder if the same applies in drivers/char/keyboard.c?

drivers/input/evdev.c +1 -1
Index: 2.6/drivers/input/evdev.c
===================================================================
@@ -320,7 +320,7 @@
 			if (t < 0 || t >= dev->keycodemax || !dev->keycodesize) return -EINVAL;
 			if (get_user(v, ip + 1)) return -EFAULT;
 			if (v < 0 || v > KEY_MAX) return -EINVAL;
-			if (v >> (dev->keycodesize * 8)) return -EINVAL;
+			if (dev->keycodesize < sizeof(v) && v >> (dev->keycodesize * 8)) return -EINVAL;
 			u = SET_INPUT_KEYCODE(dev, t, v);
 			clear_bit(u, dev->keybit);
 			set_bit(v, dev->keybit);
Signature · 4 lines
Ian Campbell

The biggest difference between time and space is that you can't reuse time.
		-- Merrick Furst