Skip to content

Commit

Permalink
Input: scancode in get/set_keycodes should be unsigned
Browse files Browse the repository at this point in the history
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: Márton Németh <nm127@freemail.hu>
Acked-by: Matthew Garrett <mjg@redhat.com>
Acked-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
  • Loading branch information
dtor committed Mar 9, 2010
1 parent ec62e1c commit 58b9399
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 94 deletions.
24 changes: 12 additions & 12 deletions drivers/hid/hid-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion drivers/input/evdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 9 additions & 11 deletions drivers/input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions drivers/input/misc/ati_remote2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -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);
Expand Down
12 changes: 5 additions & 7 deletions drivers/input/misc/winbond-cir.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions drivers/input/sparse-keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ struct key_entry *sparse_keymap_entry_from_keycode(struct input_dev *dev,
EXPORT_SYMBOL(sparse_keymap_entry_from_keycode);

static int sparse_keymap_getkeycode(struct input_dev *dev,
int scancode, int *keycode)
unsigned int scancode,
unsigned int *keycode)
{
const struct key_entry *key =
sparse_keymap_entry_from_scancode(dev, scancode);
Expand All @@ -78,7 +79,8 @@ static int sparse_keymap_getkeycode(struct input_dev *dev,
}

static int sparse_keymap_setkeycode(struct input_dev *dev,
int scancode, int keycode)
unsigned int scancode,
unsigned int keycode)
{
struct key_entry *key;
int old_keycode;
Expand Down
4 changes: 2 additions & 2 deletions drivers/media/IR/ir-keytable.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static int ir_copy_table(struct ir_scancode_table *destin,
* If the key is not found, returns -EINVAL, otherwise, returns 0.
*/
static int ir_getkeycode(struct input_dev *dev,
int scancode, int *keycode)
unsigned int scancode, unsigned int *keycode)
{
int elem;
struct ir_input_dev *ir_dev = input_get_drvdata(dev);
Expand Down Expand Up @@ -291,7 +291,7 @@ static int ir_insert_key(struct ir_scancode_table *rc_tab,
* If the key is not found, returns -EINVAL, otherwise, returns 0.
*/
static int ir_setkeycode(struct input_dev *dev,
int scancode, int keycode)
unsigned int scancode, unsigned int keycode)
{
int rc = 0;
struct ir_input_dev *ir_dev = input_get_drvdata(dev);
Expand Down
4 changes: 2 additions & 2 deletions drivers/media/dvb/dvb-usb/dvb-usb-remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <linux/usb/input.h>

static int dvb_usb_getkeycode(struct input_dev *dev,
int scancode, int *keycode)
unsigned int scancode, unsigned int *keycode)
{
struct dvb_usb_device *d = input_get_drvdata(dev);

Expand Down Expand Up @@ -39,7 +39,7 @@ static int dvb_usb_getkeycode(struct input_dev *dev,
}

static int dvb_usb_setkeycode(struct input_dev *dev,
int scancode, int keycode)
unsigned int scancode, unsigned int keycode)
{
struct dvb_usb_device *d = input_get_drvdata(dev);

Expand Down
16 changes: 7 additions & 9 deletions drivers/platform/x86/dell-wmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static struct key_entry *dell_wmi_keymap = dell_legacy_wmi_keymap;

static struct input_dev *dell_wmi_input_dev;

static struct key_entry *dell_wmi_get_entry_by_scancode(int code)
static struct key_entry *dell_wmi_get_entry_by_scancode(unsigned int code)
{
struct key_entry *key;

Expand All @@ -153,7 +153,7 @@ static struct key_entry *dell_wmi_get_entry_by_scancode(int code)
return NULL;
}

static struct key_entry *dell_wmi_get_entry_by_keycode(int keycode)
static struct key_entry *dell_wmi_get_entry_by_keycode(unsigned int keycode)
{
struct key_entry *key;

Expand All @@ -164,8 +164,8 @@ static struct key_entry *dell_wmi_get_entry_by_keycode(int keycode)
return NULL;
}

static int dell_wmi_getkeycode(struct input_dev *dev, int scancode,
int *keycode)
static int dell_wmi_getkeycode(struct input_dev *dev,
unsigned int scancode, unsigned int *keycode)
{
struct key_entry *key = dell_wmi_get_entry_by_scancode(scancode);

Expand All @@ -177,13 +177,11 @@ static int dell_wmi_getkeycode(struct input_dev *dev, int scancode,
return -EINVAL;
}

static int dell_wmi_setkeycode(struct input_dev *dev, int scancode, int keycode)
static int dell_wmi_setkeycode(struct input_dev *dev,
unsigned int scancode, unsigned int keycode)
{
struct key_entry *key;
int old_keycode;

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

key = dell_wmi_get_entry_by_scancode(scancode);
if (key && key->type == KE_KEY) {
Expand Down
15 changes: 7 additions & 8 deletions drivers/platform/x86/hp-wmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ static DEVICE_ATTR(als, S_IRUGO | S_IWUSR, show_als, set_als);
static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL);
static DEVICE_ATTR(tablet, S_IRUGO, show_tablet, NULL);

static struct key_entry *hp_wmi_get_entry_by_scancode(int code)
static struct key_entry *hp_wmi_get_entry_by_scancode(unsigned int code)
{
struct key_entry *key;

Expand All @@ -289,7 +289,7 @@ static struct key_entry *hp_wmi_get_entry_by_scancode(int code)
return NULL;
}

static struct key_entry *hp_wmi_get_entry_by_keycode(int keycode)
static struct key_entry *hp_wmi_get_entry_by_keycode(unsigned int keycode)
{
struct key_entry *key;

Expand All @@ -300,7 +300,8 @@ static struct key_entry *hp_wmi_get_entry_by_keycode(int keycode)
return NULL;
}

static int hp_wmi_getkeycode(struct input_dev *dev, int scancode, int *keycode)
static int hp_wmi_getkeycode(struct input_dev *dev,
unsigned int scancode, unsigned int *keycode)
{
struct key_entry *key = hp_wmi_get_entry_by_scancode(scancode);

Expand All @@ -312,13 +313,11 @@ static int hp_wmi_getkeycode(struct input_dev *dev, int scancode, int *keycode)
return -EINVAL;
}

static int hp_wmi_setkeycode(struct input_dev *dev, int scancode, int keycode)
static int hp_wmi_setkeycode(struct input_dev *dev,
unsigned int scancode, unsigned int keycode)
{
struct key_entry *key;
int old_keycode;

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

key = hp_wmi_get_entry_by_scancode(scancode);
if (key && key->type == KE_KEY) {
Expand Down
15 changes: 7 additions & 8 deletions drivers/platform/x86/panasonic-laptop.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ static struct acpi_driver acpi_pcc_driver = {
};

#define KEYMAP_SIZE 11
static const int initial_keymap[KEYMAP_SIZE] = {
static const unsigned int initial_keymap[KEYMAP_SIZE] = {
/* 0 */ KEY_RESERVED,
/* 1 */ KEY_BRIGHTNESSDOWN,
/* 2 */ KEY_BRIGHTNESSUP,
Expand All @@ -222,7 +222,7 @@ struct pcc_acpi {
struct acpi_device *device;
struct input_dev *input_dev;
struct backlight_device *backlight;
int keymap[KEYMAP_SIZE];
unsigned int keymap[KEYMAP_SIZE];
};

struct pcc_keyinput {
Expand Down Expand Up @@ -445,7 +445,8 @@ static struct attribute_group pcc_attr_group = {

/* hotkey input device driver */

static int pcc_getkeycode(struct input_dev *dev, int scancode, int *keycode)
static int pcc_getkeycode(struct input_dev *dev,
unsigned int scancode, unsigned int *keycode)
{
struct pcc_acpi *pcc = input_get_drvdata(dev);

Expand All @@ -457,7 +458,7 @@ static int pcc_getkeycode(struct input_dev *dev, int scancode, int *keycode)
return 0;
}

static int keymap_get_by_keycode(struct pcc_acpi *pcc, int keycode)
static int keymap_get_by_keycode(struct pcc_acpi *pcc, unsigned int keycode)
{
int i;

Expand All @@ -469,17 +470,15 @@ static int keymap_get_by_keycode(struct pcc_acpi *pcc, int keycode)
return 0;
}

static int pcc_setkeycode(struct input_dev *dev, int scancode, int keycode)
static int pcc_setkeycode(struct input_dev *dev,
unsigned int scancode, unsigned int keycode)
{
struct pcc_acpi *pcc = input_get_drvdata(dev);
int oldkeycode;

if (scancode >= ARRAY_SIZE(pcc->keymap))
return -EINVAL;

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

oldkeycode = pcc->keymap[scancode];
pcc->keymap[scancode] = keycode;

Expand Down
Loading

0 comments on commit 58b9399

Please sign in to comment.