Skip to contentSkip to conversation

HID: flydigi: add support for vader 5 pro

PATCH Superseded Denis Benato 2 participants 4 messages Aug 8

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 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

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

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     | 914 ++++++++++++++++++++++++++++++++++
 drivers/hid/hid-ids.h         |   3 +
 drivers/input/joystick/xpad.c |  24 +
 5 files changed, 950 insertions(+)
 create mode 100644 drivers/hid/hid-flydigi.c
Signature · 1 line
2.47.3
#1 lore raw

PATCH v2 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 enstablished pattern of spawning two evdevs that share the same uniqid so that SDL can match the two and expose them as a single controller.

Assisted-by VSCode:gpt-5.3-codex
---
 drivers/hid/Kconfig       |   8 +
 drivers/hid/Makefile      |   1 +
 drivers/hid/hid-flydigi.c | 914 ++++++++++++++++++++++++++++++++++++++
 drivers/hid/hid-ids.h     |   3 +
 4 files changed, 926 insertions(+)
 create mode 100644 drivers/hid/hid-flydigi.c
drivers/hid/Kconfig +8 -0
index aa7fa11a0197..59afcdb7ac18 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
+	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 48a863b245ee..356c19b31585 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 +914 -0

914 lines not on this page · raw message

drivers/hid/hid-ids.h +3 -0
index 19ab36489a60..9f151074814a 100644
@@ -515,6 +515,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
#2 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Probe error path fails to set `fd->removed = true`, leading to UAF and destroyed mutex usage via…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Probe error path fails to set fd->removed = true, leading to UAF and destroyed mutex usage via devres unregistration and input callbacks. --

--- Patch [1]: [PATCH v2 1/2] HID: flydigi: add support for vader 5 pro --- commit 0a66486909a61950a8b4745db38b10508fd08b5c
Author: Denis Benato <[email protected]>

HID: flydigi: add support for vader 5 pro

This commit adds support for the Flydigi Vader 5 Pro gamepad. It introduces a driver that creates two evdev nodes (gamepad and sensors) sharing the same uniqid.

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

[ ... ]

Quoted 19 lines
drivers/hid/hid-flydigi.c new file +19 -0
+static void flydigi_gamepad_close(struct input_dev *dev)
+{
+	struct flydigi_device *fd = input_get_drvdata(dev);
+	bool removed;
+
+	scoped_guard(spinlock_irqsave, &fd->lock) {
+		fd->gamepad_open = false;
+		fd->strong = 0;
+		fd->weak = 0;
+	}
+
+	cancel_delayed_work_sync(&fd->acquire_work);
+
+	scoped_guard(spinlock_irqsave, &fd->lock)
+		removed = fd->removed;
+
+	if (!removed)
+		schedule_work(&fd->rumble_work);
+}

[ ... ]

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)
+{

[ ... ]

Quoted 13 lines
drivers/hid/hid-flydigi.c new file +13 -0
+	ret = flydigi_register_gamepad(fd);
+	if (ret)
+		goto err_stop;
+
+	ret = flydigi_register_sensors(fd);
+	if (ret)
+		goto err_stop;
+
+	ret = hid_hw_open(hdev);
+	if (ret) {
+		hid_err(hdev, "hw open failed: %d\n", ret);
+		goto err_stop;
+	}

[ ... ]

drivers/hid/hid-flydigi.c line 872

Quoted 6 lines
drivers/hid/hid-flydigi.c new file +6 -0
+err_stop:
+	hid_hw_stop(hdev);
+	cancel_delayed_work_sync(&fd->acquire_work);
+	cancel_work_sync(&fd->rumble_work);
+	mutex_destroy(&fd->output_mutex);
+	return ret;

[Severity: High]
Can a probe failure after gamepad registration cause a use-after-free?

If flydigi_probe() fails after flydigi_register_gamepad() completes (for example, if hid_hw_open() fails), the err_stop path is taken. However, fd->removed is not set to true.

When probe returns an error, devres will unregister the input device. If userspace had already opened the device, the unregistration will trigger flydigi_gamepad_close(). Because fd->removed is still false, it will schedule fd->rumble_work:

	if (!removed)
		schedule_work(&fd->rumble_work);

After devres frees the fd structure, the workqueue could execute flydigi_rumble_worker(), resulting in a use-after-free and an attempt to lock the destroyed output_mutex.

Should fd->removed be set to true in the err_stop path, similar to what is done in flydigi_remove()?

Quoted 1 line

+}

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

PATCH v2 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 feb8f368f834..545119a4fb36 100644
@@ -406,6 +406,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 */
@@ -2044,11 +2056,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