lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2vycv2ka2vnuemvkqh4wnrl6iwdbta5c6wkywpbg3p5oecdecr@n7fjhfjvjwuo>
Date: Thu, 8 Jan 2026 11:50:02 +0100
From: Benjamin Tissoires <bentiss@...nel.org>
To: Tomasz Pakuła <tomasz.pakula.oficjalny@...il.com>
Cc: dmitry.torokhov@...il.com, corbet@....net, jikos@...nel.org, 
	linux-input@...r.kernel.org, linux-kernel@...r.kernel.org, linux-doc@...r.kernel.org, 
	vi@...rift.com, linux-kernel@...imeter.info, peter.hutterer@...-t.net
Subject: Re: [RFC PATCH 4/6] Input: Assign EV_BTN event to HID Joysticks

On Jan 04 2026, Tomasz Pakuła wrote:
> Joysticks will now fire EV_BTN for every of their buttons, even buttons
> that were previously ignored because they were cut off by KEY_MAX. This
> in turns enables joysticks to finally report buttons above 80 which was
> the previous limitation.
> 
> Signed-off-by: Tomasz Pakuła <tomasz.pakula.oficjalny@...il.com>
> ---
>  drivers/hid/hid-input.c | 27 +++++++++++++++++++++------
>  include/linux/input.h   |  2 ++
>  2 files changed, 23 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
> index 900a6fc9813e..1c11077b1577 100644
> --- a/drivers/hid/hid-input.c
> +++ b/drivers/hid/hid-input.c
> @@ -760,11 +760,15 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
>  		case HID_GD_MOUSE:
>  		case HID_GD_POINTER:  code += BTN_MOUSE; break;
>  		case HID_GD_JOYSTICK:
> -				if (code <= 0xf)
> -					code += BTN_JOYSTICK;
> -				else
> -					code += BTN_TRIGGER_HAPPY - 0x10;
> -				break;
> +			if (input->button_count >= INPUT_MAX_BUTTONS)
> +				goto ignore;
> +
> +			code += BTN_JOYSTICK;
> +			if (code > BTN_DEAD)
> +				code += BTN_TRIGGER_HAPPY - BTN_DEAD - 1;
> +			if (code > KEY_MAX)
> +				code = KEY_RESERVED;
> +			break;
>  		case HID_GD_GAMEPAD:
>  				if (code <= 0xf)
>  					code += BTN_GAMEPAD;
> @@ -1379,7 +1383,6 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
>  	}
>  
>  	set_bit(usage->type, input->evbit);
> -
>  	/*
>  	 * This part is *really* controversial:
>  	 * - HID aims at being generic so we should do our best to export
> @@ -1390,12 +1393,18 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
>  	 *   *_MISC+N to overwrite a legitimate even, which confuses userspace
>  	 *   (for instance ABS_MISC + 7 is ABS_MT_SLOT, which has a different
>  	 *   processing)
> +	 * - Joysticks can have arbitrary number of buttons without defined
> +	 *   usages. Buttons that extend beyond KEY_MAX are assigned to
> +	 *   KEY_RESERVED thus deduplication must be disabled for them.
>  	 *
>  	 * If devices still want to use this (at their own risk), they will
>  	 * have to use the quirk HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE, but
>  	 * the default should be a reliable mapping.
>  	 */
>  	while (usage->code <= max && test_and_set_bit(usage->code, bit)) {
> +		if (field->application == HID_GD_JOYSTICK && usage->code == KEY_RESERVED)
> +			break;
> +
>  		if (device->quirks & HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE) {
>  			usage->code = find_next_zero_bit(bit,
>  							 max + 1,
> @@ -1455,6 +1464,12 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
>  	if (usage->type == EV_KEY) {
>  		set_bit(EV_MSC, input->evbit);
>  		set_bit(MSC_SCAN, input->mscbit);
> +
> +		if (field->application == HID_GD_JOYSTICK &&
> +		    (usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) {

Too bad we only set up the button ranges for joysticks, when we could do
this for all HID devices with a button usage page.

It also makes the code hard to follow because we now enable this at the
different place than the other mappings.

Cheers,
Benjamin

> +			set_bit(EV_BTN, input->evbit);
> +			++input->button_count;
> +		}
>  	}
>  
>  	return;
> diff --git a/include/linux/input.h b/include/linux/input.h
> index f6389de4a4d1..7f39c663fa85 100644
> --- a/include/linux/input.h
> +++ b/include/linux/input.h
> @@ -214,6 +214,8 @@ struct input_dev {
>  };
>  #define to_input_dev(d) container_of(d, struct input_dev, dev)
>  
> +#define INPUT_MAX_BUTTONS 2048 /* A sane limit of supported device buttons */
> +
>  /*
>   * Verify that we are in sync with input_device_id mod_devicetable.h #defines
>   */
> -- 
> 2.52.0
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ