[PATCH v2 7/8] USB: cdc-acm: always claim data interface

From: Johan Hovold
Date: Mon Mar 22 2021 - 11:54:20 EST


Make sure to always claim the data interface and bail out if binding
fails.

Note that the driver had a check to verify that the data interface was
not already bound to a driver but would not detect other failures (e.g.
if the interface was not authorised).

Signed-off-by: Johan Hovold <johan@xxxxxxxxxx>
---
drivers/usb/class/cdc-acm.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 6991ffd66c5d..914486d0f68c 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -1296,13 +1296,6 @@ static int acm_probe(struct usb_interface *intf,
if (!combined_interfaces && intf != control_interface)
return -ENODEV;

- if (!combined_interfaces && usb_interface_claimed(data_interface)) {
- /* valid in this context */
- dev_dbg(&intf->dev, "The data interface isn't available\n");
- return -EBUSY;
- }
-
-
if (data_interface->cur_altsetting->desc.bNumEndpoints < 2 ||
control_interface->cur_altsetting->desc.bNumEndpoints == 0)
return -EINVAL;
@@ -1486,7 +1479,11 @@ static int acm_probe(struct usb_interface *intf,
acm->line.bDataBits = 8;
acm_set_line(acm, &acm->line);

- usb_driver_claim_interface(&acm_driver, data_interface, acm);
+ if (!acm->combined_interfaces) {
+ rv = usb_driver_claim_interface(&acm_driver, data_interface, acm);
+ if (rv)
+ goto err_remove_files;
+ }

tty_dev = tty_port_register_device(&acm->port, acm_tty_driver, minor,
&control_interface->dev);
@@ -1508,6 +1505,7 @@ static int acm_probe(struct usb_interface *intf,
usb_set_intfdata(data_interface, NULL);
usb_driver_release_interface(&acm_driver, data_interface);
}
+err_remove_files:
if (acm->country_codes) {
device_remove_file(&acm->control->dev,
&dev_attr_wCountryCodes);
--
2.26.3