linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2 1/1] uapi: cdc.h: cleanly provide for more interfaces and countries
@ 2025-10-30 13:20 Oliver Neukum
  2025-10-30 15:18 ` Gustavo A. R. Silva
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Oliver Neukum @ 2025-10-30 13:20 UTC (permalink / raw)
  To: gregkh, gustavo, linux-usb; +Cc: 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

Signed-off-by: Oliver Neukum <oneukum@suse.com>
---
 drivers/usb/class/cdc-acm.c  |  2 +-
 include/uapi/linux/usb/cdc.h | 12 ++++++++----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 73f9476774ae..c272b00b947c 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -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;
 
diff --git a/include/uapi/linux/usb/cdc.h b/include/uapi/linux/usb/cdc.h
index 1924cf665448..0208b2f76bf1 100644
--- a/include/uapi/linux/usb/cdc.h
+++ b/include/uapi/linux/usb/cdc.h
@@ -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.51.1


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

* Re: [PATCHv2 1/1] uapi: cdc.h: cleanly provide for more interfaces and countries
  2025-10-30 13:20 [PATCHv2 1/1] uapi: cdc.h: cleanly provide for more interfaces and countries Oliver Neukum
@ 2025-10-30 15:18 ` Gustavo A. R. Silva
  2025-10-31  9:58 ` kernel test robot
  2025-11-01  2:08 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2025-10-30 15:18 UTC (permalink / raw)
  To: Oliver Neukum, gregkh, linux-usb



On 10/30/25 13:20, Oliver Neukum wrote:
> 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
> 
> Signed-off-by: Oliver Neukum <oneukum@suse.com>
> ---
>   drivers/usb/class/cdc-acm.c  |  2 +-
>   include/uapi/linux/usb/cdc.h | 12 ++++++++----
>   2 files changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
> index 73f9476774ae..c272b00b947c 100644
> --- a/drivers/usb/class/cdc-acm.c
> +++ b/drivers/usb/class/cdc-acm.c
> @@ -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

>   		acm->country_rel_date = cfd->iCountryCodeRelDate;
>   
> diff --git a/include/uapi/linux/usb/cdc.h b/include/uapi/linux/usb/cdc.h
> index 1924cf665448..0208b2f76bf1 100644
> --- a/include/uapi/linux/usb/cdc.h
> +++ b/include/uapi/linux/usb/cdc.h
> @@ -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 */


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

* Re: [PATCHv2 1/1] uapi: cdc.h: cleanly provide for more interfaces and countries
  2025-10-30 13:20 [PATCHv2 1/1] uapi: cdc.h: cleanly provide for more interfaces and countries Oliver Neukum
  2025-10-30 15:18 ` Gustavo A. R. Silva
@ 2025-10-31  9:58 ` kernel test robot
  2025-11-01  2:08 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2025-10-31  9:58 UTC (permalink / raw)
  To: Oliver Neukum, gregkh, gustavo, linux-usb; +Cc: oe-kbuild-all, Oliver Neukum

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/202510311740.AvZo1SI1-lkp@intel.com/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/202510311740.AvZo1SI1-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/202510311740.AvZo1SI1-lkp@intel.com/

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);
         |                 ^~~~~~~~~~~~~~~~~~

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

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

* Re: [PATCHv2 1/1] uapi: cdc.h: cleanly provide for more interfaces and countries
  2025-10-30 13:20 [PATCHv2 1/1] uapi: cdc.h: cleanly provide for more interfaces and countries Oliver Neukum
  2025-10-30 15:18 ` Gustavo A. R. Silva
  2025-10-31  9:58 ` kernel test robot
@ 2025-11-01  2:08 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2025-11-01  2:08 UTC (permalink / raw)
  To: Oliver Neukum, gregkh, gustavo, linux-usb
  Cc: llvm, oe-kbuild-all, Oliver Neukum

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/202511010928.O8jbJSc1-lkp@intel.com/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/202511010928.O8jbJSc1-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/202511010928.O8jbJSc1-lkp@intel.com/

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.

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

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

end of thread, other threads:[~2025-11-01  2:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-30 13:20 [PATCHv2 1/1] uapi: cdc.h: cleanly provide for more interfaces and countries Oliver Neukum
2025-10-30 15:18 ` Gustavo A. R. Silva
2025-10-31  9:58 ` kernel test robot
2025-11-01  2:08 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).