public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: core: new quirk to handle devices with zero configurations
@ 2026-02-26  9:47 Jie Deng
  2026-02-26 12:21 ` kernel test robot
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jie Deng @ 2026-02-26  9:47 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Jie Deng

Some USB devices incorrectly report bNumConfigurations as 0 in their
device descriptor, which causes the USB core to reject them during
enumeration.
logs:
usb 1-2: device descriptor read/64, error -71
usb 1-2: no configurations
usb 1-2: can't read configurations, error -22

However, these devices actually work correctly when
treated as having a single configuration.

Add a new quirk USB_QUIRK_FORCE_ONE_CONFIG to handle such devices.
When this quirk is set, assume the device has 1 configuration instead
of failing with -EINVAL.

This quirk is applied to the device with VID:PID 5131:2007 which
exhibits this behavior.

Signed-off-by: Jie Deng <dengjie03@kylinos.cn>
---
 Documentation/admin-guide/kernel-parameters.txt | 3 +++
 drivers/usb/core/config.c                       | 7 ++++++-
 drivers/usb/core/quirks.c                       | 5 +++++
 include/linux/usb/quirks.h                      | 3 +++
 4 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index cb850e5290c2..63e6d3ebbd7a 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -8183,6 +8183,9 @@ Kernel parameters
 				p = USB_QUIRK_SHORT_SET_ADDRESS_REQ_TIMEOUT
 					(Reduce timeout of the SET_ADDRESS
 					request from 5000 ms to 500 ms);
+				r = USB_QUIRK_FORCE_ONE_CONFIG (Device
+					claims zero configurations,
+					forcing to 1);
 			Example: quirks=0781:5580:bk,0a5c:5834:gij
 
 	usbhid.mousepoll=
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index 1cd5fa61dc76..f60fed224cbb 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -927,7 +927,12 @@ int usb_get_configuration(struct usb_device *dev)
 		dev->descriptor.bNumConfigurations = ncfg = USB_MAXCONFIG;
 	}
 
-	if (ncfg < 1) {
+	if (dev->quirks & USB_QUIRK_FORCE_ONE_CONFIG) {
+		dev_info(ddev, "Device claims zero configurations,
+				forcing to 1\n");
+		dev->descriptor.bNumConfigurations = 1;
+		ncfg = 1;
+	} esle if (ncfg < 1) {
 		dev_err(ddev, "no configurations\n");
 		return -EINVAL;
 	}
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index e347236d83e8..74b20ef4e41d 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -140,6 +140,8 @@ static int quirks_param_set(const char *value, const struct kernel_param *kp)
 			case 'p':
 				flags |= USB_QUIRK_SHORT_SET_ADDRESS_REQ_TIMEOUT;
 				break;
+			case 'r':
+				flags |= USB_QUIRK_FORCE_ONE_CONFIG;
 			/* Ignore unrecognized flag characters */
 			}
 		}
@@ -589,6 +591,9 @@ static const struct usb_device_id usb_quirk_list[] = {
 	/* VCOM device */
 	{ USB_DEVICE(0x4296, 0x7570), .driver_info = USB_QUIRK_CONFIG_INTF_STRINGS },
 
+	/* Noji-MCS SmartCard Reader */
+	{ USB_DEVICE(0x5131, 0x2007), .driver_info = USB_QUIRK_FORCE_ONE_CONFIG },
+
 	/* INTEL VALUE SSD */
 	{ USB_DEVICE(0x8086, 0xf1a5), .driver_info = USB_QUIRK_RESET_RESUME },
 
diff --git a/include/linux/usb/quirks.h b/include/linux/usb/quirks.h
index 2f7bd2fdc616..b3cc7beab4a3 100644
--- a/include/linux/usb/quirks.h
+++ b/include/linux/usb/quirks.h
@@ -78,4 +78,7 @@
 /* skip BOS descriptor request */
 #define USB_QUIRK_NO_BOS			BIT(17)
 
+/* Device claims zero configurations, forcing to 1 */
+#define USB_QUIRK_FORCE_ONE_CONFIG		BIT(18)
+
 #endif /* __LINUX_USB_QUIRKS_H */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] usb: core: new quirk to handle devices with zero configurations
  2026-02-26  9:47 [PATCH] usb: core: new quirk to handle devices with zero configurations Jie Deng
@ 2026-02-26 12:21 ` kernel test robot
  2026-02-26 14:28 ` Greg Kroah-Hartman
  2026-02-26 15:30 ` Alan Stern
  2 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2026-02-26 12:21 UTC (permalink / raw)
  To: Jie Deng, Greg Kroah-Hartman
  Cc: oe-kbuild-all, linux-usb, linux-kernel, Jie Deng

Hi Jie,

kernel test robot noticed the following build errors:

[auto build test ERROR on usb/usb-testing]
[also build test ERROR on usb/usb-next usb/usb-linus westeri-thunderbolt/next linus/master v7.0-rc1 next-20260225]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jie-Deng/usb-core-new-quirk-to-handle-devices-with-zero-configurations/20260226-180039
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
patch link:    https://lore.kernel.org/r/20260226094737.1306471-1-dengjie03%40kylinos.cn
patch subject: [PATCH] usb: core: new quirk to handle devices with zero configurations
config: parisc-randconfig-r072-20260226 (https://download.01.org/0day-ci/archive/20260226/202602262055.asAbiuP0-lkp@intel.com/config)
compiler: hppa-linux-gcc (GCC) 9.5.0
smatch version: v0.5.0-8994-gd50c5a4c
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260226/202602262055.asAbiuP0-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602262055.asAbiuP0-lkp@intel.com/

All error/warnings (new ones prefixed by >>):

   drivers/usb/core/config.c: In function 'usb_get_configuration':
>> drivers/usb/core/config.c:931:18: warning: missing terminating " character
     931 |   dev_info(ddev, "Device claims zero configurations,
         |                  ^
   drivers/usb/core/config.c:932:19: warning: missing terminating " character
     932 |     forcing to 1\n");
         |                   ^
>> drivers/usb/core/config.c:1156: error: unterminated argument list invoking macro "dev_info"
    1156 | }
         | 
>> drivers/usb/core/config.c:931:3: error: 'dev_info' undeclared (first use in this function); did you mean '_dev_info'?
     931 |   dev_info(ddev, "Device claims zero configurations,
         |   ^~~~~~~~
         |   _dev_info
   drivers/usb/core/config.c:931:3: note: each undeclared identifier is reported only once for each function it appears in
>> drivers/usb/core/config.c:931:11: error: expected ';' at end of input
     931 |   dev_info(ddev, "Device claims zero configurations,
         |           ^
         |           ;
   ......
    1156 | }
         |            
>> drivers/usb/core/config.c:931:3: error: expected declaration or statement at end of input
     931 |   dev_info(ddev, "Device claims zero configurations,
         |   ^~~~~~~~
>> drivers/usb/core/config.c:931:3: error: expected declaration or statement at end of input
>> drivers/usb/core/config.c:922:6: warning: unused variable 'result' [-Wunused-variable]
     922 |  int result;
         |      ^~~~~~
>> drivers/usb/core/config.c:921:32: warning: unused variable 'desc' [-Wunused-variable]
     921 |  struct usb_config_descriptor *desc;
         |                                ^~~~
>> drivers/usb/core/config.c:920:17: warning: unused variable 'bigbuffer' [-Wunused-variable]
     920 |  unsigned char *bigbuffer;
         |                 ^~~~~~~~~
>> drivers/usb/core/config.c:919:22: warning: unused variable 'length' [-Wunused-variable]
     919 |  unsigned int cfgno, length;
         |                      ^~~~~~
>> drivers/usb/core/config.c:919:15: warning: unused variable 'cfgno' [-Wunused-variable]
     919 |  unsigned int cfgno, length;
         |               ^~~~~
>> drivers/usb/core/config.c:1156: warning: control reaches end of non-void function [-Wreturn-type]
    1156 | }
         | 
   At top level:
>> drivers/usb/core/config.c:659:12: warning: 'usb_parse_configuration' defined but not used [-Wunused-function]
     659 | static int usb_parse_configuration(struct usb_device *dev, int cfgidx,
         |            ^~~~~~~~~~~~~~~~~~~~~~~


vim +/dev_info +1156 drivers/usb/core/config.c

81cf4a45360f70 Masakazu Mokuno  2017-11-10  1035  
3148bf041d169a Andiry Xu        2011-09-23  1036  /* Get BOS descriptor set */
3148bf041d169a Andiry Xu        2011-09-23  1037  int usb_get_bos_descriptor(struct usb_device *dev)
3148bf041d169a Andiry Xu        2011-09-23  1038  {
3148bf041d169a Andiry Xu        2011-09-23  1039  	struct device *ddev = &dev->dev;
3148bf041d169a Andiry Xu        2011-09-23  1040  	struct usb_bos_descriptor *bos;
3148bf041d169a Andiry Xu        2011-09-23  1041  	struct usb_dev_cap_header *cap;
81cf4a45360f70 Masakazu Mokuno  2017-11-10  1042  	struct usb_ssp_cap_descriptor *ssp_cap;
3dd550a2d36596 Alan Stern       2019-09-04  1043  	unsigned char *buffer, *buffer0;
81cf4a45360f70 Masakazu Mokuno  2017-11-10  1044  	int length, total_len, num, i, ssac;
81cf4a45360f70 Masakazu Mokuno  2017-11-10  1045  	__u8 cap_type;
3148bf041d169a Andiry Xu        2011-09-23  1046  	int ret;
3148bf041d169a Andiry Xu        2011-09-23  1047  
2740ac33c87b3d Johannes Brüderl 2025-12-07  1048  	if (dev->quirks & USB_QUIRK_NO_BOS) {
2740ac33c87b3d Johannes Brüderl 2025-12-07  1049  		dev_dbg(ddev, "skipping BOS descriptor\n");
2740ac33c87b3d Johannes Brüderl 2025-12-07  1050  		return -ENOMSG;
2740ac33c87b3d Johannes Brüderl 2025-12-07  1051  	}
2740ac33c87b3d Johannes Brüderl 2025-12-07  1052  
bf4afc53b77aea Linus Torvalds   2026-02-21  1053  	bos = kzalloc_obj(*bos);
3148bf041d169a Andiry Xu        2011-09-23  1054  	if (!bos)
3148bf041d169a Andiry Xu        2011-09-23  1055  		return -ENOMEM;
3148bf041d169a Andiry Xu        2011-09-23  1056  
3148bf041d169a Andiry Xu        2011-09-23  1057  	/* Get BOS descriptor */
3148bf041d169a Andiry Xu        2011-09-23  1058  	ret = usb_get_descriptor(dev, USB_DT_BOS, 0, bos, USB_DT_BOS_SIZE);
a03ff54460817c Alan Stern       2019-05-13  1059  	if (ret < USB_DT_BOS_SIZE || bos->bLength < USB_DT_BOS_SIZE) {
7a09c1269702db Alan Stern       2022-11-02  1060  		dev_notice(ddev, "unable to get BOS descriptor or descriptor too short\n");
3148bf041d169a Andiry Xu        2011-09-23  1061  		if (ret >= 0)
3148bf041d169a Andiry Xu        2011-09-23  1062  			ret = -ENOMSG;
3148bf041d169a Andiry Xu        2011-09-23  1063  		kfree(bos);
3148bf041d169a Andiry Xu        2011-09-23  1064  		return ret;
3148bf041d169a Andiry Xu        2011-09-23  1065  	}
3148bf041d169a Andiry Xu        2011-09-23  1066  
3148bf041d169a Andiry Xu        2011-09-23  1067  	length = bos->bLength;
3148bf041d169a Andiry Xu        2011-09-23  1068  	total_len = le16_to_cpu(bos->wTotalLength);
3148bf041d169a Andiry Xu        2011-09-23  1069  	num = bos->bNumDeviceCaps;
3148bf041d169a Andiry Xu        2011-09-23  1070  	kfree(bos);
3148bf041d169a Andiry Xu        2011-09-23  1071  	if (total_len < length)
3148bf041d169a Andiry Xu        2011-09-23  1072  		return -EINVAL;
3148bf041d169a Andiry Xu        2011-09-23  1073  
bf4afc53b77aea Linus Torvalds   2026-02-21  1074  	dev->bos = kzalloc_obj(*dev->bos);
3148bf041d169a Andiry Xu        2011-09-23  1075  	if (!dev->bos)
3148bf041d169a Andiry Xu        2011-09-23  1076  		return -ENOMEM;
3148bf041d169a Andiry Xu        2011-09-23  1077  
3148bf041d169a Andiry Xu        2011-09-23  1078  	/* Now let's get the whole BOS descriptor set */
3148bf041d169a Andiry Xu        2011-09-23  1079  	buffer = kzalloc(total_len, GFP_KERNEL);
3148bf041d169a Andiry Xu        2011-09-23  1080  	if (!buffer) {
3148bf041d169a Andiry Xu        2011-09-23  1081  		ret = -ENOMEM;
3148bf041d169a Andiry Xu        2011-09-23  1082  		goto err;
3148bf041d169a Andiry Xu        2011-09-23  1083  	}
3148bf041d169a Andiry Xu        2011-09-23  1084  	dev->bos->desc = (struct usb_bos_descriptor *)buffer;
3148bf041d169a Andiry Xu        2011-09-23  1085  
3148bf041d169a Andiry Xu        2011-09-23  1086  	ret = usb_get_descriptor(dev, USB_DT_BOS, 0, buffer, total_len);
3148bf041d169a Andiry Xu        2011-09-23  1087  	if (ret < total_len) {
7a09c1269702db Alan Stern       2022-11-02  1088  		dev_notice(ddev, "unable to get BOS descriptor set\n");
3148bf041d169a Andiry Xu        2011-09-23  1089  		if (ret >= 0)
3148bf041d169a Andiry Xu        2011-09-23  1090  			ret = -ENOMSG;
3148bf041d169a Andiry Xu        2011-09-23  1091  		goto err;
3148bf041d169a Andiry Xu        2011-09-23  1092  	}
3dd550a2d36596 Alan Stern       2019-09-04  1093  
3dd550a2d36596 Alan Stern       2019-09-04  1094  	buffer0 = buffer;
3148bf041d169a Andiry Xu        2011-09-23  1095  	total_len -= length;
3dd550a2d36596 Alan Stern       2019-09-04  1096  	buffer += length;
3148bf041d169a Andiry Xu        2011-09-23  1097  
3148bf041d169a Andiry Xu        2011-09-23  1098  	for (i = 0; i < num; i++) {
3148bf041d169a Andiry Xu        2011-09-23  1099  		cap = (struct usb_dev_cap_header *)buffer;
3148bf041d169a Andiry Xu        2011-09-23  1100  
1c0edc3633b560 Alan Stern       2017-10-18  1101  		if (total_len < sizeof(*cap) || total_len < cap->bLength) {
1c0edc3633b560 Alan Stern       2017-10-18  1102  			dev->bos->desc->bNumDeviceCaps = i;
3148bf041d169a Andiry Xu        2011-09-23  1103  			break;
1c0edc3633b560 Alan Stern       2017-10-18  1104  		}
81cf4a45360f70 Masakazu Mokuno  2017-11-10  1105  		cap_type = cap->bDevCapabilityType;
1c0edc3633b560 Alan Stern       2017-10-18  1106  		length = cap->bLength;
81cf4a45360f70 Masakazu Mokuno  2017-11-10  1107  		if (bos_desc_len[cap_type] && length < bos_desc_len[cap_type]) {
81cf4a45360f70 Masakazu Mokuno  2017-11-10  1108  			dev->bos->desc->bNumDeviceCaps = i;
81cf4a45360f70 Masakazu Mokuno  2017-11-10  1109  			break;
81cf4a45360f70 Masakazu Mokuno  2017-11-10  1110  		}
81cf4a45360f70 Masakazu Mokuno  2017-11-10  1111  
3148bf041d169a Andiry Xu        2011-09-23  1112  		if (cap->bDescriptorType != USB_DT_DEVICE_CAPABILITY) {
7a09c1269702db Alan Stern       2022-11-02  1113  			dev_notice(ddev, "descriptor type invalid, skip\n");
974bba5c118f4c Niklas Neronin   2023-11-15  1114  			goto skip_to_next_descriptor;
3148bf041d169a Andiry Xu        2011-09-23  1115  		}
3148bf041d169a Andiry Xu        2011-09-23  1116  
81cf4a45360f70 Masakazu Mokuno  2017-11-10  1117  		switch (cap_type) {
3148bf041d169a Andiry Xu        2011-09-23  1118  		case USB_CAP_TYPE_EXT:
3148bf041d169a Andiry Xu        2011-09-23  1119  			dev->bos->ext_cap =
3148bf041d169a Andiry Xu        2011-09-23  1120  				(struct usb_ext_cap_descriptor *)buffer;
3148bf041d169a Andiry Xu        2011-09-23  1121  			break;
3148bf041d169a Andiry Xu        2011-09-23  1122  		case USB_SS_CAP_TYPE:
3148bf041d169a Andiry Xu        2011-09-23  1123  			dev->bos->ss_cap =
3148bf041d169a Andiry Xu        2011-09-23  1124  				(struct usb_ss_cap_descriptor *)buffer;
3148bf041d169a Andiry Xu        2011-09-23  1125  			break;
3220befddc0da1 Mathias Nyman    2015-10-01  1126  		case USB_SSP_CAP_TYPE:
81cf4a45360f70 Masakazu Mokuno  2017-11-10  1127  			ssp_cap = (struct usb_ssp_cap_descriptor *)buffer;
81cf4a45360f70 Masakazu Mokuno  2017-11-10  1128  			ssac = (le32_to_cpu(ssp_cap->bmAttributes) &
07b9f12864d16c Mathias Nyman    2017-12-19  1129  				USB_SSP_SUBLINK_SPEED_ATTRIBS);
81cf4a45360f70 Masakazu Mokuno  2017-11-10  1130  			if (length >= USB_DT_USB_SSP_CAP_SIZE(ssac))
81cf4a45360f70 Masakazu Mokuno  2017-11-10  1131  				dev->bos->ssp_cap = ssp_cap;
3220befddc0da1 Mathias Nyman    2015-10-01  1132  			break;
3148bf041d169a Andiry Xu        2011-09-23  1133  		case CONTAINER_ID_TYPE:
3148bf041d169a Andiry Xu        2011-09-23  1134  			dev->bos->ss_id =
3148bf041d169a Andiry Xu        2011-09-23  1135  				(struct usb_ss_container_id_descriptor *)buffer;
3148bf041d169a Andiry Xu        2011-09-23  1136  			break;
faee822c5a7ab9 Mathias Nyman    2016-02-12  1137  		case USB_PTM_CAP_TYPE:
faee822c5a7ab9 Mathias Nyman    2016-02-12  1138  			dev->bos->ptm_cap =
faee822c5a7ab9 Mathias Nyman    2016-02-12  1139  				(struct usb_ptm_cap_descriptor *)buffer;
1d6903a617a221 Nick Desaulniers 2020-11-10  1140  			break;
3148bf041d169a Andiry Xu        2011-09-23  1141  		default:
3148bf041d169a Andiry Xu        2011-09-23  1142  			break;
3148bf041d169a Andiry Xu        2011-09-23  1143  		}
3dd550a2d36596 Alan Stern       2019-09-04  1144  
974bba5c118f4c Niklas Neronin   2023-11-15  1145  skip_to_next_descriptor:
3dd550a2d36596 Alan Stern       2019-09-04  1146  		total_len -= length;
3dd550a2d36596 Alan Stern       2019-09-04  1147  		buffer += length;
3148bf041d169a Andiry Xu        2011-09-23  1148  	}
3dd550a2d36596 Alan Stern       2019-09-04  1149  	dev->bos->desc->wTotalLength = cpu_to_le16(buffer - buffer0);
3148bf041d169a Andiry Xu        2011-09-23  1150  
3148bf041d169a Andiry Xu        2011-09-23  1151  	return 0;
3148bf041d169a Andiry Xu        2011-09-23  1152  
3148bf041d169a Andiry Xu        2011-09-23  1153  err:
3148bf041d169a Andiry Xu        2011-09-23  1154  	usb_release_bos_descriptor(dev);
3148bf041d169a Andiry Xu        2011-09-23  1155  	return ret;
3148bf041d169a Andiry Xu        2011-09-23 @1156  }

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] usb: core: new quirk to handle devices with zero configurations
  2026-02-26  9:47 [PATCH] usb: core: new quirk to handle devices with zero configurations Jie Deng
  2026-02-26 12:21 ` kernel test robot
@ 2026-02-26 14:28 ` Greg Kroah-Hartman
  2026-02-27  3:00   ` Jie Deng
  2026-02-26 15:30 ` Alan Stern
  2 siblings, 1 reply; 6+ messages in thread
From: Greg Kroah-Hartman @ 2026-02-26 14:28 UTC (permalink / raw)
  To: Jie Deng; +Cc: linux-usb, linux-kernel

On Thu, Feb 26, 2026 at 05:47:37PM +0800, Jie Deng wrote:
> Some USB devices incorrectly report bNumConfigurations as 0 in their
> device descriptor, which causes the USB core to reject them during
> enumeration.
> logs:
> usb 1-2: device descriptor read/64, error -71
> usb 1-2: no configurations
> usb 1-2: can't read configurations, error -22
> 
> However, these devices actually work correctly when
> treated as having a single configuration.

Really?  Don't devices like this violate the USB spec?

> Add a new quirk USB_QUIRK_FORCE_ONE_CONFIG to handle such devices.
> When this quirk is set, assume the device has 1 configuration instead
> of failing with -EINVAL.
> 
> This quirk is applied to the device with VID:PID 5131:2007 which
> exhibits this behavior.
> 
> Signed-off-by: Jie Deng <dengjie03@kylinos.cn>
> ---
>  Documentation/admin-guide/kernel-parameters.txt | 3 +++
>  drivers/usb/core/config.c                       | 7 ++++++-
>  drivers/usb/core/quirks.c                       | 5 +++++
>  include/linux/usb/quirks.h                      | 3 +++
>  4 files changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index cb850e5290c2..63e6d3ebbd7a 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -8183,6 +8183,9 @@ Kernel parameters
>  				p = USB_QUIRK_SHORT_SET_ADDRESS_REQ_TIMEOUT
>  					(Reduce timeout of the SET_ADDRESS
>  					request from 5000 ms to 500 ms);
> +				r = USB_QUIRK_FORCE_ONE_CONFIG (Device
> +					claims zero configurations,
> +					forcing to 1);

Why "r"?

>  			Example: quirks=0781:5580:bk,0a5c:5834:gij
>  
>  	usbhid.mousepoll=
> diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
> index 1cd5fa61dc76..f60fed224cbb 100644
> --- a/drivers/usb/core/config.c
> +++ b/drivers/usb/core/config.c
> @@ -927,7 +927,12 @@ int usb_get_configuration(struct usb_device *dev)
>  		dev->descriptor.bNumConfigurations = ncfg = USB_MAXCONFIG;
>  	}
>  
> -	if (ncfg < 1) {
> +	if (dev->quirks & USB_QUIRK_FORCE_ONE_CONFIG) {
> +		dev_info(ddev, "Device claims zero configurations,
> +				forcing to 1\n");
> +		dev->descriptor.bNumConfigurations = 1;
> +		ncfg = 1;

But is the configuration descriptor actually present?  This feels odd to
me.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] usb: core: new quirk to handle devices with zero configurations
  2026-02-26  9:47 [PATCH] usb: core: new quirk to handle devices with zero configurations Jie Deng
  2026-02-26 12:21 ` kernel test robot
  2026-02-26 14:28 ` Greg Kroah-Hartman
@ 2026-02-26 15:30 ` Alan Stern
  2026-02-27  1:47   ` Jie Deng
  2 siblings, 1 reply; 6+ messages in thread
From: Alan Stern @ 2026-02-26 15:30 UTC (permalink / raw)
  To: Jie Deng; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel

On Thu, Feb 26, 2026 at 05:47:37PM +0800, Jie Deng wrote:
> Some USB devices incorrectly report bNumConfigurations as 0 in their
> device descriptor, which causes the USB core to reject them during
> enumeration.
> logs:
> usb 1-2: device descriptor read/64, error -71
> usb 1-2: no configurations
> usb 1-2: can't read configurations, error -22
> 
> However, these devices actually work correctly when
> treated as having a single configuration.
> 
> Add a new quirk USB_QUIRK_FORCE_ONE_CONFIG to handle such devices.
> When this quirk is set, assume the device has 1 configuration instead
> of failing with -EINVAL.
> 
> This quirk is applied to the device with VID:PID 5131:2007 which
> exhibits this behavior.
> 
> Signed-off-by: Jie Deng <dengjie03@kylinos.cn>
> ---
>  Documentation/admin-guide/kernel-parameters.txt | 3 +++
>  drivers/usb/core/config.c                       | 7 ++++++-
>  drivers/usb/core/quirks.c                       | 5 +++++
>  include/linux/usb/quirks.h                      | 3 +++
>  4 files changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index cb850e5290c2..63e6d3ebbd7a 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -8183,6 +8183,9 @@ Kernel parameters
>  				p = USB_QUIRK_SHORT_SET_ADDRESS_REQ_TIMEOUT
>  					(Reduce timeout of the SET_ADDRESS
>  					request from 5000 ms to 500 ms);
> +				r = USB_QUIRK_FORCE_ONE_CONFIG (Device
> +					claims zero configurations,
> +					forcing to 1);
>  			Example: quirks=0781:5580:bk,0a5c:5834:gij
>  
>  	usbhid.mousepoll=
> diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
> index 1cd5fa61dc76..f60fed224cbb 100644
> --- a/drivers/usb/core/config.c
> +++ b/drivers/usb/core/config.c
> @@ -927,7 +927,12 @@ int usb_get_configuration(struct usb_device *dev)
>  		dev->descriptor.bNumConfigurations = ncfg = USB_MAXCONFIG;
>  	}
>  
> -	if (ncfg < 1) {
> +	if (dev->quirks & USB_QUIRK_FORCE_ONE_CONFIG) {
> +		dev_info(ddev, "Device claims zero configurations,
> +				forcing to 1\n");
> +		dev->descriptor.bNumConfigurations = 1;
> +		ncfg = 1;

What if a device claims to have 2 configurations but the flag is set?  
This will cause the kernel to ignore the second configuration.

> +	} esle if (ncfg < 1) {
-----------^^

Clearly you never compiled this code.

Alan Stern

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] usb: core: new quirk to handle devices with zero configurations
  2026-02-26 15:30 ` Alan Stern
@ 2026-02-27  1:47   ` Jie Deng
  0 siblings, 0 replies; 6+ messages in thread
From: Jie Deng @ 2026-02-27  1:47 UTC (permalink / raw)
  To: Alan Stern; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel


在 2026/2/26 23:30, Alan Stern 写道:
> On Thu, Feb 26, 2026 at 05:47:37PM +0800, Jie Deng wrote:
>> Some USB devices incorrectly report bNumConfigurations as 0 in their
>> device descriptor, which causes the USB core to reject them during
>> enumeration.
>> logs:
>> usb 1-2: device descriptor read/64, error -71
>> usb 1-2: no configurations
>> usb 1-2: can't read configurations, error -22
>>
>> However, these devices actually work correctly when
>> treated as having a single configuration.
>>
>> Add a new quirk USB_QUIRK_FORCE_ONE_CONFIG to handle such devices.
>> When this quirk is set, assume the device has 1 configuration instead
>> of failing with -EINVAL.
>>
>> This quirk is applied to the device with VID:PID 5131:2007 which
>> exhibits this behavior.
>>
>> Signed-off-by: Jie Deng <dengjie03@kylinos.cn>
>> ---
>>   Documentation/admin-guide/kernel-parameters.txt | 3 +++
>>   drivers/usb/core/config.c                       | 7 ++++++-
>>   drivers/usb/core/quirks.c                       | 5 +++++
>>   include/linux/usb/quirks.h                      | 3 +++
>>   4 files changed, 17 insertions(+), 1 deletion(-)
>>
>> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
>> index cb850e5290c2..63e6d3ebbd7a 100644
>> --- a/Documentation/admin-guide/kernel-parameters.txt
>> +++ b/Documentation/admin-guide/kernel-parameters.txt
>> @@ -8183,6 +8183,9 @@ Kernel parameters
>>   				p = USB_QUIRK_SHORT_SET_ADDRESS_REQ_TIMEOUT
>>   					(Reduce timeout of the SET_ADDRESS
>>   					request from 5000 ms to 500 ms);
>> +				r = USB_QUIRK_FORCE_ONE_CONFIG (Device
>> +					claims zero configurations,
>> +					forcing to 1);
>>   			Example: quirks=0781:5580:bk,0a5c:5834:gij
>>   
>>   	usbhid.mousepoll=
>> diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
>> index 1cd5fa61dc76..f60fed224cbb 100644
>> --- a/drivers/usb/core/config.c
>> +++ b/drivers/usb/core/config.c
>> @@ -927,7 +927,12 @@ int usb_get_configuration(struct usb_device *dev)
>>   		dev->descriptor.bNumConfigurations = ncfg = USB_MAXCONFIG;
>>   	}
>>   
>> -	if (ncfg < 1) {
>> +	if (dev->quirks & USB_QUIRK_FORCE_ONE_CONFIG) {
>> +		dev_info(ddev, "Device claims zero configurations,
>> +				forcing to 1\n");
>> +		dev->descriptor.bNumConfigurations = 1;
>> +		ncfg = 1;
> What if a device claims to have 2 configurations but the flag is set?
> This will cause the kernel to ignore the second configuration.

Thank you for your reply. I will modify the judgment logic and

generate a new version of the patch.

Jie Deng

>
>> +	} esle if (ncfg < 1) {
> -----------^^
>
> Clearly you never compiled this code.
>
> Alan Stern

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] usb: core: new quirk to handle devices with zero configurations
  2026-02-26 14:28 ` Greg Kroah-Hartman
@ 2026-02-27  3:00   ` Jie Deng
  0 siblings, 0 replies; 6+ messages in thread
From: Jie Deng @ 2026-02-27  3:00 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel


在 2026/2/26 22:28, Greg Kroah-Hartman 写道:
> On Thu, Feb 26, 2026 at 05:47:37PM +0800, Jie Deng wrote:
>> Some USB devices incorrectly report bNumConfigurations as 0 in their
>> device descriptor, which causes the USB core to reject them during
>> enumeration.
>> logs:
>> usb 1-2: device descriptor read/64, error -71
>> usb 1-2: no configurations
>> usb 1-2: can't read configurations, error -22
>>
>> However, these devices actually work correctly when
>> treated as having a single configuration.
> Really?  Don't devices like this violate the USB spec?
These devices do not comply with the USB spec in terms
of uploading the device descriptors.
>> diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
>> index 1cd5fa61dc76..f60fed224cbb 100644
>> --- a/drivers/usb/core/config.c
>> +++ b/drivers/usb/core/config.c
>> @@ -927,7 +927,12 @@ int usb_get_configuration(struct usb_device *dev)
>>   		dev->descriptor.bNumConfigurations = ncfg = USB_MAXCONFIG;
>>   	}
>>   
>> -	if (ncfg < 1) {
>> +	if (dev->quirks & USB_QUIRK_FORCE_ONE_CONFIG) {
>> +		dev_info(ddev, "Device claims zero configurations,
>> +				forcing to 1\n");
>> +		dev->descriptor.bNumConfigurations = 1;
>> +		ncfg = 1;
> But is the configuration descriptor actually present?  This feels odd to
> me.
>
> thanks,
>
> greg k-h

The configuration descriptor exists. I connected this device to the 
Windows system,
and the device worked normally. By capturing the data packets during the 
enumeration
process of this device on both the Windows and Linux systems, it was 
found that when
the bNumConfigurations value was 0 on the Windows system, it would 
default to using
a single configuration to continue the enumeration. However, on the 
Linux system,
the enumeration would be terminated.

Jie Deng



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-02-27  3:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-26  9:47 [PATCH] usb: core: new quirk to handle devices with zero configurations Jie Deng
2026-02-26 12:21 ` kernel test robot
2026-02-26 14:28 ` Greg Kroah-Hartman
2026-02-27  3:00   ` Jie Deng
2026-02-26 15:30 ` Alan Stern
2026-02-27  1:47   ` Jie Deng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox