summaryrefslogtreecommitdiff
path: root/drivers/hid/hid-steam.c
AgeCommit message (Collapse)AuthorFilesLines
2024-01-15HID: hid-steam: Fix cleanup in probe()Dan Carpenter1-11/+15
There are a number of issues in this code. First of all if steam_create_client_hid() fails then it leads to an error pointer dereference when we call hid_destroy_device(steam->client_hdev). Also there are a number of leaks. hid_hw_stop() is not called if hid_hw_open() fails for example. And it doesn't call steam_unregister() or hid_hw_close(). Fixes: 691ead124a0c ("HID: hid-steam: Clean up locking") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Reviewed-by: Vicki Pfau <vi@endrift.com> Link: https://lore.kernel.org/r/1fd87904-dabf-4879-bb89-72d13ebfc91e@moroto.mountain Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
2024-01-15HID: hid-steam: remove pointless error messageDan Carpenter1-7/+3
This error message doesn't really add any information. If modprobe fails then the user will already know what the error code is. In the case of kmalloc() it's a style violation to print an error message for that because kmalloc has it's own better error messages built in. Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Reviewed-by: Vicki Pfau <vi@endrift.com> Link: https://lore.kernel.org/r/305898fb-6bd4-4749-806c-05ec51bbeb80@moroto.mountain Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
2024-01-02HID: hid-steam: Add gamepad-only mode switched to by holding optionsVicki Pfau1-10/+103
This commit adds a hotkey to switch between "gamepad" mode (mouse and keyboard disabled) and "desktop" mode (gamepad disabled) by holding down the options button (mapped here as the start button). This mirrors the behavior of the official Steam client. This also adds and uses a function for generating haptic pulses, as Steam also does when engaging this hotkey. Signed-off-by: Vicki Pfau <vi@endrift.com> Signed-off-by: Jiri Kosina <jkosina@suse.com>
2024-01-02HID: hid-steam: Better handling of serial number lengthVicki Pfau1-5/+6
The second byte of the GET_STRING_ATTRIB report is a length, so we should set the size of the buffer to be the size we're actually requesting, and only reject the reply if the length out is nonsensical. Signed-off-by: Vicki Pfau <vi@endrift.com> Signed-off-by: Jiri Kosina <jkosina@suse.com>
2024-01-02HID: hid-steam: Update list of identifiers from SDLVicki Pfau1-65/+221
SDL includes a list of settings (formerly called registers in this driver), reports (formerly cmds), and various other identifiers that were provided by Valve. This commit imports a significant chunk of that list as well as replacing most of the guessed names and a handful of magic constants. It also replaces bitmask definitions that used hex with the BIT macro. Signed-off-by: Vicki Pfau <vi@endrift.com> Signed-off-by: Jiri Kosina <jkosina@suse.com>
2024-01-02HID: hid-steam: Make client_opened a counterVicki Pfau1-5/+5
The client_opened variable was used to track if the hidraw was opened by any clients to silence keyboard/mouse events while opened. However, there was no counting of how many clients were opened, so opening two at the same time and then closing one would fool the driver into thinking it had no remaining opened clients. Signed-off-by: Vicki Pfau <vi@endrift.com> Signed-off-by: Jiri Kosina <jkosina@suse.com>
2024-01-02HID: hid-steam: Clean up lockingVicki Pfau1-53/+69
This cleans up the locking logic so that the spinlock is consistently used for access to a small handful of struct variables, and the mutex is exclusively and consistently used for ensuring that mutliple threads aren't trying to send/receive reports at the same time. Previously, only some report transactions were guarded by this mutex, potentially breaking atomicity. The mutex has been renamed to reflect this usage. Signed-off-by: Vicki Pfau <vi@endrift.com> Signed-off-by: Jiri Kosina <jkosina@suse.com>
2024-01-02HID: hid-steam: Disable watchdog instead of using a heartbeatVicki Pfau1-28/+2
The Steam Deck has a setting that controls whether or not the watchdog is enabled, so instead of using a heartbeat to keep the watchdog from triggering, this commit changes the behavior to simply disable the watchdog instead. Signed-off-by: Jiri Kosina <jkosina@suse.com>
2024-01-02HID: hid-steam: Avoid overwriting smoothing parameterVicki Pfau1-5/+0
The original implementation of this driver incorrectly guessed the function of this register. It's not only unnecessary to write to this register for lizard mode but actually counter-productive since it overwrites whatever previous value was intentionally set, for example by Steam. Signed-off-by: Vicki Pfau <vi@endrift.com> Signed-off-by: Jiri Kosina <jkosina@suse.com>
2023-02-22Merge branch 'for-6.3/steam' into for-linusBenjamin Tissoires1-26/+357
Add Steam Deck support (Vicki Pfau)
2023-02-06HID: steam: Constify lowlevel HID driverThomas Weißschuh1-1/+1
Since commit 52d225346904 ("HID: Make lowlevel driver structs const") the lowlevel HID drivers are only exposed as const. Take advantage of this to constify the underlying structure, too. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Link: https://lore.kernel.org/r/20230130-hid-const-ll-driver-v1-4-3fc282b3b1d0@weissschuh.net Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2023-02-06HID: hid-steam: Add rumble on DeckVicki Pfau1-0/+54
The Steam Deck includes a new report that allows for emulating XInput-style rumble motors with the Deck's actuators. This adds support for passing these values directly to the Deck. Signed-off-by: Vicki Pfau <vi@endrift.com> Reviewed-by: Lyude Paul <lyude@redhat.com> Link: https://lore.kernel.org/r/20230126030126.895670-3-vi@endrift.com Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2023-02-06HID: hid-steam: Add Steam Deck supportVicki Pfau1-26/+303
Add preliminary support for the Steam Deck's controller interface. Currently, this only supports the controller inputs and toggling lizard mode (Valve's name for a hardware kb/m emulation mode). It does not support any of the advanced features, such as the motion sensors or force-feedback. The Steam Deck also includes a heartbeat for lizard mode that switches it back on if no reports have been received within a few milliseconds. The official Steam client handles this by sending a handful of configuration reports every few ms, so we copy this behavior by sending configuration reports to disable the mouse and reset the digital mappings every 5ms. As this isn't needed for the older Steam Controller, this is only done on the Steam Deck. Signed-off-by: Vicki Pfau <vi@endrift.com> Reviewed-by: Lyude Paul <lyude@redhat.com> Link: https://lore.kernel.org/r/20230126030126.895670-2-vi@endrift.com Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
2022-10-05Merge branch 'for-6.1/core' into for-linusBenjamin Tissoires1-4/+4
- move from strlcpy with unused retval to strscpy (Wolfram Sang) - Kconfig fixes (Randy Dunlap) - HID-BPF preparatory patches, convert blank defines as enums (Benjamin Tissoires)
2022-08-25HID: move from strlcpy with unused retval to strscpyWolfram Sang1-4/+4
Follow the advice of the below link and prefer 'strscpy' in this subsystem. Conversion is 1:1 because the return value is not used. Generated by a coccinelle script. Link: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/ Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2022-08-25HID: steam: Prevent NULL pointer dereference in steam_{recv,send}_reportLee Jones1-0/+10
It is possible for a malicious device to forgo submitting a Feature Report. The HID Steam driver presently makes no prevision for this and de-references the 'struct hid_report' pointer obtained from the HID devices without first checking its validity. Let's change that. Cc: Jiri Kosina <jikos@kernel.org> Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com> Cc: linux-input@vger.kernel.org Fixes: c164d6abf3841 ("HID: add driver for Valve Steam Controller") Signed-off-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2020-06-19HID: steam: fixes race in handling device list.Rodrigo Rivas Costa1-2/+4
Using uhid and KASAN this driver crashed because it was getting several connection events where it only expected one. Then the device was added several times to the static device list and it got corrupted. This patch checks if the device is already in the list before adding it. Signed-off-by: Rodrigo Rivas Costa <rodrigorivascosta@gmail.com> Tested-by: Siarhei Vishniakou <svv@google.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2020-01-09HID: steam: Fix input device disappearingRodrigo Rivas Costa1-0/+4
The `connected` value for wired devices was not properly initialized, it must be set to `true` upon creation, because wired devices do not generate connection events. When a raw client (the Steam Client) uses the device, the input device is destroyed. Then, when the raw client finishes, it must be recreated. But since the `connected` variable was false this never happended. Signed-off-by: Rodrigo Rivas Costa <rodrigorivascosta@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2019-03-18HID: steam: fix deadlock with input devices.Rodrigo Rivas Costa1-7/+19
When using this driver with the wireless dongle and some usermode program that monitors every input device (acpid, for example), while another usermode client opens and closes the low-level device repeadedly, the system eventually deadlocks. The reason is that steam_input_register_device() must not be called with the mutex held, because the input subsystem has its own synchronization that clashes with this one: it is possible that steam_input_open() is called before input_register_device() returns, and since steam_input_open() needs to lock the mutex, it deadlocks. However we must hold the mutex when calling any function that sends commands to the controller. If not, random commands end up falling fail. Reported-by: Simon Gene Gottlieb <simon@gottliebtfreitag.de> Signed-off-by: Rodrigo Rivas Costa <rodrigorivascosta@gmail.com> Tested-by: Simon Gene Gottlieb <simon@gottliebtfreitag.de> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2019-02-14HID: steam: fix boot loop with bluetooth firmwareRodrigo Rivas Costa1-23/+11
There is a new firmware for the Steam Controller with support for BLE connections. When using such a device with a wired connection, it reboots itself every 10 seconds unless an application has opened it. Doing hid_hw_open() unconditionally on probe fixes the issue, and the code becomes simpler. Signed-off-by: Rodrigo Rivas Costa <rodrigorivascosta@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2018-11-19HID: steam: remove input device when a hid client is running.Rodrigo Rivas Costa1-64/+90
Previously, when a HID client such as the Steam Client was running, this driver disabled its input device to avoid doubling the input events. While it worked mostly fine, some games got confused by the idle gamepad, and switched to two player mode, or asked the user to choose which gamepad to use. Other games just crashed, probably a bug in Unity [1]. With this commit, when a HID client starts, the input device is removed; when the HID client ends the input device is recreated. [1]: https://github.com/ValveSoftware/steam-for-linux/issues/5645 Signed-off-by: Rodrigo Rivas Costa <rodrigorivascosta@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2018-06-20HID: steam: use hid_device.driver_data instead of hid_set_drvdata()Rodrigo Rivas Costa1-5/+5
When creating the low-level hidraw device, the reference to steam_device was stored using hid_set_drvdata(). But this value is not guaranteed to be kept when set before calling probe. If this pointer is reset, it crashes when opening the emulated hidraw device. It looks like hid_set_drvdata() is for users "avobe" this hid_device, while hid_device.driver_data it for users "below" this one. In this case, we are creating a virtual hidraw device, so we must use hid_device.driver_data. Signed-off-by: Rodrigo Rivas Costa <rodrigorivascosta@gmail.com> Tested-by: Mariusz Ceier <mceier+kernel@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2018-05-15HID: steam: add missing fields in client initializationJiri Kosina1-0/+3
->product, ->version and ->type fields in the client struct were left out unitialized from the hid device fields; fix that. Reported-by: Rodrigo Rivas Costa <rodrigorivascosta@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2018-05-15HID: steam: add battery device.Rodrigo Rivas Costa1-1/+140
The wireless Steam Controller is battery operated, so add the battery device and power information. Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2018-05-15HID: add driver for Valve Steam ControllerRodrigo Rivas Costa1-0/+973
There are two ways to connect the Steam Controller: directly to the USB or with the USB wireless adapter. Both methods are similar, but the wireless adapter can connect up to 4 devices at the same time. The wired device will appear as 3 interfaces: a virtual mouse, a virtual keyboard and a custom HID device. The wireless device will appear as 5 interfaces: a virtual keyboard and 4 custom HID devices, that will remain silent until a device is actually connected. The custom HID device has a report descriptor with all vendor specific usages, so the hid-generic is not very useful. In a PC/SteamBox Valve Steam Client provices a software translation by using hidraw and a creates a uinput virtual gamepad and XTest keyboard/mouse. This driver intercepts the hidraw usage, so it can get out of the way when the Steam Client is in use. Signed-off-by: Rodrigo Rivas Costa <rodrigorivascosta@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>