HID: steam: Add 2026 Steam Controller support
Subsystems (2)
Vicki Pfau
maintainerv5 cover HID: steam: Add 2026 Steam Controller support
This is the second half of a series that modernizes the hid-steam controller. It adds support for the new 2026 Steam Controller, with feature parity compared to the 2015 model and the Steam Deck drivers, as well as some smaller cleanup. The biggest cleanup is cleaning up the somewhat lax locking practices, but a few more minor things exposed to userspace include logging improvements and zeroing inputs when switching from gamepad mode to lizard mode.
This has a little bit of code cleanup and fixes some lock safety issues.
Vicki Pfau (6):
HID: steam: Refactor registration
HID: steam: Initial 2026 Steam Controller support
HID: steam: Fix wording of connect/disconnect logs
HID: steam: Don't set feature reports when disconnecting
HID: steam: Clean up locking
HID: steam: Zero out inputs when disabling gamepad mode
drivers/hid/hid-ids.h | 4 + drivers/hid/hid-steam.c | 1033 ++++++++++++++++++++++++++++++++------- 2 files changed, 848 insertions(+), 189 deletions(-)
Signature · 1 line
2.54.0
Vicki Pfau
maintainerPATCH v5 1/6 HID: steam: Refactor registration
This refactors and simplifies the registration/unregistration flow. Since we now only perform registration when the client isn't opened anymore, the logic for handling that can be removed, and the rest of the function streamlined.
We also remove the previous assumption that we have a serial number to show we're registered, replacing it with a single purpose boolean.
In a previous refactor the code for unregistering a battery if later registration steps failed was accidentally left out. As a result, a lingering power_supply object could get left over after the steam object was torn down. This is also fixed here.
--- drivers/hid/hid-steam.c | 81 +++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 43 deletions(-)
drivers/hid/hid-steam.c +38 -43
@@ -334,6 +334,7 @@ struct steam_device {unsigned long quirks;struct work_struct work_connect;bool connected; +bool registered;char serial_no[STEAM_SERIAL_LEN +1 ];struct power_supply_desc battery_desc;struct power_supply __rcu *battery;
@@ -1139,9 +1140,6 @@ static void steam_battery_unregister(struct steam_device *steam)static int steam_register (struct steam_device *steam) {int ret; -unsigned long client_opened; -unsigned long flags; -bool do_add;/* * This function can be called several times in a row with the
@@ -1149,66 +1147,63 @@ static int steam_register(struct steam_device *steam)* another client send a get_connection_status command, for example. * The battery and serial number are set just once per device. */ -if (!steam->serial_no[0 ]) { -/* -* Unlikely, but getting the serial could fail, and it is not so -* important, so make up a serial number and go on. -*/ -if (steam_get_serial (steam) <0 ) -strscpy (steam->serial_no,"XXXXXXXXXX" , -sizeof (steam->serial_no)); - - ret =steam_get_attributes (steam); -if (ret <0 ) -hid_err (steam->hdev, -"%s:steam_get_attributes failed with error %d\n" , - __func__, ret); +if (steam->registered) +return 0 ; -hid_info (steam->hdev,"Steam Controller '%s' connected" , - steam->serial_no); +/* +* Unlikely, but getting the serial could fail, and it is not so +* important, so make up a serial number and go on. +*/ +if (steam_get_serial (steam) <0 || !steam->serial_no[0 ]) +strscpy (steam->serial_no,"XXXXXXXXXX" , +sizeof (steam->serial_no)); -/* ignore battery errors, we can live without it */ -if (steam->quirks &STEAM_QUIRK_WIRELESS ) -steam_battery_register (steam); + ret =steam_get_attributes (steam); +if (ret <0 ) +hid_err (steam->hdev, +"%s:steam_get_attributes failed with error %d\n" , + __func__, ret); - do_add = true; - } +hid_info (steam->hdev,"Steam Controller '%s' connected" , + steam->serial_no); -spin_lock_irqsave (&steam->lock, flags); - client_opened = steam->client_opened; -spin_unlock_irqrestore (&steam->lock, flags); +/* ignore battery errors, we can live without it */ +if (steam->quirks &STEAM_QUIRK_WIRELESS ) +steam_battery_register (steam); -if (!client_opened) { -steam_set_lizard_mode (steam, lizard_mode); - ret =steam_input_register (steam); -if (ret !=0 ) - goto steam_register_input_fail; - ret =steam_sensors_register (steam); -if (ret !=0 ) - goto steam_register_sensors_fail; - } +steam_set_lizard_mode (steam, lizard_mode); + ret =steam_input_register (steam); +if (ret !=0 ) + goto steam_register_input_fail; + ret =steam_sensors_register (steam); +if (ret !=0 ) + goto steam_register_sensors_fail; -if (do_add) { -mutex_lock (&steam_devices_lock); -if (list_empty (&steam->list)) -list_add (&steam->list, &steam_devices); -mutex_unlock (&steam_devices_lock); - } + steam->registered = true; +mutex_lock (&steam_devices_lock); +if (list_empty (&steam->list)) +list_add (&steam->list, &steam_devices); +mutex_unlock (&steam_devices_lock);return 0 ; steam_register_sensors_fail:steam_input_unregister (steam); steam_register_input_fail: +steam_battery_unregister (steam); +cancel_work_sync (&steam->rumble_work); +cancel_delayed_work_sync (&steam->mode_switch); +cancel_delayed_work_sync (&steam->coalesce_rumble_work);return ret; }static void steam_unregister (struct steam_device *steam) { -if (!steam->serial_no[0 ]) +if (!steam->registered)return ;hid_info (steam->hdev,"Steam Controller '%s' disconnected" , steam->serial_no); + steam->registered = false;steam_battery_unregister (steam);steam_sensors_unregister (steam);steam_input_unregister (steam);
Signature · 1 line
2.54.0
Vicki Pfau
maintainerPATCH v5 2/6 HID: steam: Initial 2026 Steam Controller support
In reply to Vicki PfauThis brings support for the 2026 Steam Controller, comparably featureful to the existing support for the Steam Deck.
--- drivers/hid/hid-ids.h | 4 + drivers/hid/hid-steam.c | 783 ++++++++++++++++++++++++++++++++++------ 2 files changed, 682 insertions(+), 105 deletions(-)
drivers/hid/hid-ids.h +4 -0
@@ -1374,6 +1374,10 @@#define USB_DEVICE_ID_STEAM_CONTROLLER 0x1102#define USB_DEVICE_ID_STEAM_CONTROLLER_WIRELESS 0x1142#define USB_DEVICE_ID_STEAM_DECK 0x1205 +#define USB_DEVICE_ID_STEAM_CONTROLLER_IBEX 0x1302 +#define USB_DEVICE_ID_STEAM_CONTROLLER_IBEX_BLE 0x1303 +#define USB_DEVICE_ID_STEAM_CONTROLLER_PROTEUS 0x1304 +#define USB_DEVICE_ID_STEAM_CONTROLLER_NEREID 0x1305#define USB_VENDOR_ID_STEELSERIES 0x1038#define USB_DEVICE_ID_STEELSERIES_SRWS1 0x1410
drivers/hid/hid-steam.c +678 -105
1,124 lines not on this page · raw message
Signature · 1 line
2.54.0
Vicki Pfau
maintainerPATCH v5 3/6 HID: steam: Fix wording of connect/disconnect logs
In reply to Vicki PfauIt always said Controller, even on Deck. Since we special-case other instances of Controller vs. Deck in strings, let's be consistent here too.
--- drivers/hid/hid-steam.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/hid/hid-steam.c +4 -2
@@ -1391,7 +1391,8 @@ static int steam_register(struct steam_device *steam)"%s:steam_get_attributes failed with error %d\n" , __func__, ret); -hid_info (steam->hdev,"Steam Controller '%s' connected" , +hid_info (steam->hdev,"Steam %s '%s' connected" , + steam->quirks &STEAM_QUIRK_DECK ?"Deck" :"Controller" , steam->serial_no);/* ignore battery errors, we can live without it */
@@ -1428,7 +1429,8 @@ static void steam_unregister(struct steam_device *steam)if (!steam->registered)return ; -hid_info (steam->hdev,"Steam Controller '%s' disconnected" , +hid_info (steam->hdev,"Steam %s '%s' disconnected" , + steam->quirks &STEAM_QUIRK_DECK ?"Deck" :"Controller" , steam->serial_no); steam->registered = false;steam_battery_unregister (steam);
Signature · 1 line
2.54.0
Vicki Pfau
maintainerPATCH v5 4/6 HID: steam: Don't set feature reports when disconnecting
In reply to Vicki PfauWhen an input device is closed, we set a feature report to reset lizard mode and IMU mode. However, if the input device is closed because it was removed, then we will necessarily error out when sending this, resulting in logged errors. Since an error here is expected, we should just fail silently.
--- drivers/hid/hid-steam.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/hid/hid-steam.c +11 -3
@@ -490,9 +490,13 @@ static int steam_recv_report_id(struct steam_device *steam, }kfree (buf); -if (ret <0 ) +/* +* Don't log if the failure is -ENODEV, as this +* can happen normally on disconnect. +*/ +if (ret <0 && ret != -ENODEV )hid_err (steam->hdev,"%s: error %d\n" , __func__, ret); -else +else if (ret >0 )hid_dbg (steam->hdev,"Received report %*ph\n" , size, data);if (ret <0 )return ret;
@@ -557,7 +561,11 @@ static int steam_send_report_id(struct steam_device *steam, }while (--retries);kfree (buf); -if (ret <0 ) +/* +* Don't log if the failure is -ENODEV, as this +* can happen normally on disconnect. +*/ +if (ret <0 && ret != -ENODEV )hid_err (steam->hdev,"%s: error %d (%*ph)\n" , __func__, ret, size, cmd);return ret;
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v5 4/6] HID: steam: Don't set feature reports when disconnecting
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Use-after-free in steam_remove() due to incorrect cancellation order of deferred work. --
--- Patch [4]: [PATCH v5 4/6] HID: steam: Don't set feature reports when disconnecting --- commit 460f363e27307cbdb952f6004dd3826de0898a07
Author: Vicki Pfau <[email protected]>
HID: steam: Don't set feature reports when disconnecting
When an input device is closed, we set a feature report to reset lizard mode and IMU mode. However, if the input device is closed because it was removed, then we will necessarily error out when sending this, resulting in logged errors. Since an error here is expected, we should just fail silently.
Quoted 5 lines
drivers/hid/hid-steam.c +0
-0
drivers/hid/hid-steam.c static int steam_recv_report_id(struct steam_device *steam, · line 498
Quoted 10 lines
drivers/hid/hid-steam.c +5
-1@@ -490,9 +490,13 @@ static int steam_recv_report_id(struct steam_device *steam, }kfree (buf); -if (ret <0 ) +/* +* Don't log if the failure is -ENODEV, as this +* can happen normally on disconnect. +*/ +if (ret <0 && ret != -ENODEV )hid_err (steam->hdev,"%s: error %d\n" , __func__, ret);
[Severity: High]
This is a pre-existing issue, but while reviewing device disconnects, I noticed a potential use-after-free during device removal in steam_remove().
Looking at steam_remove(), cancel_work_sync(&steam->work_connect) is called before hid_hw_stop(hdev):
drivers/hid/hid-steam.c:steam_remove() {
...
cancel_work_sync(&steam->work_connect);
if (steam->quirks & STEAM_QUIRK_WIRELESS) {
hid_info(hdev, "Steam wireless receiver disconnected");
}
steam_unregister(steam);
hid_hw_stop(hdev);
}Because hid_hw_stop() is called last, hardware interrupts can still trigger steam_raw_event() after the work item is cancelled. If a wireless connection event (ID_CONTROLLER_WIRELESS) or an unexpected input report arrives during this window, steam_raw_event() will invoke steam_do_connect_event(), which re-schedules steam->work_connect:
drivers/hid/hid-steam.c:steam_raw_event() {
...
case ID_CONTROLLER_WIRELESS:
...
switch (data[4]) {
...
case 0x02:
steam_do_connect_event(steam, true);
break;
...
}After steam_remove() returns and the device memory is freed by devres, the workqueue retains the pending work, which could access the freed memory when it runs.
Should hid_hw_stop(hdev) be called before cancel_work_sync() to ensure no new events can queue the work?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Vicki Pfau
maintainerPATCH v5 5/6 HID: steam: Clean up locking
In reply to Vicki PfauThis cleans up several issues with locking behavior, including RCU accesses not being guarded behind a lock.
--- drivers/hid/hid-steam.c | 105 +++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 49 deletions(-)
drivers/hid/hid-steam.c +56 -49
@@ -403,6 +403,7 @@ struct steam_device {spinlock_t lock;struct hid_device *hdev, *client_hdev;struct mutex report_mutex; +struct mutex registration_mutex;unsigned long client_opened;struct input_dev __rcu *input;struct input_dev __rcu *sensors;
@@ -620,7 +621,6 @@ static int steam_exchange_report_id(struct steam_device *steam, u8 *cmd, int csiunsigned int retries =5 ;int ret; -guard (mutex)(&steam->report_mutex); do { ret = steam_send_report_id(steam, cmd, csize, report_id); if (ret < 0)
@@ -784,7 +784,6 @@ static inline int steam_haptic_pulse(struct steam_device *steam, u8 pad, report[8 ] = count >>8 ; report[9 ] = gain; -guard (mutex)(&steam->report_mutex); ret =steam_send_report (steam, report,10 ); }
@@ -826,7 +825,6 @@ static inline int steam_haptic_rumble(struct steam_device *steam, report[9 ] = left_gain; report[10 ] = right_gain; -guard (mutex)(&steam->report_mutex); ret =steam_send_report (steam, report,sizeof (report)); }return ret;
@@ -837,8 +835,10 @@ static void steam_haptic_rumble_cb(struct work_struct *work) struct steam_device *steam = container_of(work, struct steam_device, rumble_work); +mutex_lock (&steam->report_mutex);steam_haptic_rumble (steam,0 , steam->rumble_left, steam->rumble_right,2 ,0 ); +mutex_unlock (&steam->report_mutex); }static void steam_coalesce_rumble_cb (struct work_struct *work)
@@ -847,8 +847,10 @@ static void steam_coalesce_rumble_cb(struct work_struct *work) struct steam_device, coalesce_rumble_work); +mutex_lock (&steam->report_mutex);steam_haptic_rumble (steam,0 , steam->rumble_left, steam->rumble_right,2 ,0 ); +mutex_unlock (&steam->report_mutex);if (steam->rumble_left || steam->rumble_right)schedule_delayed_work (&steam->coalesce_rumble_work,HZ /20 );
@@ -880,7 +882,6 @@ static void steam_set_lizard_mode(struct steam_device *steam, bool enable)if (steam->gamepad_mode) enable = false; -mutex_lock (&steam->report_mutex);if (enable) {/* enable esc, enter, cursors */ steam_send_report_byte (steam,ID_SET_DEFAULT_DIGITAL_MAPPINGS );
@@ -903,14 +904,13 @@ static void steam_set_lizard_mode(struct steam_device *steam, bool enable)SETTING_RIGHT_TRACKPAD_MODE ,TRACKPAD_NONE ,/* disable mouse */ 0); } -mutex_unlock (&steam->report_mutex); }static int steam_input_open (struct input_dev *dev) {struct steam_device *steam =input_get_drvdata (dev);unsigned long flags; -bool set_lizard_mode; +bool client_opened;/* * Disabling lizard mode automatically is only done on the Steam
@@ -919,9 +919,10 @@ static int steam_input_open(struct input_dev *dev)*/ if (!(steam->quirks & (STEAM_QUIRK_DECK |STEAM_QUIRK_IBEX ))) {spin_lock_irqsave (&steam->lock, flags); - set_lizard_mode = !steam->client_opened && lizard_mode; + client_opened = steam->client_opened;spin_unlock_irqrestore (&steam->lock, flags); -if (set_lizard_mode) +guard (mutex)(&steam->report_mutex); +if (!client_opened && lizard_mode)steam_set_lizard_mode (steam, false); }
@@ -932,13 +933,14 @@ static void steam_input_close(struct input_dev *dev) {struct steam_device *steam =input_get_drvdata (dev);unsigned long flags; -bool set_lizard_mode; +bool client_opened;if (!(steam->quirks & (STEAM_QUIRK_DECK |STEAM_QUIRK_IBEX ))) {spin_lock_irqsave (&steam->lock, flags); - set_lizard_mode = !steam->client_opened && lizard_mode; + client_opened = steam->client_opened;spin_unlock_irqrestore (&steam->lock, flags); -if (set_lizard_mode) +guard (mutex)(&steam->report_mutex); +if (!client_opened && lizard_mode)steam_set_lizard_mode (steam, true); } }
@@ -946,14 +948,11 @@ static void steam_input_close(struct input_dev *dev)static int steam_sensor_open (struct input_dev *dev) {struct steam_device *steam =input_get_drvdata (dev); -unsigned long flags; -bool client_opened; -spin_lock_irqsave (&steam->lock, flags); - client_opened = steam->client_opened; -spin_unlock_irqrestore (&steam->lock, flags); -if (client_opened) -return 0 ; + scoped_guard(spinlock_irqsave, &steam->lock) { +if (steam->client_opened) +return 0 ; + }guard (mutex)(&steam->report_mutex); steam_write_settings(steam, SETTING_IMU_MODE,
@@ -966,14 +965,11 @@ static int steam_sensor_open(struct input_dev *dev)static void steam_sensor_close (struct input_dev *dev) {struct steam_device *steam =input_get_drvdata (dev); -unsigned long flags; -bool client_opened; -spin_lock_irqsave (&steam->lock, flags); - client_opened = steam->client_opened; -spin_unlock_irqrestore (&steam->lock, flags); -if (client_opened) -return ; + scoped_guard(spinlock_irqsave, &steam->lock) { +if (steam->client_opened) +return ; + }guard (mutex)(&steam->report_mutex);steam_write_settings (steam,SETTING_IMU_MODE ,0 ,0 );
@@ -1377,14 +1373,18 @@ static int steam_register(struct steam_device *steam) {int ret; +mutex_lock (&steam->registration_mutex);/* * This function can be called several times in a row with the * wireless adaptor, without steam_unregister() between them, because * another client send a get_connection_status command, for example. */ -if (steam->registered) +if (steam->registered) { +mutex_unlock (&steam->registration_mutex);return 0 ; + } +mutex_lock (&steam->report_mutex);/* * Unlikely, but getting the serial could fail, and it is not so * important, so make up a serial number and go on.
@@ -1403,11 +1403,13 @@ static int steam_register(struct steam_device *steam) steam->quirks &STEAM_QUIRK_DECK ?"Deck" :"Controller" , steam->serial_no); +steam_set_lizard_mode (steam, lizard_mode); +mutex_unlock (&steam->report_mutex); +/* ignore battery errors, we can live without it */ if (steam->quirks & (STEAM_QUIRK_WIRELESS |STEAM_QUIRK_IBEX ))steam_battery_register (steam); -steam_set_lizard_mode (steam, lizard_mode); ret =steam_input_register (steam);if (ret !=0 ) goto steam_register_input_fail;
@@ -1416,6 +1418,7 @@ static int steam_register(struct steam_device *steam) goto steam_register_sensors_fail; steam->registered = true; +mutex_unlock (&steam->registration_mutex);mutex_lock (&steam_devices_lock);if (list_empty (&steam->list))list_add (&steam->list, &steam_devices);
@@ -1426,6 +1429,7 @@ static int steam_register(struct steam_device *steam)steam_input_unregister (steam); steam_register_input_fail:steam_battery_unregister (steam); +mutex_unlock (&steam->registration_mutex);cancel_work_sync (&steam->rumble_work);cancel_delayed_work_sync (&steam->mode_switch);cancel_delayed_work_sync (&steam->coalesce_rumble_work);
@@ -1440,10 +1444,12 @@ static void steam_unregister(struct steam_device *steam)hid_info (steam->hdev,"Steam %s '%s' disconnected" , steam->quirks &STEAM_QUIRK_DECK ?"Deck" :"Controller" , steam->serial_no); +mutex_lock (&steam->registration_mutex); steam->registered = false;steam_battery_unregister (steam);steam_sensors_unregister (steam);steam_input_unregister (steam); +mutex_unlock (&steam->registration_mutex);cancel_work_sync (&steam->rumble_work);cancel_delayed_work_sync (&steam->mode_switch);cancel_delayed_work_sync (&steam->coalesce_rumble_work);
@@ -1484,23 +1490,26 @@ static void steam_mode_switch_cb(struct work_struct *work) struct steam_device, mode_switch);unsigned long flags;bool client_opened; +bool gamepad_mode; +if (!lizard_mode)return ; +spin_lock_irqsave (&steam->lock, flags); steam->gamepad_mode = !steam->gamepad_mode; -hid_dbg (steam->hdev,"%s: switching gamepad mode to %i\n" , __func__, steam->gamepad_mode); -if (steam->gamepad_mode) + gamepad_mode = steam->gamepad_mode; + client_opened = steam->client_opened; +spin_unlock_irqrestore (&steam->lock, flags); + +guard (mutex)(&steam->report_mutex); +hid_dbg (steam->hdev,"%s: switching gamepad mode to %i\n" , __func__, gamepad_mode); +if (gamepad_mode)steam_set_lizard_mode (steam, false); -else { -spin_lock_irqsave (&steam->lock, flags); - client_opened = steam->client_opened; -spin_unlock_irqrestore (&steam->lock, flags); -if (!client_opened) -steam_set_lizard_mode (steam, lizard_mode); - } +else if (!client_opened) +steam_set_lizard_mode (steam, lizard_mode);steam_haptic_pulse (steam,STEAM_PAD_RIGHT ,0x190 ,0 ,1 ,0 ); -if (steam->gamepad_mode) { +if (gamepad_mode) {steam_haptic_pulse (steam,STEAM_PAD_LEFT ,0x14D ,0x14D ,0x2D ,0 ); }else {steam_haptic_pulse (steam,STEAM_PAD_LEFT ,0x1F4 ,0x1F4 ,0x1E ,0 );
@@ -1687,6 +1696,7 @@ static int steam_probe(struct hid_device *hdev,hid_set_drvdata (hdev, steam);spin_lock_init (&steam->lock);mutex_init (&steam->report_mutex); +mutex_init (&steam->registration_mutex); steam->quirks = id->driver_data;INIT_WORK (&steam->work_connect, steam_work_connect_cb);INIT_DELAYED_WORK (&steam->mode_switch, steam_mode_switch_cb);
@@ -1795,13 +1805,10 @@ static void steam_remove(struct hid_device *hdev)static void steam_do_connect_event (struct steam_device *steam,bool connected) { -unsigned long flags;bool changed; -spin_lock_irqsave (&steam->lock, flags); changed = steam->connected != connected; steam->connected = connected; -spin_unlock_irqrestore (&steam->lock, flags);if (changed &&schedule_work (&steam->work_connect) ==0 ) dbg_hid("%s: connected=%d event already queued\n",
@@ -2230,8 +2237,6 @@ static void steam_do_deck_sensors_event(struct steam_device *steam,static void steam_do_battery_event (struct steam_device *steam,struct power_supply *battery,u8 *data) { -unsigned long flags; -s16 volts =steam_le16 (data +12 );u8 batt = data[14 ];
@@ -2239,10 +2244,8 @@ static void steam_do_battery_event(struct steam_device *steam,rcu_read_lock (); battery =rcu_dereference (steam->battery);if (likely (battery)) { -spin_lock_irqsave (&steam->lock, flags); steam->battery_voltage = volts; steam->battery_charge = batt; -spin_unlock_irqrestore (&steam->lock, flags);power_supply_changed (battery); }rcu_read_unlock ();
@@ -2427,15 +2430,12 @@ static void steam_do_ibex_battery_event(struct steam_device *steam,struct power_supply *battery, const struct steam_ibex_battery_status *data) { - unsigned long flags; -/* Creating the battery may have failed */ guard (rcu )(); battery =rcu_dereference (steam->battery);if (!likely (battery))return ; -spin_lock_irqsave (&steam->lock, flags); steam->battery_voltage =get_unaligned_le16 (&data->battery_voltage); steam->battery_current =get_unaligned_le16 (&data->battery_current); steam->battery_temp =get_unaligned_le16 (&data->temperature);
@@ -2454,7 +2454,6 @@ static void steam_do_ibex_battery_event(struct steam_device *steam, steam->battery_status =POWER_SUPPLY_STATUS_UNKNOWN ;break ; } -spin_unlock_irqrestore (&steam->lock, flags);power_supply_changed (battery); }
@@ -2470,6 +2469,7 @@ static int steam_raw_event(struct hid_device *hdev,if (!steam)return 0 ; +guard (spinlock_irqsave)(&steam->lock);if (steam->client_opened)hid_input_report (steam->client_hdev, report->type, data, size,0 );
@@ -2633,6 +2633,8 @@ static int steam_param_set_lizard_mode(const char *val, {struct steam_device *steam;int ret; +bool client_opened; +unsigned long flags; ret =param_set_bool (val, kp);if (ret)
@@ -2640,8 +2642,13 @@ static int steam_param_set_lizard_mode(const char *val,mutex_lock (&steam_devices_lock);list_for_each_entry (steam, &steam_devices, list) { -if (!steam->client_opened) +spin_lock_irqsave (&steam->lock, flags); + client_opened = steam->client_opened; +spin_unlock_irqrestore (&steam->lock, flags); +if (!client_opened) { +guard (mutex)(&steam->report_mutex);steam_set_lizard_mode (steam, lizard_mode); + } }mutex_unlock (&steam_devices_lock);return 0 ;
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v5 5/6] HID: steam: Clean up locking
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
New issues:
- [High] Missing report_mutex protection in steam_probe causes HID report interleaving and initialization failures.
Pre-existing issues:
- [High] Time-of-check to time-of-use (TOCTOU) race in steam_unregister leads to resource leakage and Use-After-Free.
- [High] Use-After-Free or NULL pointer dereference in steam_remove due to incorrect teardown order.
- [High] Information leak of uninitialized kernel heap memory to the USB device.
--
--- Patch [5]: [PATCH v5 5/6] HID: steam: Clean up locking --- commit 0b18780ca8de0e3b0d434638ab8287e9b2859654
Author: Vicki Pfau <[email protected]>
HID: steam: Clean up locking
This cleans up several issues with locking behavior, including RCU accesses not being guarded behind a lock.
drivers/hid/hid-steam.c static int steam_exchange_report_id(struct steam_device *steam, u8 *cmd, int csi · line 626
Quoted 12 lines
drivers/hid/hid-steam.c +0
-1@@ -620,7 +621,6 @@ static int steam_exchange_report_id(struct steam_device *steam, u8 *cmd, int csiunsigned int retries =5 ;int ret; -guard (mutex)(&steam->report_mutex); do { ret = steam_send_report_id(steam, cmd, csize, report_id); if (ret < 0)
[Severity: High]
Since the guard was removed here, should callers now hold report_mutex?
This regression appears in steam_probe(), where steam_get_conn_status() calls this without the mutex being held:
drivers/hid/hid-steam.c:steam_probe() {
...
if (steam->quirks & STEAM_QUIRK_WIRELESS) {
...
steam->connected = false;
ret = steam_get_conn_status(steam);
...
}Could this allow concurrent wireless events to interleave HID requests and cause initialization failures?
[ ... ]
drivers/hid/hid-steam.c static void steam_unregister(struct steam_device *steam) · line 1455
Quoted 13 lines
drivers/hid/hid-steam.c +2
-0@@ -1440,10 +1444,12 @@ static void steam_unregister(struct steam_device *steam)hid_info (steam->hdev,"Steam %s '%s' disconnected" , steam->quirks &STEAM_QUIRK_DECK ?"Deck" :"Controller" , steam->serial_no); +mutex_lock (&steam->registration_mutex); steam->registered = false;steam_battery_unregister (steam);steam_sensors_unregister (steam);steam_input_unregister (steam); +mutex_unlock (&steam->registration_mutex);cancel_work_sync (&steam->rumble_work);cancel_delayed_work_sync (&steam->mode_switch);cancel_delayed_work_sync (&steam->coalesce_rumble_work);
[Severity: High]
This is a pre-existing issue, but does checking the registered flag outside this new mutex allow a time-of-check to time-of-use race?
If steam_unregister() is called concurrently from the workqueue, it might check if (!steam->registered) and return early before the registration finishes.
Later in steam_remove(), it completely bypasses unregistration if connected is false, leaving registered input nodes pointing to freed memory:
drivers/hid/hid-steam.c:steam_remove() {
...
if (steam->connected)
steam_unregister(steam);
...
}[Severity: High]
This is a pre-existing issue, but is there a use-after-free window in steam_remove() during device teardown?
The client HID device is destroyed before the hardware is stopped:
drivers/hid/hid-steam.c:steam_remove() {
...
hid_destroy_device(steam->client_hdev);
...
hid_hw_stop(hdev);
...
}If the hardware generates an interrupt in this window, could steam_raw_event() attempt to access the freed client_hdev?
[Severity: High]
This is a pre-existing issue, but does steam_send_report_id() leak uninitialized kernel heap memory to the USB device?
When allocating the report buffer, it uses hid_alloc_report_buf() which relies on kmalloc(), not kzalloc():
drivers/hid/hid-steam.c:steam_send_report_id() {
...
buf = hid_alloc_report_buf(r, GFP_KERNEL);
if (!buf)
return -ENOMEM;
buf[0] = report_id;
memcpy(buf + 1, cmd, size);
...
ret = hid_hw_raw_request(steam->hdev, report_id,
buf, max(size + 1, len),
HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
...
}Since only size bytes are copied into buf, will the remaining bytes up to max(size + 1, len) contain uninitialized memory when sent over the bus?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Vicki Pfau
maintainerPATCH v5 6/6 HID: steam: Zero out inputs when disabling gamepad mode
In reply to Vicki PfauWhen gamepad mode is disabled the gamepad input devices will stop receiving updates. However, in the case where there are buttons still pressed this will appear as an indefinitely-held button. Instead we should zero out the inputs to make it look like things are all released. We do the same thing for gyroscope inputs to make sure it doesn't look like it's endlessly rotating, but we freeze the accelerometer input since zero isn't a neutral input on the surface of the Earth.
--- drivers/hid/hid-steam.c | 78 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 4 deletions(-)
drivers/hid/hid-steam.c +74 -4
@@ -1501,13 +1501,83 @@ static void steam_mode_switch_cb(struct work_struct *work) client_opened = steam->client_opened;spin_unlock_irqrestore (&steam->lock, flags); -guard (mutex)(&steam->report_mutex);hid_dbg (steam->hdev,"%s: switching gamepad mode to %i\n" , __func__, gamepad_mode); -if (gamepad_mode) +if (gamepad_mode) { +guard (mutex)(&steam->report_mutex);steam_set_lizard_mode (steam, false); -else if (!client_opened) -steam_set_lizard_mode (steam, lizard_mode); + }else { +struct input_dev *input; +struct input_dev *sensors; + +if (!client_opened) { +guard (mutex)(&steam->report_mutex); +steam_set_lizard_mode (steam, lizard_mode); + } + +/* +* Zero out inputs so it doesn't look like we're holding +* anything indefinitely. +*/ +guard (spinlock_irqsave)(&steam->lock); +rcu_read_lock (); + input =rcu_dereference (steam->input); +if (likely (input)) { +input_report_key (input,BTN_TR2 ,0 ); +input_report_key (input,BTN_TL2 ,0 ); +input_report_key (input,BTN_TR ,0 ); +input_report_key (input,BTN_TL ,0 ); +input_report_key (input,BTN_Y ,0 ); +input_report_key (input,BTN_B ,0 ); +input_report_key (input,BTN_X ,0 ); +input_report_key (input,BTN_A ,0 ); +input_report_key (input,BTN_DPAD_UP ,0 ); +input_report_key (input,BTN_DPAD_RIGHT ,0 ); +input_report_key (input,BTN_DPAD_LEFT ,0 ); +input_report_key (input,BTN_DPAD_DOWN ,0 ); +input_report_key (input,BTN_SELECT ,0 ); +input_report_key (input,BTN_MODE ,0 ); +input_report_key (input,BTN_START ,0 ); +input_report_key (input,BTN_THUMBR ,0 ); +input_report_key (input,BTN_THUMBL ,0 ); +input_report_key (input,BTN_THUMB ,0 ); +input_report_key (input,BTN_THUMB2 ,0 ); +input_report_key (input,BTN_GRIPL ,0 ); +input_report_key (input,BTN_GRIPR ,0 ); + +input_report_abs (input,ABS_X ,0 ); +input_report_abs (input,ABS_Y ,0 ); +input_report_abs (input,ABS_RX ,0 ); +input_report_abs (input,ABS_RY ,0 ); +input_report_abs (input,ABS_HAT0X ,0 ); +input_report_abs (input,ABS_HAT0Y ,0 ); +input_report_abs (input,ABS_HAT2Y ,0 ); +input_report_abs (input,ABS_HAT2X ,0 ); + +if (steam->quirks & (STEAM_QUIRK_DECK |STEAM_QUIRK_IBEX )) { +input_report_key (input,BTN_BASE ,0 ); +input_report_key (input,BTN_GRIPL2 ,0 ); +input_report_key (input,BTN_GRIPR2 ,0 ); + +input_report_abs (input,ABS_HAT1X ,0 ); +input_report_abs (input,ABS_HAT1Y ,0 ); + } + +input_sync (input); + } + sensors =rcu_dereference (steam->sensors); +if (likely (sensors)) { +/* Skip accelerometers since 0 isn't a neutral input */ +input_report_abs (sensors,ABS_RX ,0 ); +input_report_abs (sensors,ABS_RY ,0 ); +input_report_abs (sensors,ABS_RZ ,0 ); + +input_sync (sensors); + } +rcu_read_unlock (); + } + +guard (mutex)(&steam->report_mutex);steam_haptic_pulse (steam,STEAM_PAD_RIGHT ,0x190 ,0 ,1 ,0 );if (gamepad_mode) {steam_haptic_pulse (steam,STEAM_PAD_LEFT ,0x14D ,0x14D ,0x2D ,0 );
Signature · 1 line
2.54.0
Quoted 10 lines · Vicki Pfau
This is the second half of a series that modernizes the hid-steam controller. It adds support for the new 2026 Steam Controller, with feature parity compared to the 2015 model and the Steam Deck drivers, as well as some smaller cleanup. The biggest cleanup is cleaning up the somewhat lax locking practices, but a few more minor things exposed to userspace include logging improvements and zeroing inputs when switching from gamepad mode to lizard mode.
This has a little bit of code cleanup and fixes some lock safety issues.
Quoted 7 lines
Vicki Pfau (6):
HID: steam: Refactor registration
HID: steam: Initial 2026 Steam Controller support
HID: steam: Fix wording of connect/disconnect logs
HID: steam: Don't set feature reports when disconnecting
HID: steam: Clean up locking
HID: steam: Zero out inputs when disabling gamepad mode
Queued in hid.git#for-7.3/steam, thanks.
Signature · 2 lines
Jiri Kosina SUSE Labs