uapi: cdc.h: cleanly provide for more interfaces and countries
Subsystems (3)
Oliver Neukum
maintainerPATCH v3 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. This is subject to sanity checking in cdc_parse_cdc_header(), thus we can trust the length.
V2: following Gustavo's suggestion to use an union
V3: following Gustavo's suggestion on safe copying
--- 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
@@ -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, cfd->wCountryCodes, cfd->bLength -4 ); acm->country_rel_date = cfd->iCountryCodeRelDate;
include/uapi/linux/usb/cdc.h +8 -4
@@ -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
Quoted 31 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. This is subject to sanity checking in
cdc_parse_cdc_header(), thus we can trust the length.V2: following Gustavo's suggestion to use an union
V3: following Gustavo's suggestion on safe copyingSigned-off-by Oliver Neukum <[email protected]>--- 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@@ -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, cfd->wCountryCodes, cfd->bLength -4 ); acm->country_rel_date = cfd->iCountryCodeRelDate;include/uapi/linux/usb/cdc.h +0
-0
include/uapi/linux/usb/cdc.h struct usb_cdc_union_desc { · line 109
Quoted 8 lines
include/uapi/linux/usb/cdc.h +3
-2@@ -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);
For UAPI code, __DECLARE_FLEX_ARRAY() should be used.
include/uapi/linux/usb/cdc.h struct usb_cdc_country_functional_desc { · line 122
Quoted 13 lines
include/uapi/linux/usb/cdc.h +4
-2+ }; } __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);
Ditto.
Thanks
-Gustavo