Skip to contentSkip to conversation

Bluetooth: hci_uart: Refactor h4_recv_buf code into h4_recv_skb

PATCH In review Luiz Augusto von Dentz 3 participants 5 messages Nov 5, 2025 – Nov 7, 2025 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/2 Bluetooth: hci_uart: Refactor h4_recv_buf code into h4_recv_skb

From: Luiz Augusto von Dentz <[email protected]>

This refactors h4_recv_buf into h4_recv_skb so it can be used by btusb to implement Bulk Serialization Mode.

---
 drivers/bluetooth/hci_h4.c   | 45 +++++++++++++++++++++++++-----------
 drivers/bluetooth/hci_uart.h |  4 ++++
 2 files changed, 35 insertions(+), 14 deletions(-)
drivers/bluetooth/hci_h4.c +31 -14
index ec017df8572c..366a66b79e78 100644
@@ -112,8 +112,9 @@ static int h4_recv(struct hci_uart *hu, const void *data, int count)
 	if (!test_bit(HCI_UART_REGISTERED, &hu->flags))
 		return -EUNATCH;
 
-	h4->rx_skb = h4_recv_buf(hu, h4->rx_skb, data, count,
-				 h4_recv_pkts, ARRAY_SIZE(h4_recv_pkts));
+	h4->rx_skb = h4_recv_skb(hu->hdev, &hu->alignment, &hu->padding,
+				 h4->rx_skb, data, count, h4_recv_pkts,
+				 ARRAY_SIZE(h4_recv_pkts));
 	if (IS_ERR(h4->rx_skb)) {
 		int err = PTR_ERR(h4->rx_skb);
 		bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err);
@@ -151,12 +152,12 @@ int __exit h4_deinit(void)
 	return hci_uart_unregister_proto(&h4p);
 }
 
-struct sk_buff *h4_recv_buf(struct hci_uart *hu, struct sk_buff *skb,
-			    const unsigned char *buffer, int count,
-			    const struct h4_recv_pkt *pkts, int pkts_count)
+struct sk_buff *h4_recv_skb(struct hci_dev *hdev, u8 *alignment, u8 *padding,
+			    struct sk_buff *skb, const unsigned char *buffer,
+			    int count, const struct h4_recv_pkt *pkts,
+			    int pkts_count)
 {
-	u8 alignment = hu->alignment ? hu->alignment : 1;
-	struct hci_dev *hdev = hu->hdev;
+	u8 align = alignment && *alignment ? *alignment : 1;
 
 	/* Check for error from previous call */
 	if (IS_ERR(skb))
@@ -166,10 +167,13 @@ struct sk_buff *h4_recv_buf(struct hci_uart *hu, struct sk_buff *skb,
 		int i, len;
 
 		/* remove padding bytes from buffer */
-		for (; hu->padding && count > 0; hu->padding--) {
-			count--;
-			buffer++;
+		if (padding) {
+			for (; (*padding) && count > 0; (*padding)--) {
+				count--;
+				buffer++;
+			}
 		}
+
 		if (!count)
 			break;
 
@@ -252,16 +256,20 @@ struct sk_buff *h4_recv_buf(struct hci_uart *hu, struct sk_buff *skb,
 			}
 
 			if (!dlen) {
-				hu->padding = (skb->len + 1) % alignment;
-				hu->padding = (alignment - hu->padding) % alignment;
+				if (padding) {
+					*padding = (skb->len + 1) % align;
+					*padding = (align - *padding) % align;
+				}
 
 				/* No more data, complete frame */
 				(&pkts[i])->recv(hdev, skb);
 				skb = NULL;
 			}
 		} else {
-			hu->padding = (skb->len + 1) % alignment;
-			hu->padding = (alignment - hu->padding) % alignment;
+			if (padding) {
+				*padding = (skb->len + 1) % align;
+				*padding = (align - *padding) % align;
+			}
 
 			/* Complete frame */
 			(&pkts[i])->recv(hdev, skb);
@@ -271,4 +279,13 @@ struct sk_buff *h4_recv_buf(struct hci_uart *hu, struct sk_buff *skb,
 
 	return skb;
 }
+EXPORT_SYMBOL_GPL(h4_recv_skb);
+
+struct sk_buff *h4_recv_buf(struct hci_uart *hu, struct sk_buff *skb,
+			    const unsigned char *buffer, int count,
+			    const struct h4_recv_pkt *pkts, int pkts_count)
+{
+	return h4_recv_skb(hu->hdev, &hu->alignment, &hu->padding, skb, buffer,
+			   count, pkts, pkts_count);
+}
 EXPORT_SYMBOL_GPL(h4_recv_buf);
drivers/bluetooth/hci_uart.h +4 -0
index 48ac7ca9334e..501b70889567 100644
@@ -165,6 +165,10 @@ int h4_deinit(void);
 struct sk_buff *h4_recv_buf(struct hci_uart *hu, struct sk_buff *skb,
 			    const unsigned char *buffer, int count,
 			    const struct h4_recv_pkt *pkts, int pkts_count);
+struct sk_buff *h4_recv_skb(struct hci_dev *hdev, u8 *alignment, u8 *padding,
+			    struct sk_buff *skb, const unsigned char *buffer,
+			    int count, const struct h4_recv_pkt *pkts,
+			    int pkts_count);
 #endif
 
 #ifdef CONFIG_BT_HCIUART_BCSP
Signature · 1 line
2.51.0
author maintainer
#1 lore raw

PATCH 2/2 Bluetooth: btusb: Add support for Bulk Serialization Mode

From: Luiz Augusto von Dentz <[email protected]>

This adds support for Bulk Serialization Mode introduced in 6.2:

https://www.bluetooth.com/bluetooth-core-6-2-feature-overview/#5-bluetooth-hci-usb-le-isochronous-support
https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-62/out/en/host-controller-interface/usb-transport-layer.html#UUID-c1a65395-29e9-87d3-2981-8bed625d0459

It works by detecting if alternate setting 1 is supported for the interface and then switches to use it as it serializes all the frames in a single Bulk endpoint using H4 headers and it considerable more robust then legacy one while allowing the transport of ISO packets:

'In addition to enabling Bluetooth® LE Audio, the new mode resolves a persistent race condition in the legacy USB transport layer. In Legacy Mode, different endpoint types are serviced in a specific order within a USB frame, which can result in out-of-order delivery of data and events. For example, a Host might receive a data packet before the event signaling its arrival. This behavior can disrupt critical processes such as connection setup, disconnection, and data encryption, adversely affecting the user experience.'

---
 drivers/bluetooth/btusb.c | 142 +++++++++++++++++++++++++++-----------
 1 file changed, 102 insertions(+), 40 deletions(-)
drivers/bluetooth/btusb.c +102 -40
index dcbff764122f..e565f598b923 100644
@@ -27,8 +27,9 @@
 #include "btbcm.h"
 #include "btrtl.h"
 #include "btmtk.h"
+#include "hci_uart.h"
 
-#define VERSION "0.8"
+#define VERSION "1.0"
 
 static bool disable_scofix;
 static bool force_scofix;
@@ -896,6 +897,9 @@ struct qca_dump_info {
 #define BTUSB_ALT6_CONTINUOUS_TX	16
 #define BTUSB_HW_SSR_ACTIVE	17
 
+#define BTUSB_PROTO_LEGACY	0x00
+#define BTUSB_PROTO_H4		0x01
+
 struct btusb_data {
 	struct hci_dev       *hdev;
 	struct usb_device    *udev;
@@ -929,6 +933,7 @@ struct btusb_data {
 	struct sk_buff *evt_skb;
 	struct sk_buff *acl_skb;
 	struct sk_buff *sco_skb;
+	struct sk_buff *rx_skb;
 
 	struct usb_endpoint_descriptor *intr_ep;
 	struct usb_endpoint_descriptor *bulk_tx_ep;
@@ -942,6 +947,7 @@ struct btusb_data {
 
 	__u8 cmdreq_type;
 	__u8 cmdreq;
+	__u8 proto;
 
 	unsigned int sco_num;
 	unsigned int air_mode;
@@ -1265,12 +1271,35 @@ static int btusb_recv_acl(struct btusb_data *data, struct sk_buff *skb)
 	return 0;
 }
 
+static const struct h4_recv_pkt btusb_recv_pkts[] = {
+	{ H4_RECV_ACL,          .recv = hci_recv_frame },
+	{ H4_RECV_SCO,          .recv = hci_recv_frame },
+	{ H4_RECV_EVENT,        .recv = hci_recv_frame },
+	{ H4_RECV_ISO,          .recv = hci_recv_frame },
+};
+
+static int btusb_recv_h4(struct btusb_data *data, void *buffer, int count)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&data->rxlock, flags);
+	data->rx_skb = h4_recv_skb(data->hdev, NULL, NULL, data->rx_skb, buffer,
+				   count, btusb_recv_pkts,
+				   ARRAY_SIZE(btusb_recv_pkts));
+	spin_unlock_irqrestore(&data->rxlock, flags);
+
+	return 0;
+}
+
 static int btusb_recv_bulk(struct btusb_data *data, void *buffer, int count)
 {
 	struct sk_buff *skb;
 	unsigned long flags;
 	int err = 0;
 
+	if (data->proto == BTUSB_PROTO_H4)
+		return btusb_recv_h4(data, buffer, count);
+
 	spin_lock_irqsave(&data->rxlock, flags);
 	skb = data->acl_skb;
 
@@ -1950,12 +1979,14 @@ static int btusb_open(struct hci_dev *hdev)
 
 	data->intf->needs_remote_wakeup = 1;
 
-	if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags))
-		goto done;
+	if (data->proto == BTUSB_PROTO_LEGACY) {
+		if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags))
+			goto done;
 
-	err = btusb_submit_intr_urb(hdev, GFP_KERNEL);
-	if (err < 0)
-		goto failed;
+		err = btusb_submit_intr_urb(hdev, GFP_KERNEL);
+		if (err < 0)
+			goto failed;
+	}
 
 	err = btusb_submit_bulk_urb(hdev, GFP_KERNEL);
 	if (err < 0) {
@@ -2045,6 +2076,34 @@ static int btusb_flush(struct hci_dev *hdev)
 	return 0;
 }
 
+static struct urb *alloc_bulk_urb(struct hci_dev *hdev, struct sk_buff *skb)
+{
+	struct btusb_data *data = hci_get_drvdata(hdev);
+	struct urb *urb;
+	unsigned int pipe;
+
+	if (!data->bulk_tx_ep)
+		return ERR_PTR(-ENODEV);
+
+	urb = usb_alloc_urb(0, GFP_KERNEL);
+	if (!urb)
+		return ERR_PTR(-ENOMEM);
+
+	pipe = usb_sndbulkpipe(data->udev, data->bulk_tx_ep->bEndpointAddress);
+
+	if (data->proto == BTUSB_PROTO_H4) {
+		/* Prepend skb with frame type */
+		memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
+	}
+
+	usb_fill_bulk_urb(urb, data->udev, pipe,
+			  skb->data, skb->len, btusb_tx_complete, skb);
+
+	skb->dev = (void *)hdev;
+
+	return urb;
+}
+
 static struct urb *alloc_ctrl_urb(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	struct btusb_data *data = hci_get_drvdata(hdev);
@@ -2052,6 +2111,9 @@ static struct urb *alloc_ctrl_urb(struct hci_dev *hdev, struct sk_buff *skb)
 	struct urb *urb;
 	unsigned int pipe;
 
+	if (data->proto == BTUSB_PROTO_H4)
+		return alloc_bulk_urb(hdev, skb);
+
 	urb = usb_alloc_urb(0, GFP_KERNEL);
 	if (!urb)
 		return ERR_PTR(-ENOMEM);
@@ -2078,35 +2140,15 @@ static struct urb *alloc_ctrl_urb(struct hci_dev *hdev, struct sk_buff *skb)
 	return urb;
 }
 
-static struct urb *alloc_bulk_urb(struct hci_dev *hdev, struct sk_buff *skb)
-{
-	struct btusb_data *data = hci_get_drvdata(hdev);
-	struct urb *urb;
-	unsigned int pipe;
-
-	if (!data->bulk_tx_ep)
-		return ERR_PTR(-ENODEV);
-
-	urb = usb_alloc_urb(0, GFP_KERNEL);
-	if (!urb)
-		return ERR_PTR(-ENOMEM);
-
-	pipe = usb_sndbulkpipe(data->udev, data->bulk_tx_ep->bEndpointAddress);
-
-	usb_fill_bulk_urb(urb, data->udev, pipe,
-			  skb->data, skb->len, btusb_tx_complete, skb);
-
-	skb->dev = (void *)hdev;
-
-	return urb;
-}
-
 static struct urb *alloc_isoc_urb(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	struct btusb_data *data = hci_get_drvdata(hdev);
 	struct urb *urb;
 	unsigned int pipe;
 
+	if (data->proto == BTUSB_PROTO_H4)
+		return alloc_bulk_urb(hdev, skb);
+
 	if (!data->isoc_tx_ep)
 		return ERR_PTR(-ENODEV);
 
@@ -2320,10 +2362,9 @@ static int btusb_switch_alt_setting(struct hci_dev *hdev, int new_alts)
 	return 0;
 }
 
-static struct usb_host_interface *btusb_find_altsetting(struct btusb_data *data,
-							int alt)
+static struct usb_host_interface *
+btusb_find_altsetting(struct usb_interface *intf, int alt)
 {
-	struct usb_interface *intf = data->isoc;
 	int i;
 
 	BT_DBG("Looking for Alt no :%d", alt);
@@ -2376,9 +2417,9 @@ static void btusb_work(struct work_struct *work)
 			 * MTU >= 3 (packets) * 25 (size) - 3 (headers) = 72
 			 * see also Core spec 5, vol 4, B 2.1.1 & Table 2.1.
 			 */
-			if (btusb_find_altsetting(data, 6))
+			if (btusb_find_altsetting(data->isoc, 6))
 				new_alts = 6;
-			else if (btusb_find_altsetting(data, 3) &&
+			else if (btusb_find_altsetting(data->isoc, 3) &&
 				 hdev->sco_mtu >= 72 &&
 				 test_bit(BTUSB_USE_ALT3_FOR_WBS, &data->flags))
 				new_alts = 3;
@@ -3827,8 +3868,11 @@ static ssize_t force_poll_sync_write(struct file *file,
 	if (err)
 		return err;
 
-	/* Only allow changes while the adapter is down */
-	if (test_bit(HCI_UP, &data->hdev->flags))
+	/* Only allow changes while the adapter is down and it is using legacy
+	 * protocol.
+	 */
+	if (test_bit(HCI_UP, &data->hdev->flags) ||
+	    data->proto != BTUSB_PROTO_LEGACY)
 		return -EPERM;
 
 	if (data->poll_sync == enable)
@@ -3927,7 +3971,7 @@ static int btusb_hci_drv_supported_altsettings(struct hci_dev *hdev, void *data,
 		goto done;
 
 	for (i = 0; i <= 6; i++) {
-		if (btusb_find_altsetting(drvdata, i))
+		if (btusb_find_altsetting(drvdata->isoc, i))
 			rp->altsettings[rp->num++] = i;
 	}
 
@@ -4022,6 +4066,15 @@ static int btusb_probe(struct usb_interface *intf,
 	if (!data)
 		return -ENOMEM;
 
+	/* If alternate setting 1 is found, it means H4 mode is supported */
+	if (btusb_find_altsetting(intf, 1)) {
+		struct usb_device *udev = interface_to_usbdev(intf);
+
+		err = usb_set_interface(udev, ifnum_base, 1);
+		if (!err)
+			data->proto = BTUSB_PROTO_H4;
+	}
+
 	for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
 		ep_desc = &intf->cur_altsetting->endpoint[i].desc;
 
@@ -4041,8 +4094,16 @@ static int btusb_probe(struct usb_interface *intf,
 		}
 	}
 
-	if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep)
-		return -ENODEV;
+	/* Check if all endpoints could be enumerated, legacy mode requires
+	 * interrupt and bulk endpoint while H4 mode only requires bulk
+	 * endpoints.
+	 */
+	if ((data->proto == BTUSB_PROTO_LEGACY && !data->intr_ep) ||
+	    !data->bulk_tx_ep || !data->bulk_rx_ep) {
+		BT_ERR("failed to enumerate endpoints");
+		err = -ENODEV;
+		goto out_free_dev;
+	}
 
 	if (id->driver_info & BTUSB_AMP) {
 		data->cmdreq_type = USB_TYPE_CLASS | 0x01;
@@ -4355,7 +4416,8 @@ static int btusb_probe(struct usb_interface *intf,
 	if (enable_autosuspend)
 		usb_enable_autosuspend(data->udev);
 
-	data->poll_sync = enable_poll_sync;
+	if (data->proto == BTUSB_PROTO_LEGACY)
+		data->poll_sync = enable_poll_sync;
 
 	err = hci_register_dev(hdev);
 	if (err < 0)
Signature · 1 line
2.51.0
#2 lore raw

Re: [PATCH v1 2/2] Bluetooth: btusb: Add support for Bulk Serialization Mode

kernel test robot noticed the following build errors:

Hi Luiz,

kernel test robot noticed the following build errors:

[auto build test ERROR on bluetooth-next/master]
[also build test ERROR on bluetooth/master linus/master v6.18-rc4 next-20251105] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Luiz-Augusto-von-Dentz/Bluetooth-btusb-Add-support-for-Bulk-Serialization-Mode/20251106-024830
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
patch link:    https://lore.kernel.org/r/20251105170445.518320-2-luiz.dentz%40gmail.com
patch subject: [PATCH v1 2/2] Bluetooth: btusb: Add support for Bulk Serialization Mode
config: nios2-randconfig-002-20251106 (https://download.01.org/0day-ci/archive/20251106/[email protected]/config)
compiler: nios2-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251106/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

drivers/bluetooth/btusb.c: In function 'btusb_recv_h4':

>> drivers/bluetooth/btusb.c:1286:17: error: implicit declaration of function 'h4_recv_skb'; did you mean 'sk_eat_skb'? [-Werror=implicit-function-declaration]
     data->rx_skb = h4_recv_skb(data->hdev, NULL, NULL, data->rx_skb, buffer,
                    ^~~~~~~~~~~
                    sk_eat_skb
>> drivers/bluetooth/btusb.c:1286:15: warning: assignment to 'struct sk_buff *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
     data->rx_skb = h4_recv_skb(data->hdev, NULL, NULL, data->rx_skb, buffer,
                  ^

cc1: some warnings being treated as errors

vim +1286 drivers/bluetooth/btusb.c

1280
1281 static int btusb_recv_h4(struct btusb_data *data, void *buffer, int count)
1282 {
1283 unsigned long flags;
1284
1285 spin_lock_irqsave(&data->rxlock, flags);

> 1286		data->rx_skb = h4_recv_skb(data->hdev, NULL, NULL, data->rx_skb, buffer,

1287 count, btusb_recv_pkts,
1288 ARRAY_SIZE(btusb_recv_pkts));
1289 spin_unlock_irqrestore(&data->rxlock, flags);
1290
1291 return 0;
1292 }
1293

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw

Re: [PATCH v1 2/2] Bluetooth: btusb: Add support for Bulk Serialization Mode

In reply to Luiz Augusto von Dentz
kernel test robot noticed the following build warnings:

Hi Luiz,

kernel test robot noticed the following build warnings:

[auto build test WARNING on bluetooth-next/master]
[also build test WARNING on bluetooth/master linus/master v6.18-rc4 next-20251106] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Luiz-Augusto-von-Dentz/Bluetooth-btusb-Add-support-for-Bulk-Serialization-Mode/20251106-024830
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
patch link:    https://lore.kernel.org/r/20251105170445.518320-2-luiz.dentz%40gmail.com
patch subject: [PATCH v1 2/2] Bluetooth: btusb: Add support for Bulk Serialization Mode
config: loongarch-allmodconfig (https://download.01.org/0day-ci/archive/20251107/[email protected]/config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251107/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/bluetooth/btusb.c:4101:6: warning: variable 'hdev' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
    4101 |         if ((data->proto == BTUSB_PROTO_LEGACY && !data->intr_ep) ||
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    4102 |             !data->bulk_tx_ep || !data->bulk_rx_ep) {
         |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/bluetooth/btusb.c:4436:15: note: uninitialized use occurs here
    4436 |         hci_free_dev(hdev);
         |                      ^~~~
   drivers/bluetooth/btusb.c:4101:2: note: remove the 'if' if its condition is always false
    4101 |         if ((data->proto == BTUSB_PROTO_LEGACY && !data->intr_ep) ||
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    4102 |             !data->bulk_tx_ep || !data->bulk_rx_ep) {
         |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    4103 |                 BT_ERR("failed to enumerate endpoints");
         |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    4104 |                 err = -ENODEV;
         |                 ~~~~~~~~~~~~~~
    4105 |                 goto out_free_dev;
         |                 ~~~~~~~~~~~~~~~~~~
    4106 |         }
         |         ~
>> drivers/bluetooth/btusb.c:4101:6: warning: variable 'hdev' is used uninitialized whenever '||' condition is true [-Wsometimes-uninitialized]
    4101 |         if ((data->proto == BTUSB_PROTO_LEGACY && !data->intr_ep) ||
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    4102 |             !data->bulk_tx_ep || !data->bulk_rx_ep) {
         |             ~~~~~~~~~~~~~~~~~
   drivers/bluetooth/btusb.c:4436:15: note: uninitialized use occurs here
    4436 |         hci_free_dev(hdev);
         |                      ^~~~
   drivers/bluetooth/btusb.c:4101:6: note: remove the '||' if its condition is always false
    4101 |         if ((data->proto == BTUSB_PROTO_LEGACY && !data->intr_ep) ||
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    4102 |             !data->bulk_tx_ep || !data->bulk_rx_ep) {
         |             ~~~~~~~~~~~~~~~~~~~~
>> drivers/bluetooth/btusb.c:4101:6: warning: variable 'hdev' is used uninitialized whenever '||' condition is true [-Wsometimes-uninitialized]
    4101 |         if ((data->proto == BTUSB_PROTO_LEGACY && !data->intr_ep) ||
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/bluetooth/btusb.c:4436:15: note: uninitialized use occurs here
    4436 |         hci_free_dev(hdev);
         |                      ^~~~
   drivers/bluetooth/btusb.c:4101:6: note: remove the '||' if its condition is always false
    4101 |         if ((data->proto == BTUSB_PROTO_LEGACY && !data->intr_ep) ||
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/bluetooth/btusb.c:4030:22: note: initialize the variable 'hdev' to silence this warning
    4030 |         struct hci_dev *hdev;
         |                             ^
         |                              = NULL

3 warnings generated.

vim +4101 drivers/bluetooth/btusb.c

4023
4024 static int btusb_probe(struct usb_interface *intf,
4025 const struct usb_device_id *id)
4026 {
4027 struct usb_endpoint_descriptor *ep_desc;
4028 struct gpio_desc *reset_gpio;
4029 struct btusb_data *data;
4030 struct hci_dev *hdev;
4031 unsigned ifnum_base;
4032 int i, err, priv_size;
4033
4034 BT_DBG("intf %p id %p", intf, id);
4035
4036 if ((id->driver_info & BTUSB_IFNUM_2) &&
4037 (intf->cur_altsetting->desc.bInterfaceNumber != 0) &&
4038 (intf->cur_altsetting->desc.bInterfaceNumber != 2))
4039 return -ENODEV;
4040
4041 ifnum_base = intf->cur_altsetting->desc.bInterfaceNumber;
4042
4043 if (!id->driver_info) {
4044 const struct usb_device_id *match;
4045
4046 match = usb_match_id(intf, quirks_table);
4047 if (match)
4048 id = match;
4049 }
4050
4051 if (id->driver_info == BTUSB_IGNORE)
4052 return -ENODEV;
4053
4054 if (id->driver_info & BTUSB_ATH3012) {
4055 struct usb_device *udev = interface_to_usbdev(intf);
4056
4057 /* Old firmware would otherwise let ath3k driver load
4058 * patch and sysconfig files
4059 */
4060 if (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x0001 &&
4061 !btusb_qca_need_patch(udev))
4062 return -ENODEV;
4063 }
4064
4065 data = devm_kzalloc(&intf->dev, sizeof(*data), GFP_KERNEL);
4066 if (!data)
4067 return -ENOMEM;
4068
4069 /* If alternate setting 1 is found, it means H4 mode is supported */
4070 if (btusb_find_altsetting(intf, 1)) {
4071 struct usb_device *udev = interface_to_usbdev(intf);
4072
4073 err = usb_set_interface(udev, ifnum_base, 1);
4074 if (!err)
4075 data->proto = BTUSB_PROTO_H4;
4076 }
4077
4078 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
4079 ep_desc = &intf->cur_altsetting->endpoint[i].desc;
4080
4081 if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) {
4082 data->intr_ep = ep_desc;
4083 continue;
4084 }
4085
4086 if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
4087 data->bulk_tx_ep = ep_desc;
4088 continue;
4089 }
4090
4091 if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
4092 data->bulk_rx_ep = ep_desc;
4093 continue;
4094 }
4095 }
4096
4097 /* Check if all endpoints could be enumerated, legacy mode requires
4098 * interrupt and bulk endpoint while H4 mode only requires bulk
4099 * endpoints.
4100 */

> 4101		if ((data->proto == BTUSB_PROTO_LEGACY && !data->intr_ep) ||
  4102		    !data->bulk_tx_ep || !data->bulk_rx_ep) {
  4103			BT_ERR("failed to enumerate endpoints");
  4104			err = -ENODEV;
  4105			goto out_free_dev;
  4106		}
  4107	
  4108		if (id->driver_info & BTUSB_AMP) {
  4109			data->cmdreq_type = USB_TYPE_CLASS | 0x01;
  4110			data->cmdreq = 0x2b;
  4111		} else {
  4112			data->cmdreq_type = USB_TYPE_CLASS;
  4113			data->cmdreq = 0x00;
  4114		}
  4115	
  4116		data->udev = interface_to_usbdev(intf);
  4117		data->intf = intf;
  4118	
  4119		INIT_WORK(&data->work, btusb_work);
  4120		INIT_WORK(&data->waker, btusb_waker);
  4121		INIT_DELAYED_WORK(&data->rx_work, btusb_rx_work);
  4122	
  4123		skb_queue_head_init(&data->acl_q);
  4124	
  4125		init_usb_anchor(&data->deferred);
  4126		init_usb_anchor(&data->tx_anchor);
  4127		spin_lock_init(&data->txlock);
  4128	
  4129		init_usb_anchor(&data->intr_anchor);
  4130		init_usb_anchor(&data->bulk_anchor);
  4131		init_usb_anchor(&data->isoc_anchor);
  4132		init_usb_anchor(&data->diag_anchor);
  4133		init_usb_anchor(&data->ctrl_anchor);
  4134		spin_lock_init(&data->rxlock);
  4135	
  4136		priv_size = 0;
  4137	
  4138		data->recv_event = hci_recv_frame;
  4139		data->recv_bulk = btusb_recv_bulk;
  4140	
  4141		if (id->driver_info & BTUSB_INTEL_COMBINED) {
  4142			/* Allocate extra space for Intel device */
  4143			priv_size += sizeof(struct btintel_data);
  4144	
  4145			/* Override the rx handlers */
  4146			data->recv_event = btintel_recv_event;
  4147			data->recv_bulk = btusb_recv_bulk_intel;
  4148		} else if (id->driver_info & BTUSB_REALTEK) {
  4149			/* Allocate extra space for Realtek device */
  4150			priv_size += sizeof(struct btrealtek_data);
  4151	
  4152			data->recv_event = btusb_recv_event_realtek;
  4153		} else if (id->driver_info & BTUSB_MEDIATEK) {
  4154			/* Allocate extra space for Mediatek device */
  4155			priv_size += sizeof(struct btmtk_data);
  4156		}
  4157	
  4158		data->recv_acl = hci_recv_frame;
  4159	
  4160		hdev = hci_alloc_dev_priv(priv_size);
  4161		if (!hdev)
  4162			return -ENOMEM;
  4163	
  4164		hdev->bus = HCI_USB;
  4165		hci_set_drvdata(hdev, data);
  4166	
  4167		data->hdev = hdev;
  4168	
  4169		SET_HCIDEV_DEV(hdev, &intf->dev);
  4170	
  4171		reset_gpio = gpiod_get_optional(&data->udev->dev, "reset",
  4172						GPIOD_OUT_LOW);
  4173		if (IS_ERR(reset_gpio)) {
  4174			err = PTR_ERR(reset_gpio);
  4175			goto out_free_dev;
  4176		} else if (reset_gpio) {
  4177			data->reset_gpio = reset_gpio;
  4178		}
  4179	
  4180		hdev->open    = btusb_open;
  4181		hdev->close   = btusb_close;
  4182		hdev->flush   = btusb_flush;
  4183		hdev->send    = btusb_send_frame;
  4184		hdev->notify  = btusb_notify;
  4185		hdev->wakeup  = btusb_wakeup;

4186 hdev->hci_drv = &btusb_hci_drv;
4187

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#4 lore raw
In reply to Luiz Augusto von Dentz

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1020010

---Test result---

Test Summary:

CheckPatch                    PENDING   0.36 seconds
GitLint                       PENDING   0.29 seconds
SubjectPrefix                 PASS      0.16 seconds
BuildKernel                   PASS      25.10 seconds
CheckAllWarning               PASS      27.12 seconds
CheckSparse                   PASS      30.76 seconds
BuildKernel32                 PASS      24.24 seconds
TestRunnerSetup               PASS      491.67 seconds
TestRunner_l2cap-tester       PASS      23.48 seconds
TestRunner_iso-tester         PASS      64.17 seconds
TestRunner_bnep-tester        PASS      6.09 seconds
TestRunner_mgmt-tester        FAIL      118.16 seconds
TestRunner_rfcomm-tester      PASS      9.04 seconds
TestRunner_sco-tester         PASS      14.12 seconds
TestRunner_ioctl-tester       PASS      9.84 seconds
TestRunner_mesh-tester        FAIL      11.50 seconds
TestRunner_smp-tester         PASS      8.25 seconds
TestRunner_userchan-tester    PASS      6.41 seconds
IncrementalBuild              PENDING   0.53 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner Output:
Total: 490, Passed: 484 (98.8%), Failed: 2, Not Run: 4

Failed Test Cases

Read Exp Feature - Success                           Failed       0.094 seconds
LL Privacy - Set Flags 1 (Add to RL)                 Failed       0.144 seconds

##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0

Failed Test Cases

Mesh - Send cancel - 1                               Timed out    2.112 seconds
Mesh - Send cancel - 2                               Timed out    1.997 seconds

##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:

---
Regards,
Linux Bluetooth