From e1b8ad0380da89a23d6483b86d72cf21c414f4be Mon Sep 17 00:00:00 2001
From: Vicki Pfau <[EMAIL REDACTED]>
Date: Wed, 4 Feb 2026 22:38:32 -0800
Subject: [PATCH] Add and use libusb_set_auto_detach_kernel_driver for the
Switch 2 driver
---
src/joystick/hidapi/SDL_hidapi_switch2.c | 1 +
src/misc/SDL_libusb.c | 1 +
src/misc/SDL_libusb.h | 1 +
3 files changed, 3 insertions(+)
diff --git a/src/joystick/hidapi/SDL_hidapi_switch2.c b/src/joystick/hidapi/SDL_hidapi_switch2.c
index a403eb4b5c5a4..0d5048364d4d9 100644
--- a/src/joystick/hidapi/SDL_hidapi_switch2.c
+++ b/src/joystick/hidapi/SDL_hidapi_switch2.c
@@ -381,6 +381,7 @@ static bool HIDAPI_DriverSwitch2_InitUSB(SDL_HIDAPI_Device *device)
return SDL_SetError("Couldn't find bulk endpoints");
}
+ ctx->libusb->set_auto_detach_kernel_driver(ctx->device_handle, true);
int res = ctx->libusb->claim_interface(ctx->device_handle, ctx->interface_number);
if (res < 0) {
return SDL_SetError("Couldn't claim interface %d: %d\n", ctx->interface_number, res);
diff --git a/src/misc/SDL_libusb.c b/src/misc/SDL_libusb.c
index e78d51d8ab74a..82fd95baf51f3 100644
--- a/src/misc/SDL_libusb.c
+++ b/src/misc/SDL_libusb.c
@@ -79,6 +79,7 @@ bool SDL_InitLibUSB(SDL_LibUSBContext **ctx)
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), kernel_driver_active)
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), detach_kernel_driver)
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), attach_kernel_driver)
+ LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int), set_auto_detach_kernel_driver)
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(libusb_device_handle *, int, int), set_interface_alt_setting)
LOAD_LIBUSB_SYMBOL(struct libusb_transfer * (LIBUSB_CALL *)(int), alloc_transfer)
LOAD_LIBUSB_SYMBOL(int (LIBUSB_CALL *)(struct libusb_transfer *), submit_transfer)
diff --git a/src/misc/SDL_libusb.h b/src/misc/SDL_libusb.h
index a493c62f51e97..9cce444aedf49 100644
--- a/src/misc/SDL_libusb.h
+++ b/src/misc/SDL_libusb.h
@@ -57,6 +57,7 @@ typedef struct SDL_LibUSBContext
int (LIBUSB_CALL *kernel_driver_active)(libusb_device_handle *dev_handle, int interface_number);
int (LIBUSB_CALL *detach_kernel_driver)(libusb_device_handle *dev_handle, int interface_number);
int (LIBUSB_CALL *attach_kernel_driver)(libusb_device_handle *dev_handle, int interface_number);
+ int (LIBUSB_CALL *set_auto_detach_kernel_driver)(libusb_device_handle *dev_handle, int enable);
int (LIBUSB_CALL *set_interface_alt_setting)(libusb_device_handle *dev, int interface_number, int alternate_setting);
struct libusb_transfer * (LIBUSB_CALL *alloc_transfer)(int iso_packets);
int (LIBUSB_CALL *submit_transfer)(struct libusb_transfer *transfer);