Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: serial: ipaq: always register a single port

Use the calc_num_ports callback to ignore unused endpoints.

The driver binds to any interface with at least one bulk-in and one
bulk-out endpoint, but some devices can have three or more endpoints of
which only either the first or second pair of endpoints is needed.

This avoids allocating resources for unused endpoints, and specifically
a port is no longer registered for the unused first endpoint pair when
there are more than three endpoints.

Signed-off-by: Johan Hovold <johan@kernel.org>

+18 -29
+18 -29
drivers/usb/serial/ipaq.c
··· 555 555 struct usb_serial_endpoints *epds) 556 556 { 557 557 /* 558 - * some devices have 3 endpoints, the 3rd of which 559 - * must be ignored as it would make the core 560 - * create a second port which oopses when used 561 - */ 562 - int ipaq_num_ports = 1; 563 - 564 - dev_dbg(&serial->dev->dev, "%s - numberofendpoints: %d\n", __func__, 565 - (int)serial->interface->cur_altsetting->desc.bNumEndpoints); 566 - 567 - /* 568 - * a few devices have 4 endpoints, seemingly Yakuma devices, 569 - * and we need the second pair, so let them have 2 ports 570 - * 571 - * TODO: can we drop port 1 ? 572 - */ 573 - if (serial->interface->cur_altsetting->desc.bNumEndpoints > 3) { 574 - ipaq_num_ports = 2; 575 - } 576 - 577 - /* 578 558 * Some of the devices in ipaq_id_table[] are composite, and we 579 - * shouldn't bind to all the interfaces. This test will rule out 559 + * shouldn't bind to all the interfaces. This test will rule out 580 560 * some obviously invalid possibilities. 581 561 */ 582 - if (epds->num_bulk_in < ipaq_num_ports || 583 - epds->num_bulk_out < ipaq_num_ports) { 562 + if (epds->num_bulk_in == 0 || epds->num_bulk_out == 0) 584 563 return -ENODEV; 564 + 565 + /* 566 + * A few devices have four endpoints, seemingly Yakuma devices, and 567 + * we need the second pair. 568 + */ 569 + if (epds->num_bulk_in > 1 && epds->num_bulk_out > 1) { 570 + epds->bulk_in[0] = epds->bulk_in[1]; 571 + epds->bulk_out[0] = epds->bulk_out[1]; 585 572 } 586 573 587 - return ipaq_num_ports; 588 - } 574 + /* 575 + * Other devices have 3 endpoints, but we only use the first bulk in 576 + * and out endpoints. 577 + */ 578 + epds->num_bulk_in = 1; 579 + epds->num_bulk_out = 1; 589 580 581 + return 1; 582 + } 590 583 591 584 static int ipaq_startup(struct usb_serial *serial) 592 585 { ··· 593 600 serial->dev->actconfig->desc.bConfigurationValue); 594 601 return -ENODEV; 595 602 } 596 - 597 - dev_dbg(&serial->dev->dev, 598 - "%s - iPAQ module configured for %d ports\n", __func__, 599 - serial->num_ports); 600 603 601 604 return usb_reset_configuration(serial->dev); 602 605 }