Skip to contentSkip to conversation

uapi: cdc.h: cleanly provide for more interfaces and countries

PATCH Superseded Oliver Neukum 3 participants 4 messages Oct 30, 2025 – Nov 1, 2025

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Oliver Neukum

author maintainer
#0 lore raw

PATCH v2 1/1 uapi: cdc.h: cleanly provide for more interfaces and countries

The spec requires at least one interface respectively country. It allows multiple ones. This needs to be clearly said in the UAPI.

V2: following Gustavo's suggestion to use an union

---
 drivers/usb/class/cdc-acm.c  |  2 +-
 include/uapi/linux/usb/cdc.h | 12 ++++++++----
 2 files changed, 9 insertions(+), 5 deletions(-)
drivers/usb/class/cdc-acm.c +1 -1
index 73f9476774ae..c272b00b947c 100644
@@ -1475,7 +1475,7 @@ static int acm_probe(struct usb_interface *intf,
 		if (!acm->country_codes)
 			goto skip_countries;
 		acm->country_code_size = cfd->bLength - 4;
-		memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0,
+		memcpy(acm->country_codes, (u8 *)&cfd->wCountryCode0,
 							cfd->bLength - 4);
 		acm->country_rel_date = cfd->iCountryCodeRelDate;
 
include/uapi/linux/usb/cdc.h +8 -4
index 1924cf665448..0208b2f76bf1 100644
@@ -104,8 +104,10 @@ struct usb_cdc_union_desc {
 	__u8	bDescriptorSubType;
 
 	__u8	bMasterInterface0;
-	__u8	bSlaveInterface0;
-	/* ... and there could be other slave interfaces */
+	union {
+		__u8	bSlaveInterface0;
+		DECLARE_FLEX_ARRAY(__u8, bSlaveInterfaces);
+	};
 } __attribute__ ((packed));
 
 /* "Country Selection Functional Descriptor" from CDC spec 5.2.3.9 */
@@ -115,8 +117,10 @@ struct usb_cdc_country_functional_desc {
 	__u8	bDescriptorSubType;
 
 	__u8	iCountryCodeRelDate;
-	__le16	wCountyCode0;
-	/* ... and there can be a lot of country codes */
+	union {
+		__le16	wCountryCode0;
+		DECLARE_FLEX_ARRAY(__le16, wCountryCodes);
+	};
 } __attribute__ ((packed));
 
 /* "Network Channel Terminal Functional Descriptor" from CDC spec 5.2.3.11 */
Signature · 1 line
2.51.1
#1 lore raw
Quoted 16 lines · Oliver Neukum

The spec requires at least one interface respectively country. It allows multiple ones. This needs to be clearly said in the UAPI.

V2: following Gustavo's suggestion to use an union

---
  drivers/usb/class/cdc-acm.c  |  2 +-
  include/uapi/linux/usb/cdc.h | 12 ++++++++----
  2 files changed, 9 insertions(+), 5 deletions(-)
drivers/usb/class/cdc-acm.c +0 -0
index 73f9476774ae..c272b00b947c 100644

drivers/usb/class/cdc-acm.c static int acm_probe(struct usb_interface *intf, · line 1479

Quoted 6 lines
drivers/usb/class/cdc-acm.c +1 -1
@@ -1475,7 +1475,7 @@ static int acm_probe(struct usb_interface *intf,
  		if (!acm->country_codes)
  			goto skip_countries;
  		acm->country_code_size = cfd->bLength - 4;
-		memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0,
+		memcpy(acm->country_codes, (u8 *)&cfd->wCountryCode0,
  							cfd->bLength - 4);

You should read from the flexible-array member, instead. Something like:

memcpy(acm->country_codes, (u8 *)&cfd->wCountryCodes, acm->country_code_size);

Otherwise, you may be reading beyond the boundaries of cfd->wCountryCode0.

-Gustavo

Quoted 32 lines
drivers/usb/class/cdc-acm.c +0 -0
  		acm->country_rel_date = cfd->iCountryCodeRelDate;
 
include/uapi/linux/usb/cdc.h +8 -4
index 1924cf665448..0208b2f76bf1 100644
@@ -104,8 +104,10 @@ struct usb_cdc_union_desc {
  	__u8	bDescriptorSubType;
 
  	__u8	bMasterInterface0;
-	__u8	bSlaveInterface0;
-	/* ... and there could be other slave interfaces */
+	union {
+		__u8	bSlaveInterface0;
+		DECLARE_FLEX_ARRAY(__u8, bSlaveInterfaces);
+	};
  } __attribute__ ((packed));
 
  /* "Country Selection Functional Descriptor" from CDC spec 5.2.3.9 */
@@ -115,8 +117,10 @@ struct usb_cdc_country_functional_desc {
  	__u8	bDescriptorSubType;
 
  	__u8	iCountryCodeRelDate;
-	__le16	wCountyCode0;
-	/* ... and there can be a lot of country codes */
+	union {
+		__le16	wCountryCode0;
+		DECLARE_FLEX_ARRAY(__le16, wCountryCodes);
+	};
  } __attribute__ ((packed));
 
  /* "Network Channel Terminal Functional Descriptor" from CDC spec 5.2.3.11 */
#2 lore raw
In reply to Oliver Neukum
kernel test robot noticed the following build errors:

Hi Oliver,

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 staging/staging-testing staging/staging-next staging/staging-linus westeri-thunderbolt/next linus/master v6.18-rc3 next-20251030] [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/Oliver-Neukum/uapi-cdc-h-cleanly-provide-for-more-interfaces-and-countries/20251030-212514
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
patch link:    https://lore.kernel.org/r/20251030132149.2575138-1-oneukum%40suse.com
patch subject: [PATCHv2 1/1] uapi: cdc.h: cleanly provide for more interfaces and countries
config: x86_64-rhel-9.4-ltp (https://download.01.org/0day-ci/archive/20251031/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251031/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from <command-line>:

>> ./usr/include/linux/usb/cdc.h:109:17: error: expected specifier-qualifier-list before 'DECLARE_FLEX_ARRAY'
     109 |                 DECLARE_FLEX_ARRAY(__u8, bSlaveInterfaces);
         |                 ^~~~~~~~~~~~~~~~~~
   ./usr/include/linux/usb/cdc.h:122:17: error: expected specifier-qualifier-list before 'DECLARE_FLEX_ARRAY'
     122 |                 DECLARE_FLEX_ARRAY(__le16, wCountryCodes);
         |                 ^~~~~~~~~~~~~~~~~~
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw
In reply to Oliver Neukum
kernel test robot noticed the following build errors:

Hi Oliver,

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 staging/staging-testing staging/staging-next staging/staging-linus westeri-thunderbolt/next linus/master v6.18-rc3 next-20251031] [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/Oliver-Neukum/uapi-cdc-h-cleanly-provide-for-more-interfaces-and-countries/20251030-212514
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
patch link:    https://lore.kernel.org/r/20251030132149.2575138-1-oneukum%40suse.com
patch subject: [PATCHv2 1/1] uapi: cdc.h: cleanly provide for more interfaces and countries
config: s390-allmodconfig (https://download.01.org/0day-ci/archive/20251101/[email protected]/config)
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251101/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from <built-in>:1:

>> ./usr/include/linux/usb/cdc.h:109:3: error: type name requires a specifier or qualifier
     109 |                 DECLARE_FLEX_ARRAY(__u8, bSlaveInterfaces);
         |                 ^
>> ./usr/include/linux/usb/cdc.h:109:28: error: type specifier missing, defaults to 'int' [-Werror,-Wimplicit-int]
     109 |                 DECLARE_FLEX_ARRAY(__u8, bSlaveInterfaces);
         |                                          ^
         |                                          int
   ./usr/include/linux/usb/cdc.h:122:3: error: type name requires a specifier or qualifier
     122 |                 DECLARE_FLEX_ARRAY(__le16, wCountryCodes);
         |                 ^
   ./usr/include/linux/usb/cdc.h:122:30: error: type specifier missing, defaults to 'int' [-Werror,-Wimplicit-int]
     122 |                 DECLARE_FLEX_ARRAY(__le16, wCountryCodes);
         |                                            ^
         |                                            int

4 errors generated.

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