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

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'net-refactor-usb-endpoint-lookups'

Johan Hovold says:

====================
net: refactor USB endpoint lookups

Use the common USB helpers for looking up bulk and interrupt endpoints
instead of open coding.
====================

Link: https://patch.msgid.link/20260330102611.1671546-1-johan@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+24 -59
+17 -48
drivers/net/usb/hso.c
··· 298 298 struct usb_device *usb, gfp_t gfp); 299 299 static void handle_usb_error(int status, const char *function, 300 300 struct hso_device *hso_dev); 301 - static struct usb_endpoint_descriptor *hso_get_ep(struct usb_interface *intf, 302 - int type, int dir); 303 301 static int hso_get_mux_ports(struct usb_interface *intf, unsigned char *ports); 304 302 static void hso_free_interface(struct usb_interface *intf); 305 303 static int hso_start_serial_device(struct hso_device *hso_dev, gfp_t flags); ··· 2495 2497 hso_net->net = net; 2496 2498 hso_net->parent = hso_dev; 2497 2499 2498 - hso_net->in_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, 2499 - USB_DIR_IN); 2500 - if (!hso_net->in_endp) { 2501 - dev_err(&interface->dev, "Can't find BULK IN endpoint\n"); 2502 - goto err_net; 2503 - } 2504 - hso_net->out_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, 2505 - USB_DIR_OUT); 2506 - if (!hso_net->out_endp) { 2507 - dev_err(&interface->dev, "Can't find BULK OUT endpoint\n"); 2500 + result = usb_find_common_endpoints(interface->cur_altsetting, 2501 + &hso_net->in_endp, &hso_net->out_endp, 2502 + NULL, NULL); 2503 + if (result) { 2504 + dev_err(&interface->dev, "Can't find BULK endpoints\n"); 2508 2505 goto err_net; 2509 2506 } 2510 2507 SET_NETDEV_DEV(net, &interface->dev); ··· 2601 2608 static struct hso_device *hso_create_bulk_serial_device( 2602 2609 struct usb_interface *interface, int port) 2603 2610 { 2611 + struct usb_host_interface *iface_desc = interface->cur_altsetting; 2604 2612 struct hso_device *hso_dev; 2605 2613 struct hso_serial *serial; 2606 2614 int num_urbs; 2607 2615 struct hso_tiocmget *tiocmget; 2616 + int ret; 2608 2617 2609 2618 hso_dev = hso_create_device(interface, port); 2610 2619 if (!hso_dev) ··· 2629 2634 if (!serial->tiocmget->serial_state_notification) 2630 2635 goto exit; 2631 2636 tiocmget = serial->tiocmget; 2632 - tiocmget->endp = hso_get_ep(interface, 2633 - USB_ENDPOINT_XFER_INT, 2634 - USB_DIR_IN); 2635 - if (!tiocmget->endp) { 2637 + ret = usb_find_int_in_endpoint(iface_desc, &tiocmget->endp); 2638 + if (ret) { 2636 2639 dev_err(&interface->dev, "Failed to find INT IN ep\n"); 2637 2640 goto exit; 2638 2641 } ··· 2649 2656 BULK_URB_TX_SIZE)) 2650 2657 goto exit; 2651 2658 2652 - serial->in_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, 2653 - USB_DIR_IN); 2654 - if (!serial->in_endp) { 2655 - dev_err(&interface->dev, "Failed to find BULK IN ep\n"); 2656 - goto exit2; 2657 - } 2658 - 2659 - if (! 2660 - (serial->out_endp = 2661 - hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, USB_DIR_OUT))) { 2662 - dev_err(&interface->dev, "Failed to find BULK OUT ep\n"); 2659 + ret = usb_find_common_endpoints(iface_desc, &serial->in_endp, 2660 + &serial->out_endp, NULL, NULL); 2661 + if (ret) { 2662 + dev_err(&interface->dev, "Failed to find BULK eps\n"); 2663 2663 goto exit2; 2664 2664 } 2665 2665 ··· 2740 2754 struct hso_shared_int *hso_create_shared_int(struct usb_interface *interface) 2741 2755 { 2742 2756 struct hso_shared_int *mux = kzalloc_obj(*mux); 2757 + int ret; 2743 2758 2744 2759 if (!mux) 2745 2760 return NULL; 2746 2761 2747 - mux->intr_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_INT, 2748 - USB_DIR_IN); 2749 - if (!mux->intr_endp) { 2762 + ret = usb_find_int_in_endpoint(interface->cur_altsetting, 2763 + &mux->intr_endp); 2764 + if (ret) { 2750 2765 dev_err(&interface->dev, "Can't find INT IN endpoint\n"); 2751 2766 goto exit; 2752 2767 } ··· 3120 3133 } 3121 3134 3122 3135 /* Helper functions */ 3123 - 3124 - /* Get the endpoint ! */ 3125 - static struct usb_endpoint_descriptor *hso_get_ep(struct usb_interface *intf, 3126 - int type, int dir) 3127 - { 3128 - int i; 3129 - struct usb_host_interface *iface = intf->cur_altsetting; 3130 - struct usb_endpoint_descriptor *endp; 3131 - 3132 - for (i = 0; i < iface->desc.bNumEndpoints; i++) { 3133 - endp = &iface->endpoint[i].desc; 3134 - if (((endp->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == dir) && 3135 - (usb_endpoint_type(endp) == type)) 3136 - return endp; 3137 - } 3138 - 3139 - return NULL; 3140 - } 3141 3136 3142 3137 /* Get the byte that describes which ports are enabled */ 3143 3138 static int hso_get_mux_ports(struct usb_interface *intf, unsigned char *ports)
+7 -11
drivers/net/usb/ipheth.c
··· 573 573 const struct usb_device_id *id) 574 574 { 575 575 struct usb_device *udev = interface_to_usbdev(intf); 576 + struct usb_endpoint_descriptor *ep_in, *ep_out; 576 577 struct usb_host_interface *hintf; 577 - struct usb_endpoint_descriptor *endp; 578 578 struct ipheth_device *dev; 579 579 struct net_device *netdev; 580 - int i; 581 580 int retval; 582 581 583 582 netdev = alloc_etherdev(sizeof(struct ipheth_device)); ··· 602 603 goto err_endpoints; 603 604 } 604 605 605 - for (i = 0; i < hintf->desc.bNumEndpoints; i++) { 606 - endp = &hintf->endpoint[i].desc; 607 - if (usb_endpoint_is_bulk_in(endp)) 608 - dev->bulk_in = endp->bEndpointAddress; 609 - else if (usb_endpoint_is_bulk_out(endp)) 610 - dev->bulk_out = endp->bEndpointAddress; 611 - } 612 - if (!(dev->bulk_in && dev->bulk_out)) { 613 - retval = -ENODEV; 606 + retval = usb_find_common_endpoints_reverse(hintf, &ep_in, &ep_out, 607 + NULL, NULL); 608 + if (retval) { 614 609 dev_err(&intf->dev, "Unable to find endpoints\n"); 615 610 goto err_endpoints; 616 611 } 612 + 613 + dev->bulk_in = ep_in->bEndpointAddress; 614 + dev->bulk_out = ep_out->bEndpointAddress; 617 615 618 616 dev->ctrl_buf = kmalloc(IPHETH_CTRL_BUF_SIZE, GFP_KERNEL); 619 617 if (dev->ctrl_buf == NULL) {