Skip to contentSkip to conversation

HID: flydigi: add support for vader 5 pro

PATCH New Denis Benato 2 participants 4 messages Sep 15

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v5 cover HID: flydigi: add support for vader 5 pro

Hi all,

A few days ago I was contacted by a friend of mine who was having his share of issues with his Flydigi Vader 5 Pro controller: specifically the rumble didn't work correctly, alongside other issues that were partially solved by using the linked project.

However at the current time his main interest is in Steam support and the driver was working in everything but Steam, which insists on using the controller in hid mode rather than evdev mode by default, and when in evdev mode it is disregarding additional buttons and the gyroscope.

So we ended up with a perfectly working driver for the controller, that at the cost of gyroscope support and back buttons has rumble working correctly in Steam.

Since the driver works in basically everything that is not Steam, including the browser, I decided to submit it anyway as someone else will surely be interested in using some other way that is not the aforementioned program.

To make optimal use of this device the xpad driver should not bind to the controller, and this is the case for more than just this controller as Derek told me, so I added some basic infrastructure to use the best available driver for the device.

I also want to thank the original authors that did the work of implementing the controller the first time (in SDL).

Best regards,
Denis Benato

Link v1: https://lore.kernel.org/all/[email protected]/
Link v2: https://lore.kernel.org/all/[email protected]/
Link v3: https://lore.kernel.org/all/[email protected]/
Link v4: https://lore.kernel.org/all/[email protected]/

v2:
- HID: flydigi: add support for vader 5 pro
- Solve flagged vulnerabilities
v3:
- HID: flydigi: add support for vader 5 pro
- Solve the flagged vulnerability

v4:
- HID: flydigi: add support for vader 5 pro
- Fix rumble possibly getting overwhelmed
- Implement battery reporting
- Improve imu reporting

v5:
- HID: flydigi: add support for vader 5 pro
- Fix reported security issues

Denis Benato (2):
HID: flydigi: add support for vader 5 pro
Input: xpad - introduce a static table to ignore devices

 drivers/hid/Kconfig           |    8 +
 drivers/hid/Makefile          |    1 +
 drivers/hid/hid-flydigi.c     | 1159 +++++++++++++++++++++++++++++++++
 drivers/hid/hid-ids.h         |    3 +
 drivers/input/joystick/xpad.c |   24 +
 5 files changed, 1195 insertions(+)
 create mode 100644 drivers/hid/hid-flydigi.c
Signature · 1 line
2.47.3
#1 lore raw

PATCH v5 1/2 HID: flydigi: add support for vader 5 pro

The Flydigi Vader Pro 5 is a gamepad with additional buttons and a gyroscope that is connected wireless to a PC via its own dongle so it's always a USB device: add support for it by following the established pattern of spawning two evdevs that share the same uniqid so that SDL can match the two and expose them as a single controller.

---
 drivers/hid/Kconfig       |    8 +
 drivers/hid/Makefile      |    1 +
 drivers/hid/hid-flydigi.c | 1159 +++++++++++++++++++++++++++++++++++++
 drivers/hid/hid-ids.h     |    3 +
 4 files changed, 1171 insertions(+)
 create mode 100644 drivers/hid/hid-flydigi.c
drivers/hid/Kconfig +8 -0
index 0e3a0ccd6901..d189c8fa297f 100644
@@ -1196,6 +1196,14 @@ config STEAM_FF
 	Say Y here if you want to enable force feedback support for the Steam
 	Deck.
 
+config HID_FLYDIGI
+	tristate "Flydigi game controller support"
+	depends on USB_HID
+	select INPUT_FF_MEMLESS
+	help
+	Support for Flydigi game controllers that use the vendor-specific
+	HID protocol, including Vader 5 Pro.
+
 config HID_STEELSERIES
 	tristate "Steelseries devices support"
 	depends on USB_HID
drivers/hid/Makefile +1 -0
index 79384d905e00..9d12ea55f7d3 100644
@@ -56,6 +56,7 @@ obj-$(CONFIG_HID_FT260)		+= hid-ft260.o
 obj-$(CONFIG_HID_GEMBIRD)	+= hid-gembird.o
 obj-$(CONFIG_HID_GFRM)		+= hid-gfrm.o
 obj-$(CONFIG_HID_GLORIOUS)  += hid-glorious.o
+obj-$(CONFIG_HID_FLYDIGI)	+= hid-flydigi.o
 obj-$(CONFIG_HID_VIVALDI_COMMON) += hid-vivaldi-common.o
 obj-$(CONFIG_HID_GOODIX_SPI)	+= hid-goodix-spi.o
 obj-$(CONFIG_HID_GOOGLE_HAMMER)	+= hid-google-hammer.o
drivers/hid/hid-flydigi.c new file +1159 -0

1,159 lines not on this page · raw message

drivers/hid/hid-ids.h +3 -0
index c53a78cd58bd..33e8d82b8694 100644
@@ -523,6 +523,9 @@
 #define USB_VENDOR_ID_FLATFROG		0x25b5
 #define USB_DEVICE_ID_MULTITOUCH_3200	0x0002
 
+#define USB_VENDOR_ID_FLYDIGI		0x37d7
+#define USB_DEVICE_ID_FLYDIGI_VADER5	0x2401
+
 #define USB_VENDOR_ID_FUTABA            0x0547
 #define USB_DEVICE_ID_LED_DISPLAY       0x7000
 
Signature · 1 line
2.47.3
#3 lore raw

PATCH v5 2/2 Input: xpad - introduce a static table to ignore devices

In reply to Denis Benato

Certain devices can work both as HID and as an xpad device: binding both would duplicate inputs causing userspace to receive double inputs; at the same time if a HID device is available it is to be preferred as it can support additional features such as integrated IMU and additional buttons and more, depending on the specific driver, therefore allow only the best driver available to bind the device.

---
 drivers/input/joystick/xpad.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/input/joystick/xpad.c +24 -0
index 2da0b7f1722a..bd24beacc788 100644
@@ -407,6 +407,18 @@ static const struct xpad_device {
 	{ 0x0000, 0x0000, "Generic X-Box pad", 0, XTYPE_UNKNOWN }
 };
 
+#define XPAD_SUBSTITUTE(_vid, _pid, _enabled) \
+	{ .vid = (_vid), .pid = (_pid), .enabled = (_enabled) }
+
+static const struct xpad_excluded_device {
+	u16 vid;
+	u16 pid;
+	bool enabled;
+} xpad_excluded_devices[] = {
+	XPAD_SUBSTITUTE(0x37d7, 0x2401, IS_ENABLED(CONFIG_HID_FLYDIGI)),
+	{ }
+};
+
 /* buttons shared with xbox and xbox360 */
 static const signed short xpad_common_btn[] = {
 	BTN_A, BTN_B, BTN_X, BTN_Y,			/* "analog" buttons */
@@ -2046,11 +2058,23 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
 	struct usb_device *udev = interface_to_usbdev(intf);
 	struct usb_xpad *xpad;
 	struct usb_endpoint_descriptor *ep_irq_in, *ep_irq_out;
+	const struct xpad_excluded_device *excluded;
 	int i, error;
 
 	if (intf->cur_altsetting->desc.bNumEndpoints != 2)
 		return -ENODEV;
 
+	for (excluded = xpad_excluded_devices;
+	     excluded->vid || excluded->pid;
+	     excluded++) {
+		if (!excluded->enabled)
+			continue;
+
+		if (le16_to_cpu(udev->descriptor.idVendor) == excluded->vid &&
+		    le16_to_cpu(udev->descriptor.idProduct) == excluded->pid)
+			return -ENODEV;
+	}
+
 	for (i = 0; xpad_device[i].idVendor; i++) {
 		if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) &&
 		    (le16_to_cpu(udev->descriptor.idProduct) == xpad_device[i].idProduct))
Signature · 1 line
2.47.3
#2 lore raw
In reply to Denis Benato
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] hid: flydigi: I/O on stopped hardware during probe error path - [Medium] hid: flydigi…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] hid: flydigi: I/O on stopped hardware during probe error path
- [Medium] hid: flydigi: devm_power_supply_register error code is masked
- [Low] hid: flydigi: missing Kconfig dependency on POWER_SUPPLY
--

commit 31540c0ea898a7ef0b58eb15e340ebc735efebe9
Author: Denis Benato <[email protected]>

HID: flydigi: add support for vader 5 pro

The Flydigi Vader Pro 5 is a gamepad with additional buttons and a gyroscope that connects to a PC via its own USB dongle. This commit adds support for it by spawning two evdev nodes that share the same unique ID, allowing SDL to expose them as a single controller.

drivers/hid/Kconfig config STEAM_FF · line 1211

Quoted 12 lines
drivers/hid/Kconfig +4 -0
index a81bf51cbcf10..3f080d59a897b 100644
@@ -1205,6 +1205,14 @@ config STEAM_FF
 	Say Y here if you want to enable force feedback support for the Steam
 	Deck.
 
+config HID_FLYDIGI
+	tristate "Flydigi game controller support"
+	depends on USB_HID
+	select INPUT_FF_MEMLESS

[Severity: Low]
Since the driver unconditionally uses power supply APIs like devm_power_supply_register(), does this Kconfig entry need a 'depends on POWER_SUPPLY' dependency?

If a user builds with CONFIG_HID_FLYDIGI=y and CONFIG_POWER_SUPPLY=n, it appears the build will fail with unresolved symbols because the power supply APIs do not provide static dummy implementations for that configuration.

Quoted 5 lines
drivers/hid/hid-flydigi.c new file +0 -0
new file mode 100644
index 0000000000000..b6d57080fed8f

[ ... ]

Quoted 2 lines
drivers/hid/hid-flydigi.c new file +2 -0
+static int flydigi_register_battery(struct flydigi_device *fd)
+{

[ ... ]

drivers/hid/hid-flydigi.c line 938

Quoted 10 lines
drivers/hid/hid-flydigi.c new file +10 -0
+	fd->battery = devm_power_supply_register(&hdev->dev, &fd->battery_desc,
+						 &psy_cfg);
+	if (IS_ERR(fd->battery)) {
+		/*
+		 * flydigi_report_battery() only checks for NULL, so packets
+		 * received while the probe failure unwinds must not find an
+		 * error pointer here.
+		 */
+		fd->battery = NULL;
+		return PTR_ERR(fd->battery);

[Severity: Medium]
By setting fd->battery to NULL before returning PTR_ERR(fd->battery), doesn't this cause the function to always return 0 (success) on failure?

It seems this will mask the actual error code (like -ENOMEM) and leave the device partially initialized when devm_power_supply_register() fails. Consider storing the error code in a temporary variable before nullifying the pointer.

[ ... ]

Quoted 2 lines
drivers/hid/hid-flydigi.c new file +2 -0
+static int flydigi_probe(struct hid_device *hdev, const struct hid_device_id *id)
+{

[ ... ]

drivers/hid/hid-flydigi.c line 1119

Quoted 4 lines
drivers/hid/hid-flydigi.c new file +4 -0
+err_stop:
+	hid_hw_stop(hdev);
+	return ret;
+}

[Severity: High]
If probe fails after hid_hw_start() succeeds (for example, in flydigi_register_sensors or hid_hw_open), could this error path lead to I/O on stopped hardware?

Since fd->removed is not set to true here, when devres subsequently unregisters the gamepad, it will trigger flydigi_gamepad_close(). Looking at flydigi_gamepad_close():

	/* Stop the motors right away on close. */
	if (!removed)
		mod_delayed_work(fd->wq, &fd->rumble_work, 0);

This will enqueue the rumble worker because removed is false. The rumble worker then executes:

static void flydigi_rumble_worker(struct work_struct *work)

{
	...
	if (removed)
		return;

	flydigi_send_rumble(fd, strong >> 8, weak >> 8);
}

This appears to call into the HID transport (hid_hw_output_report) after hid_hw_stop() has already shut down the hardware, which could lead to URB submission errors or use-after-free in the lower-level transport driver.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1