summary refs log tree commit diff
path: root/drivers/input/input.c
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2010-01-05 17:56:01 -0800
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2010-01-06 00:27:29 -0800
commit92a3a58788790645c6143b5353ef065fd26110bb (patch)
treee84cffdd0198641ce02ae65c2449070b21710847 /drivers/input/input.c
parent4f93df40859cf471774f6ef3ec7f2870c2e8e260 (diff)
downloadlinux-92a3a58788790645c6143b5353ef065fd26110bb.tar.gz
Input: cleanse capabilities bits before registering device
To avoid showing garbage in capability bits, zero out bitmasks absent
from dev->evbit in case driver inadvertently leaves some garbage there.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input/input.c')
-rw-r--r--drivers/input/input.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 910d7be06eff..a31394c1eca8 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -1497,6 +1497,25 @@ void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int
 }
 EXPORT_SYMBOL(input_set_capability);
 
+#define INPUT_CLEANSE_BITMASK(dev, type, bits)				\
+	do {								\
+		if (!test_bit(EV_##type, dev->evbit))			\
+			memset(dev->bits##bit, 0,			\
+				sizeof(dev->bits##bit));		\
+	} while (0)
+
+static void input_cleanse_bitmasks(struct input_dev *dev)
+{
+	INPUT_CLEANSE_BITMASK(dev, KEY, key);
+	INPUT_CLEANSE_BITMASK(dev, REL, rel);
+	INPUT_CLEANSE_BITMASK(dev, ABS, abs);
+	INPUT_CLEANSE_BITMASK(dev, MSC, msc);
+	INPUT_CLEANSE_BITMASK(dev, LED, led);
+	INPUT_CLEANSE_BITMASK(dev, SND, snd);
+	INPUT_CLEANSE_BITMASK(dev, FF, ff);
+	INPUT_CLEANSE_BITMASK(dev, SW, sw);
+}
+
 /**
  * input_register_device - register device with input core
  * @dev: device to be registered
@@ -1522,6 +1541,9 @@ int input_register_device(struct input_dev *dev)
 	/* KEY_RESERVED is not supposed to be transmitted to userspace. */
 	__clear_bit(KEY_RESERVED, dev->keybit);
 
+	/* Make sure that bitmasks not mentioned in dev->evbit are clean. */
+	input_cleanse_bitmasks(dev);
+
 	/*
 	 * If delay and period are pre-set by the driver, then autorepeating
 	 * is handled by the driver itself and we don't do it in input.c.