Skip to contentSkip to conversation

introducing the common CDC parser to other drivers

PATCH New Oliver Neukum 2 participants 5 messages Oct 19, 2015

Subsystems (5)
lore
Share & tools
lore

Oliver Neukum

author maintainer
#0 lore raw

PATCH v2 1/1 introducing the common CDC parser to other drivers

This series introduces the common CDC parser into the CDC tty and serial drivers. As it depends on the common parser in the netdev tree, Greg agreed for this to go through the netdev tree.

author maintainer
#1 lore raw

PATCH 1/3 cdc-acm: use the common parser for all CDC drivers

From: Oliver Neukum <[email protected]>

Use the common parser in CDC-ACM for code depuplication

---
 drivers/usb/class/cdc-acm.c | 66 +++++++--------------------------------------
 1 file changed, 9 insertions(+), 57 deletions(-)
drivers/usb/class/cdc-acm.c +9 -57
index b30e742..d30e942 100644
@@ -1075,6 +1075,7 @@ static int acm_write_buffers_alloc(struct acm *acm)
 static int acm_probe(struct usb_interface *intf,
 		     const struct usb_device_id *id)
 {
+	struct usb_cdc_parsed_header header;
 	struct usb_cdc_union_desc *union_header = NULL;
 	struct usb_cdc_country_functional_desc *cfd = NULL;
 	unsigned char *buffer = intf->altsetting->extra;
@@ -1090,13 +1091,12 @@ static int acm_probe(struct usb_interface *intf,
 	int ctrlsize, readsize;
 	u8 *buf;
 	u8 ac_management_function = 0;
-	u8 call_management_function = 0;
+	u8 call_management_function;
 	int call_interface_num = -1;
 	int data_interface_num = -1;
 	unsigned long quirks;
 	int num_rx_buf;
 	int i;
-	unsigned int elength = 0;
 	int combined_interfaces = 0;
 	struct device *tty_dev;
 	int rv = -ENOMEM;
@@ -1137,61 +1137,13 @@ static int acm_probe(struct usb_interface *intf,
 		}
 	}
 
-	while (buflen > 0) {
-		elength = buffer[0];
-		if (!elength) {
-			dev_err(&intf->dev, "skipping garbage byte\n");
-			elength = 1;
-			goto next_desc;
-		}
-		if (buffer[1] != USB_DT_CS_INTERFACE) {
-			dev_err(&intf->dev, "skipping garbage\n");
-			goto next_desc;
-		}
-
-		switch (buffer[2]) {
-		case USB_CDC_UNION_TYPE: /* we've found it */
-			if (elength < sizeof(struct usb_cdc_union_desc))
-				goto next_desc;
-			if (union_header) {
-				dev_err(&intf->dev, "More than one "
-					"union descriptor, skipping ...\n");
-				goto next_desc;
-			}
-			union_header = (struct usb_cdc_union_desc *)buffer;
-			break;
-		case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/
-			if (elength < sizeof(struct usb_cdc_country_functional_desc))
-				goto next_desc;
-			cfd = (struct usb_cdc_country_functional_desc *)buffer;
-			break;
-		case USB_CDC_HEADER_TYPE: /* maybe check version */
-			break; /* for now we ignore it */
-		case USB_CDC_ACM_TYPE:
-			if (elength < 4)
-				goto next_desc;
-			ac_management_function = buffer[3];
-			break;
-		case USB_CDC_CALL_MANAGEMENT_TYPE:
-			if (elength < 5)
-				goto next_desc;
-			call_management_function = buffer[3];
-			call_interface_num = buffer[4];
-			break;
-		default:
-			/*
-			 * there are LOTS more CDC descriptors that
-			 * could legitimately be found here.
-			 */
-			dev_dbg(&intf->dev, "Ignoring descriptor: "
-					"type %02x, length %ud\n",
-					buffer[2], elength);
-			break;
-		}
-next_desc:
-		buflen -= elength;
-		buffer += elength;
-	}
+	cdc_parse_cdc_header(&header, intf, buffer, buflen);
+	union_header = header.usb_cdc_union_desc;
+	call_management_function = header.usb_cdc_call_mgmt_descriptor->bmCapabilities;
+	if (call_management_function)
+		call_interface_num = header.usb_cdc_call_mgmt_descriptor->bDataInterface;
+	ac_management_function = header.usb_cdc_acm_descriptor->bmCapabilities;
+	cfd = header.usb_cdc_country_functional_desc;
 
 	if (!union_header) {
 		if (call_interface_num > 0) {
Signature · 1 line
2.1.4
author maintainer
#2 lore raw

PATCH 2/3 cdc-wdm: use common CDC parser

In reply to Oliver Neukum

From: Oliver Neukum <[email protected]>

cdc-wdm can use the common parser for the CDC extra header. Code duplication is reduced.

---
 drivers/usb/class/cdc-wdm.c | 29 ++++-------------------------
 1 file changed, 4 insertions(+), 25 deletions(-)
drivers/usb/class/cdc-wdm.c +4 -25
index 61ea879..2177069 100644
@@ -875,38 +875,17 @@ static int wdm_probe(struct usb_interface *intf, const struct usb_device_id *id)
 	int rv = -EINVAL;
 	struct usb_host_interface *iface;
 	struct usb_endpoint_descriptor *ep;
-	struct usb_cdc_dmm_desc *dmhd;
+	struct usb_cdc_parsed_header header;
 	u8 *buffer = intf->altsetting->extra;
 	int buflen = intf->altsetting->extralen;
 	u16 maxcom = WDM_DEFAULT_BUFSIZE;
 
 	if (!buffer)
 		goto err;
-	while (buflen > 2) {
-		if (buffer[1] != USB_DT_CS_INTERFACE) {
-			dev_err(&intf->dev, "skipping garbage\n");
-			goto next_desc;
-		}
 
-		switch (buffer[2]) {
-		case USB_CDC_HEADER_TYPE:
-			break;
-		case USB_CDC_DMM_TYPE:
-			dmhd = (struct usb_cdc_dmm_desc *)buffer;
-			maxcom = le16_to_cpu(dmhd->wMaxCommand);
-			dev_dbg(&intf->dev,
-				"Finding maximum buffer length: %d", maxcom);
-			break;
-		default:
-			dev_err(&intf->dev,
-				"Ignoring extra header, type %d, length %d\n",
-				buffer[2], buffer[0]);
-			break;
-		}
-next_desc:
-		buflen -= buffer[0];
-		buffer += buffer[0];
-	}
+	cdc_parse_cdc_header(&header, intf, buffer, buflen);
+	if (header.usb_cdc_dmm_desc)
+		maxcom = le16_to_cpu(header.usb_cdc_dmm_desc->wMaxCommand);
 
 	iface = intf->cur_altsetting;
 	if (iface->desc.bNumEndpoints != 1)
Signature · 1 line
2.1.4
author maintainer
#3 lore raw

PATCH 3/3 CDC parser: add dependencies

In reply to Oliver Neukum

Using the common parser for CDC extra headers means that cdc-acm and cdc-wdm need to select usbnet

---
 drivers/net/usb/Kconfig   | 10 +++++-----
 drivers/usb/class/Kconfig |  2 ++
 2 files changed, 7 insertions(+), 5 deletions(-)
drivers/net/usb/Kconfig +5 -5
index 3a8a36c..8cf0eba 100644
@@ -262,7 +262,7 @@ config USB_NET_CDC_NCM
 
 config USB_NET_HUAWEI_CDC_NCM
 	tristate "Huawei NCM embedded AT channel support"
-	depends on USB_USBNET
+	select USB_USBNET
 	select USB_WDM
 	select USB_NET_CDC_NCM
 	help
@@ -277,7 +277,7 @@ config USB_NET_HUAWEI_CDC_NCM
 
 config USB_NET_CDC_MBIM
 	tristate "CDC MBIM support"
-	depends on USB_USBNET
+	select USB_USBNET
 	select USB_WDM
 	select USB_NET_CDC_NCM
 	help
@@ -381,7 +381,7 @@ config USB_NET_MCS7830
 
 config USB_NET_RNDIS_HOST
 	tristate "Host for RNDIS and ActiveSync devices"
-	depends on USB_USBNET
+	select USB_USBNET
 	select USB_NET_CDCETHER
 	help
 	  This option enables hosting "Remote NDIS" USB networking links,
@@ -466,7 +466,7 @@ config USB_KC2190
 
 config USB_NET_ZAURUS
 	tristate "Sharp Zaurus (stock ROMs) and compatible"
-	depends on USB_USBNET
+	select USB_USBNET
 	select USB_NET_CDCETHER
 	select CRC32
 	default y
@@ -502,7 +502,7 @@ config USB_NET_KALMIA
 
 config USB_NET_QMI_WWAN
 	tristate "QMI WWAN driver for Qualcomm MSM based 3G and LTE modems"
-	depends on USB_USBNET
+	select USB_USBNET
 	select USB_WDM
 	help
 	  Support WWAN LTE/3G devices based on Qualcomm Mobile Data Modem
drivers/usb/class/Kconfig +2 -0
index bb8b736..e3c05b2 100644
@@ -6,6 +6,7 @@ comment "USB Device Class drivers"
 config USB_ACM
 	tristate "USB Modem (CDC ACM) support"
 	depends on TTY
+	select USB_USBNET
 	---help---
 	  This driver supports USB modems and ISDN adapters which support the
 	  Communication Device Class Abstract Control Model interface.
@@ -29,6 +30,7 @@ config USB_PRINTER
 
 config USB_WDM
 	tristate "USB Wireless Device Management support"
+	select USB_USBNET
 	---help---
 	  This driver supports the WMC Device Management functionality
 	  of cell phones compliant to the CDC WMC specification. You can use
Signature · 1 line
2.1.4
#4 lore raw

Re: [PATCH 3/3] CDC parser: add dependencies

reproduce:

Hi Oliver,

[auto build test WARNING on usb/usb-next -- if it's inappropriate base, please suggest rules for selecting the more suitable base]

url:    https://github.com/0day-ci/linux/commits/Oliver-Neukum/cdc-acm-use-the-common-parser-for-all-CDC-drivers/20151019-195318
config: x86_64-randconfig-x015-201542 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

warning: (USB_NET_RNDIS_WLAN && USB_ACM && USB_WDM) selects USB_USBNET which has unmet direct dependencies (NETDEVICES && USB_NET_DRIVERS)

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation