]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Bluetooth: btusb: refactor endpoint lookup
authorJohan Hovold <johan@kernel.org>
Mon, 30 Mar 2026 09:41:33 +0000 (11:41 +0200)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Mon, 13 Apr 2026 13:18:16 +0000 (09:18 -0400)
Use the common USB helper for looking up bulk and interrupt endpoints
instead of open coding.

Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
drivers/bluetooth/btusb.c

index 07fc169e03b64922666c6ee91a8172a4ae8dbe4e..4fb0e9dceca0c43e1700f42b10dd7fc19c85d7e7 100644 (file)
@@ -3689,31 +3689,14 @@ static inline int __set_diag_interface(struct hci_dev *hdev)
 {
        struct btusb_data *data = hci_get_drvdata(hdev);
        struct usb_interface *intf = data->diag;
-       int i;
+       int ret;
 
        if (!data->diag)
                return -ENODEV;
 
-       data->diag_tx_ep = NULL;
-       data->diag_rx_ep = NULL;
-
-       for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
-               struct usb_endpoint_descriptor *ep_desc;
-
-               ep_desc = &intf->cur_altsetting->endpoint[i].desc;
-
-               if (!data->diag_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
-                       data->diag_tx_ep = ep_desc;
-                       continue;
-               }
-
-               if (!data->diag_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
-                       data->diag_rx_ep = ep_desc;
-                       continue;
-               }
-       }
-
-       if (!data->diag_tx_ep || !data->diag_rx_ep) {
+       ret = usb_find_common_endpoints(intf->cur_altsetting, &data->diag_rx_ep,
+                                       &data->diag_tx_ep, NULL, NULL);
+       if (ret) {
                bt_dev_err(hdev, "invalid diagnostic descriptors");
                return -ENODEV;
        }
@@ -4039,12 +4022,11 @@ static struct hci_drv btusb_hci_drv = {
 static int btusb_probe(struct usb_interface *intf,
                       const struct usb_device_id *id)
 {
-       struct usb_endpoint_descriptor *ep_desc;
        struct gpio_desc *reset_gpio;
        struct btusb_data *data;
        struct hci_dev *hdev;
        unsigned ifnum_base;
-       int i, err, priv_size;
+       int err, priv_size;
 
        BT_DBG("intf %p id %p", intf, id);
 
@@ -4081,26 +4063,9 @@ static int btusb_probe(struct usb_interface *intf,
        if (!data)
                return -ENOMEM;
 
-       for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
-               ep_desc = &intf->cur_altsetting->endpoint[i].desc;
-
-               if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) {
-                       data->intr_ep = ep_desc;
-                       continue;
-               }
-
-               if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
-                       data->bulk_tx_ep = ep_desc;
-                       continue;
-               }
-
-               if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
-                       data->bulk_rx_ep = ep_desc;
-                       continue;
-               }
-       }
-
-       if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep) {
+       err = usb_find_common_endpoints(intf->cur_altsetting, &data->bulk_rx_ep,
+                                       &data->bulk_tx_ep, &data->intr_ep, NULL);
+       if (err) {
                kfree(data);
                return -ENODEV;
        }