[PATCH v3 29/31] USB: Retain the result of configuration requests

From: Leon Romanovsky

Date: Wed Nov 18 2026 - 14:36:00 EST


From: Leon Romanovsky <leonro@xxxxxxxxxx>

The generic USB device driver can bind successfully even when setting its
configuration fails. Authorization that attaches this driver therefore
cannot use the attachment result to report configuration errors or decide
whether setup can be retried.

Retain the last configuration result for callers holding the device lock.
Keep driver binding successful so userspace can recover by selecting
another configuration.

Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxx>
---
drivers/usb/core/message.c | 12 +++++++++++-
include/linux/usb.h | 2 ++
2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index b8e2d864faa46..0a022ce8739c2 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -2042,6 +2042,8 @@ static bool usb_has_claimant(struct usb_device *dev,
return false;
}

+static int usb_set_configuration_internal(struct usb_device *dev, int configuration);
+
/*
* usb_set_configuration - Makes a particular device setting be current
* @dev: the device whose configuration is being updated
@@ -2089,6 +2091,15 @@ static bool usb_has_claimant(struct usb_device *dev,
* drivers currently known to the kernel.
*/
int usb_set_configuration(struct usb_device *dev, int configuration)
+{
+ int ret = usb_set_configuration_internal(dev, configuration);
+
+ dev->config_error = ret;
+ return ret;
+}
+EXPORT_SYMBOL_GPL(usb_set_configuration);
+
+static int usb_set_configuration_internal(struct usb_device *dev, int configuration)
{
int i, ret;
struct usb_host_config *cp = NULL;
@@ -2349,7 +2360,6 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
usb_autosuspend_device(dev);
return 0;
}
-EXPORT_SYMBOL_GPL(usb_set_configuration);

static LIST_HEAD(set_config_list);
static DEFINE_SPINLOCK(set_config_lock);
diff --git a/include/linux/usb.h b/include/linux/usb.h
index a5e706f67f33a..d372712eba34c 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -599,6 +599,7 @@ struct usb3_lpm_parameters {
* @descriptor: USB device descriptor
* @bos: USB device BOS descriptor set
* @config: all of the device's configs
+ * @config_error: Result of the last configuration request.
* @actconfig: the active configuration
* @ep_in: array of IN endpoints
* @ep_out: array of OUT endpoints
@@ -686,6 +687,7 @@ struct usb_device {
struct usb_host_config *config;

struct usb_host_config *actconfig;
+ int config_error;
struct usb_host_endpoint *ep_in[16];
struct usb_host_endpoint *ep_out[16];


--
2.56.1