net: refactor USB endpoint lookups
Subsystems (5)
cover net: refactor USB endpoint lookups
Use the common USB helpers for looking up bulk and interrupt endpoints instead of open coding.
Johan
Johan Hovold (2):
net: hso: refactor endpoint lookup
net: ipeth: refactor endpoint lookup
drivers/net/usb/hso.c | 65 +++++++++++----------------------------- drivers/net/usb/ipheth.c | 18 +++++------ 2 files changed, 24 insertions(+), 59 deletions(-)
Signature · 1 line
2.52.0
PATCH 1/2 net: hso: refactor endpoint lookup
Use the common USB helpers for looking up bulk and interrupt endpoints instead of a custom implementation.
--- drivers/net/usb/hso.c | 65 +++++++++++-------------------------------- 1 file changed, 17 insertions(+), 48 deletions(-)
drivers/net/usb/hso.c +17 -48
@@ -298,8 +298,6 @@ static int hso_mux_submit_intr_urb(struct hso_shared_int *mux_int, struct usb_device *usb, gfp_t gfp);static void handle_usb_error (int status,const char *function,struct hso_device *hso_dev); -static struct usb_endpoint_descriptor *hso_get_ep (struct usb_interface *intf, -int type,int dir);static int hso_get_mux_ports (struct usb_interface *intf,unsigned char *ports);static void hso_free_interface (struct usb_interface *intf);static int hso_start_serial_device (struct hso_device *hso_dev,gfp_t flags);
@@ -2497,16 +2495,11 @@ static struct hso_device *hso_create_net_device(struct usb_interface *interface, hso_net->net = net; hso_net->parent = hso_dev; - hso_net->in_endp =hso_get_ep (interface,USB_ENDPOINT_XFER_BULK , -USB_DIR_IN ); -if (!hso_net->in_endp) { -dev_err (&interface->dev,"Can't find BULK IN endpoint\n" ); - goto err_net; - } - hso_net->out_endp =hso_get_ep (interface,USB_ENDPOINT_XFER_BULK , -USB_DIR_OUT ); -if (!hso_net->out_endp) { -dev_err (&interface->dev,"Can't find BULK OUT endpoint\n" ); + result =usb_find_common_endpoints (interface->cur_altsetting, + &hso_net->in_endp, &hso_net->out_endp, +NULL ,NULL ); +if (result) { +dev_err (&interface->dev,"Can't find BULK endpoints\n" ); goto err_net; }SET_NETDEV_DEV (net, &interface->dev);
@@ -2608,10 +2601,12 @@ static void hso_free_serial_device(struct hso_device *hso_dev)static struct hso_device *hso_create_bulk_serial_device (struct usb_interface *interface,int port) { +struct usb_host_interface *iface_desc = interface->cur_altsetting;struct hso_device *hso_dev;struct hso_serial *serial;int num_urbs;struct hso_tiocmget *tiocmget; +int ret; hso_dev =hso_create_device (interface, port);if (!hso_dev)
@@ -2634,10 +2629,8 @@ static struct hso_device *hso_create_bulk_serial_device(if (!serial->tiocmget->serial_state_notification) goto exit; tiocmget = serial->tiocmget; - tiocmget->endp =hso_get_ep (interface, -USB_ENDPOINT_XFER_INT , -USB_DIR_IN ); -if (!tiocmget->endp) { + ret =usb_find_int_in_endpoint (iface_desc, &tiocmget->endp); +if (ret) {dev_err (&interface->dev,"Failed to find INT IN ep\n" ); goto exit; }
@@ -2656,17 +2649,10 @@ static struct hso_device *hso_create_bulk_serial_device( BULK_URB_TX_SIZE)) goto exit; - serial->in_endp =hso_get_ep (interface,USB_ENDPOINT_XFER_BULK , -USB_DIR_IN ); -if (!serial->in_endp) { -dev_err (&interface->dev,"Failed to find BULK IN ep\n" ); - goto exit2; - } - -if (! - (serial->out_endp = -hso_get_ep (interface,USB_ENDPOINT_XFER_BULK ,USB_DIR_OUT ))) { -dev_err (&interface->dev,"Failed to find BULK OUT ep\n" ); + ret =usb_find_common_endpoints (iface_desc, &serial->in_endp, + &serial->out_endp,NULL ,NULL ); +if (ret) { +dev_err (&interface->dev,"Failed to find BULK eps\n" ); goto exit2; }
@@ -2754,13 +2740,14 @@ staticstruct hso_shared_int *hso_create_shared_int (struct usb_interface *interface) {struct hso_shared_int *mux =kzalloc_obj (*mux); +int ret;if (!mux)return NULL ; - mux->intr_endp =hso_get_ep (interface,USB_ENDPOINT_XFER_INT , -USB_DIR_IN ); -if (!mux->intr_endp) { + ret =usb_find_int_in_endpoint (interface->cur_altsetting, + &mux->intr_endp); +if (ret) {dev_err (&interface->dev,"Can't find INT IN endpoint\n" ); goto exit; }
@@ -3134,24 +3121,6 @@ static void hso_free_interface(struct usb_interface *interface)/* Helper functions */ -/* Get the endpoint ! */ -static struct usb_endpoint_descriptor *hso_get_ep (struct usb_interface *intf, -int type,int dir) -{ -int i; -struct usb_host_interface *iface = intf->cur_altsetting; -struct usb_endpoint_descriptor *endp; - -for (i =0 ; i < iface->desc.bNumEndpoints; i++) { - endp = &iface->endpoint[i].desc; -if (((endp->bEndpointAddress &USB_ENDPOINT_DIR_MASK ) == dir) && - (usb_endpoint_type (endp) == type)) -return endp; - } - -return NULL ; -} -/* Get the byte that describes which ports are enabled */ static int hso_get_mux_ports (struct usb_interface *intf,unsigned char *ports) {
Signature · 1 line
2.52.0
PATCH 2/2 net: ipeth: refactor endpoint lookup
In reply to Johan HovoldUse the common USB helper for looking up bulk and interrupt endpoints instead of open coding.
--- drivers/net/usb/ipheth.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
drivers/net/usb/ipheth.c +7 -11
@@ -573,11 +573,10 @@ static int ipheth_probe(struct usb_interface *intf, const struct usb_device_id *id) {struct usb_device *udev =interface_to_usbdev (intf); +struct usb_endpoint_descriptor *ep_in, *ep_out;struct usb_host_interface *hintf; -struct usb_endpoint_descriptor *endp;struct ipheth_device *dev;struct net_device *netdev; -int i;int retval; netdev =alloc_etherdev (sizeof (struct ipheth_device ));
@@ -603,19 +602,16 @@ static int ipheth_probe(struct usb_interface *intf, goto err_endpoints; } -for (i =0 ; i < hintf->desc.bNumEndpoints; i++) { - endp = &hintf->endpoint[i].desc; -if (usb_endpoint_is_bulk_in (endp)) - dev->bulk_in = endp->bEndpointAddress; -else if (usb_endpoint_is_bulk_out (endp)) - dev->bulk_out = endp->bEndpointAddress; - } -if (!(dev->bulk_in && dev->bulk_out)) { - retval = -ENODEV ; + retval =usb_find_common_endpoints_reverse (hintf, &ep_in, &ep_out, +NULL ,NULL ); +if (retval) {dev_err (&intf->dev,"Unable to find endpoints\n" ); goto err_endpoints; } + dev->bulk_in = ep_in->bEndpointAddress; + dev->bulk_out = ep_out->bEndpointAddress; + dev->ctrl_buf =kmalloc (IPHETH_CTRL_BUF_SIZE ,GFP_KERNEL );if (dev->ctrl_buf ==NULL ) { retval = -ENOMEM ;
Signature · 1 line
2.52.0
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Mon, 30 Mar 2026 12:26:09 +0200 you wrote:
Use the common USB helpers for looking up bulk and interrupt endpoints instead of open coding.
Johan
Johan Hovold (2):
net: hso: refactor endpoint lookup
net: ipeth: refactor endpoint lookup[...]
Here is the summary with links:
- [1/2] net: hso: refactor endpoint lookup
https://git.kernel.org/netdev/net-next/c/da45a55748f2
- [2/2] net: ipeth: refactor endpoint lookup
https://git.kernel.org/netdev/net-next/c/abfca6b13bcf
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html