mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Checking keycodesize when adjusting keymaps breaks my IR remote
@ 2005-08-30  8:38 Ian Campbell
  0 siblings, 0 replies; only message in thread
From: Ian Campbell @ 2005-08-30  8:38 UTC (permalink / raw)
  To: Dmitry Torokhov, Vojtech Pavlik; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2051 bytes --]

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?

Signed-off-by: Ian Campbell <ijc@hellion.org.uk>

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

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-08-30  8:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-30  8:38 Checking keycodesize when adjusting keymaps breaks my IR remote Ian Campbell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®