Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 58b93995 authored by Dmitry Torokhov's avatar Dmitry Torokhov
Browse files

Input: scancode in get/set_keycodes should be unsigned



The HID layer has some scan codes of the form 0xffbc0000 for logitech
devices which do not work if scancode is typed as signed int, so we need
to switch to unsigned it instead. While at it keycode being signed does
not make much sense either.

Acked-by: default avatarMárton Németh <nm127@freemail.hu>
Acked-by: default avatarMatthew Garrett <mjg@redhat.com>
Acked-by: default avatarJiri Kosina <jkosina@suse.cz>
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
parent ec62e1c8
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -68,22 +68,25 @@ static const struct {
#define map_key_clear(c)	hid_map_usage_clear(hidinput, usage, &bit, \
		&max, EV_KEY, (c))

static inline int match_scancode(int code, int scancode)
static inline int match_scancode(unsigned int code, unsigned int scancode)
{
	if (scancode == 0)
		return 1;
	return ((code & (HID_USAGE_PAGE | HID_USAGE)) == scancode);

	return (code & (HID_USAGE_PAGE | HID_USAGE)) == scancode;
}

static inline int match_keycode(int code, int keycode)
static inline int match_keycode(unsigned int code, unsigned int keycode)
{
	if (keycode == 0)
		return 1;
	return (code == keycode);

	return code == keycode;
}

static struct hid_usage *hidinput_find_key(struct hid_device *hid,
		int scancode, int keycode)
					   unsigned int scancode,
					   unsigned int keycode)
{
	int i, j, k;
	struct hid_report *report;
@@ -105,8 +108,8 @@ static struct hid_usage *hidinput_find_key(struct hid_device *hid,
	return NULL;
}

static int hidinput_getkeycode(struct input_dev *dev, int scancode,
				int *keycode)
static int hidinput_getkeycode(struct input_dev *dev,
			       unsigned int scancode, unsigned int *keycode)
{
	struct hid_device *hid = input_get_drvdata(dev);
	struct hid_usage *usage;
@@ -119,16 +122,13 @@ static int hidinput_getkeycode(struct input_dev *dev, int scancode,
	return -EINVAL;
}

static int hidinput_setkeycode(struct input_dev *dev, int scancode,
				int keycode)
static int hidinput_setkeycode(struct input_dev *dev,
			       unsigned int scancode, unsigned int keycode)
{
	struct hid_device *hid = input_get_drvdata(dev);
	struct hid_usage *usage;
	int old_keycode;

	if (keycode < 0 || keycode > KEY_MAX)
		return -EINVAL;

	usage = hidinput_find_key(hid, scancode, 0);
	if (usage) {
		old_keycode = usage->code;
+1 −1
Original line number Diff line number Diff line
@@ -515,7 +515,7 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
	struct input_absinfo abs;
	struct ff_effect effect;
	int __user *ip = (int __user *)p;
	int i, t, u, v;
	unsigned int i, t, u, v;
	int error;

	switch (cmd) {
+9 −11
Original line number Diff line number Diff line
@@ -582,7 +582,8 @@ static int input_fetch_keycode(struct input_dev *dev, int scancode)
}

static int input_default_getkeycode(struct input_dev *dev,
				    int scancode, int *keycode)
				    unsigned int scancode,
				    unsigned int *keycode)
{
	if (!dev->keycodesize)
		return -EINVAL;
@@ -596,7 +597,8 @@ static int input_default_getkeycode(struct input_dev *dev,
}

static int input_default_setkeycode(struct input_dev *dev,
				    int scancode, int keycode)
				    unsigned int scancode,
				    unsigned int keycode)
{
	int old_keycode;
	int i;
@@ -654,11 +656,9 @@ static int input_default_setkeycode(struct input_dev *dev,
 * This function should be called by anyone interested in retrieving current
 * keymap. Presently keyboard and evdev handlers use it.
 */
int input_get_keycode(struct input_dev *dev, int scancode, int *keycode)
int input_get_keycode(struct input_dev *dev,
		      unsigned int scancode, unsigned int *keycode)
{
	if (scancode < 0)
		return -EINVAL;

	return dev->getkeycode(dev, scancode, keycode);
}
EXPORT_SYMBOL(input_get_keycode);
@@ -672,16 +672,14 @@ EXPORT_SYMBOL(input_get_keycode);
 * This function should be called by anyone needing to update current
 * keymap. Presently keyboard and evdev handlers use it.
 */
int input_set_keycode(struct input_dev *dev, int scancode, int keycode)
int input_set_keycode(struct input_dev *dev,
		      unsigned int scancode, unsigned int keycode)
{
	unsigned long flags;
	int old_keycode;
	int retval;

	if (scancode < 0)
		return -EINVAL;

	if (keycode < 0 || keycode > KEY_MAX)
	if (keycode > KEY_MAX)
		return -EINVAL;

	spin_lock_irqsave(&dev->event_lock, flags);
+7 −7
Original line number Diff line number Diff line
@@ -474,10 +474,11 @@ static void ati_remote2_complete_key(struct urb *urb)
}

static int ati_remote2_getkeycode(struct input_dev *idev,
				  int scancode, int *keycode)
				  unsigned int scancode, unsigned int *keycode)
{
	struct ati_remote2 *ar2 = input_get_drvdata(idev);
	int index, mode;
	unsigned int mode;
	int index;

	mode = scancode >> 8;
	if (mode > ATI_REMOTE2_PC || !((1 << mode) & ar2->mode_mask))
@@ -491,10 +492,12 @@ static int ati_remote2_getkeycode(struct input_dev *idev,
	return 0;
}

static int ati_remote2_setkeycode(struct input_dev *idev, int scancode, int keycode)
static int ati_remote2_setkeycode(struct input_dev *idev,
				  unsigned int scancode, unsigned int keycode)
{
	struct ati_remote2 *ar2 = input_get_drvdata(idev);
	int index, mode, old_keycode;
	unsigned int mode, old_keycode;
	int index;

	mode = scancode >> 8;
	if (mode > ATI_REMOTE2_PC || !((1 << mode) & ar2->mode_mask))
@@ -504,9 +507,6 @@ static int ati_remote2_setkeycode(struct input_dev *idev, int scancode, int keyc
	if (index < 0)
		return -EINVAL;

	if (keycode < KEY_RESERVED || keycode > KEY_MAX)
		return -EINVAL;

	old_keycode = ar2->keycode[mode][index];
	ar2->keycode[mode][index] = keycode;
	__set_bit(keycode, idev->keybit);
+5 −7
Original line number Diff line number Diff line
@@ -385,26 +385,24 @@ wbcir_do_getkeycode(struct wbcir_data *data, u32 scancode)
}

static int
wbcir_getkeycode(struct input_dev *dev, int scancode, int *keycode)
wbcir_getkeycode(struct input_dev *dev,
		 unsigned int scancode, unsigned int *keycode)
{
	struct wbcir_data *data = input_get_drvdata(dev);

	*keycode = (int)wbcir_do_getkeycode(data, (u32)scancode);
	*keycode = wbcir_do_getkeycode(data, scancode);
	return 0;
}

static int
wbcir_setkeycode(struct input_dev *dev, int sscancode, int keycode)
wbcir_setkeycode(struct input_dev *dev,
		 unsigned int scancode, unsigned int keycode)
{
	struct wbcir_data *data = input_get_drvdata(dev);
	struct wbcir_keyentry *keyentry;
	struct wbcir_keyentry *new_keyentry;
	unsigned long flags;
	unsigned int old_keycode = KEY_RESERVED;
	u32 scancode = (u32)sscancode;

	if (keycode < 0 || keycode > KEY_MAX)
		return -EINVAL;

	new_keyentry = kmalloc(sizeof(*new_keyentry), GFP_KERNEL);
	if (!new_keyentry)
Loading