[PATCH] comedi: ni_usb6501: refactor endpoint lookup

Johan Hovold posted 1 patch 6 days, 23 hours ago
drivers/comedi/drivers/ni_usb6501.c | 23 ++++-------------------
1 file changed, 4 insertions(+), 19 deletions(-)
[PATCH] comedi: ni_usb6501: refactor endpoint lookup
Posted by Johan Hovold 6 days, 23 hours ago
Use the common USB helper for looking up bulk and interrupt endpoints
instead of open coding.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/comedi/drivers/ni_usb6501.c | 23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/drivers/comedi/drivers/ni_usb6501.c b/drivers/comedi/drivers/ni_usb6501.c
index 0dd9edf7bced..7afc5661a5ec 100644
--- a/drivers/comedi/drivers/ni_usb6501.c
+++ b/drivers/comedi/drivers/ni_usb6501.c
@@ -477,31 +477,16 @@ static int ni6501_find_endpoints(struct comedi_device *dev)
 	struct usb_interface *intf = comedi_to_usb_interface(dev);
 	struct ni6501_private *devpriv = dev->private;
 	struct usb_host_interface *iface_desc = intf->cur_altsetting;
-	struct usb_endpoint_descriptor *ep_desc;
-	int i;
+	int ret;
 
 	if (iface_desc->desc.bNumEndpoints != 2) {
 		dev_err(dev->class_dev, "Wrong number of endpoints\n");
 		return -ENODEV;
 	}
 
-	for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
-		ep_desc = &iface_desc->endpoint[i].desc;
-
-		if (usb_endpoint_is_bulk_in(ep_desc)) {
-			if (!devpriv->ep_rx)
-				devpriv->ep_rx = ep_desc;
-			continue;
-		}
-
-		if (usb_endpoint_is_bulk_out(ep_desc)) {
-			if (!devpriv->ep_tx)
-				devpriv->ep_tx = ep_desc;
-			continue;
-		}
-	}
-
-	if (!devpriv->ep_rx || !devpriv->ep_tx)
+	ret = usb_find_common_endpoints(iface_desc, &devpriv->ep_rx,
+					&devpriv->ep_tx, NULL, NULL);
+	if (ret)
 		return -ENODEV;
 
 	if (usb_endpoint_maxp(devpriv->ep_rx) < RX_MAX_SIZE)
-- 
2.52.0
Re: [PATCH] comedi: ni_usb6501: refactor endpoint lookup
Posted by Ian Abbott 5 days, 22 hours ago
On 30/03/2026 10:46, Johan Hovold wrote:
> Use the common USB helper for looking up bulk and interrupt endpoints
> instead of open coding.
> 
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>   drivers/comedi/drivers/ni_usb6501.c | 23 ++++-------------------
>   1 file changed, 4 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/comedi/drivers/ni_usb6501.c b/drivers/comedi/drivers/ni_usb6501.c
> index 0dd9edf7bced..7afc5661a5ec 100644
> --- a/drivers/comedi/drivers/ni_usb6501.c
> +++ b/drivers/comedi/drivers/ni_usb6501.c
> @@ -477,31 +477,16 @@ static int ni6501_find_endpoints(struct comedi_device *dev)
>   	struct usb_interface *intf = comedi_to_usb_interface(dev);
>   	struct ni6501_private *devpriv = dev->private;
>   	struct usb_host_interface *iface_desc = intf->cur_altsetting;
> -	struct usb_endpoint_descriptor *ep_desc;
> -	int i;
> +	int ret;
>   
>   	if (iface_desc->desc.bNumEndpoints != 2) {
>   		dev_err(dev->class_dev, "Wrong number of endpoints\n");
>   		return -ENODEV;
>   	}
>   
> -	for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
> -		ep_desc = &iface_desc->endpoint[i].desc;
> -
> -		if (usb_endpoint_is_bulk_in(ep_desc)) {
> -			if (!devpriv->ep_rx)
> -				devpriv->ep_rx = ep_desc;
> -			continue;
> -		}
> -
> -		if (usb_endpoint_is_bulk_out(ep_desc)) {
> -			if (!devpriv->ep_tx)
> -				devpriv->ep_tx = ep_desc;
> -			continue;
> -		}
> -	}
> -
> -	if (!devpriv->ep_rx || !devpriv->ep_tx)
> +	ret = usb_find_common_endpoints(iface_desc, &devpriv->ep_rx,
> +					&devpriv->ep_tx, NULL, NULL);
> +	if (ret)
>   		return -ENODEV;
>   
>   	if (usb_endpoint_maxp(devpriv->ep_rx) < RX_MAX_SIZE)

Looks good, thanks!

Reviewed-by: Ian Abbott <abbotti@mev.co.uk>

-- 
-=( Ian Abbott <abbotti@mev.co.uk> || MEV Ltd. is a company  )=-
-=( registered in England & Wales.  Regd. number: 02862268.  )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-