[lkml]   [2005]   [Aug]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
SubjectChecking keycodesize when adjusting keymaps breaks my IR remote
Hi Gents,

This patch:
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

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?

Signed-off-by: Ian Campbell <>

Index: 2.6/drivers/input/evdev.c
--- 2.6.orig/drivers/input/evdev.c 2005-08-29 10:40:22.000000000 +0100
+++ 2.6/drivers/input/evdev.c 2005-08-30 09:23:31.000000000 +0100
@@ -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);

Ian Campbell

The biggest difference between time and space is that you can't reuse time.
-- Merrick Furst
[unhandled content-type:application/pgp-signature]
 \ /
  Last update: 2005-08-30 10:41    [W:0.019 / U:0.224 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site