Skip to contentSkip to conversation

Bluetooth: btusb: Add support for Qualcomm multi-subsystem QCC2072

bug report Dan Carpenter 2 participants 6 messages Sep 17 – Sep 19 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

Hello Zijun Hu,

Commit 2e63b55654e0 ("Bluetooth: btusb: Add support for Qualcomm multi-subsystem QCC2072") from Sep 13, 2026 (linux-next), leads to the following Smatch static checker warning:

	drivers/bluetooth/btusb_qcom.c:2516 btqcom_set_bdaddr()
	warn: passing positive error code '(-4095)-(-62),(-60)-(-1),1-255' to 'ERR_PTR'

drivers/bluetooth/btusb_qcom.c

    2507   *
    2508   * Return: 0 on success, or a negative errno on failure.
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    2509   */
    2510 static int btqcom_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
    2511 {
    2512         int ret;
    2513 
    2514         ret = __hci_reset_sync(hdev);
    2515         if (ret) {
--> 2516                 bt_dev_err(hdev, "HCI reset before setting BD_ADDR failed: %pe",
    2517                            ERR_PTR(ret));
    2518                 return ret;

ret comes from skb->data in __hci_cmd_sync_status_sk() so it's a u8 and not necessarily a negative error code.

    2519         }
    2520 
    2521         ret = qbt_write_bda(hdev, bdaddr);
    2522 
    2523         return ret;
    2524 }

This email is a free service from the Smatch-CI project [smatch.sf.net].

regards,
dan carpenter

#1 lore raw
Quoted 9 lines · Dan Carpenter

Hello Zijun Hu,

Commit 2e63b55654e0 ("Bluetooth: btusb: Add support for Qualcomm multi-subsystem QCC2072") from Sep 13, 2026 (linux-next), leads to the following Smatch static checker warning:

	drivers/bluetooth/btusb_qcom.c:2516 btqcom_set_bdaddr()
	warn: passing positive error code '(-4095)-(-62),(-60)-(-1),1-255' to 'ERR_PTR'

See also:

drivers/bluetooth/btusb_qcom.c:2931 btusb_qcom_shutdown_unified() warn: passing positive error code '(-4095)-(-62),(-60)-(-1),1-255' to 'ERR_PTR' drivers/bluetooth/btusb_qcom.c:2947 btusb_qcom_shutdown_unified() warn: passing positive error code '(-4095)-(-62),(-60)-(-1),1-255' to 'ERR_PTR' drivers/bluetooth/btusb_qcom.c:3562 btusb_post_download_unified_bt() warn: passing positive error code '(-4095)-(-62),(-60)-(-1),1-255' to 'ERR_PTR' drivers/bluetooth/btusb_qcom.c:3977 btusb_qcom_setup_unified() warn: passing positive error code '(-4095)-(-62),(-60)-(-1),1-255' to 'ERR_PTR'

regards,
dan carpenter

#2 lore raw
Quoted 6 lines · Dan Carpenter

See also:

drivers/bluetooth/btusb_qcom.c:2931 btusb_qcom_shutdown_unified() warn: passing positive error code '(-4095)-(-62),(-60)-(-1),1-255' to 'ERR_PTR' drivers/bluetooth/btusb_qcom.c:2947 btusb_qcom_shutdown_unified() warn: passing positive error code '(-4095)-(-62),(-60)-(-1),1-255' to 'ERR_PTR' drivers/bluetooth/btusb_qcom.c:3562 btusb_post_download_unified_bt() warn: passing positive error code '(-4095)-(-62),(-60)-(-1),1-255' to 'ERR_PTR' drivers/bluetooth/btusb_qcom.c:3977 btusb_qcom_setup_unified() warn: passing positive error code '(-4095)-(-62),(-60)-(-1),1-255' to 'ERR_PTR'

Thanks for the report.

But All reported cases are false positives: __hci_reset_sync() always returns 0 or a negative errno, *never* a positive value.

#3 lore raw
Quoted 8 lines · Zijun Hu
Quoted 6 lines · Dan Carpenter

See also:

drivers/bluetooth/btusb_qcom.c:2931 btusb_qcom_shutdown_unified() warn: passing positive error code '(-4095)-(-62),(-60)-(-1),1-255' to 'ERR_PTR' drivers/bluetooth/btusb_qcom.c:2947 btusb_qcom_shutdown_unified() warn: passing positive error code '(-4095)-(-62),(-60)-(-1),1-255' to 'ERR_PTR' drivers/bluetooth/btusb_qcom.c:3562 btusb_post_download_unified_bt() warn: passing positive error code '(-4095)-(-62),(-60)-(-1),1-255' to 'ERR_PTR' drivers/bluetooth/btusb_qcom.c:3977 btusb_qcom_setup_unified() warn: passing positive error code '(-4095)-(-62),(-60)-(-1),1-255' to 'ERR_PTR'

Quoted 4 lines

Thanks for the report.

But All reported cases are false positives: __hci_reset_sync() always returns 0 or a negative errno, *never* a positive value.

The return values come from here.

net/bluetooth/hci_sync.c
256 int __hci_cmd_sync_status_sk(struct hci_dev *hdev, u16 opcode, u32 plen,
257 const void *param, u8 event, u32 timeout,
258 struct sock *sk)
259 {
260 struct sk_buff *skb;
261 u8 status;
262
263 skb = __hci_cmd_sync_sk(hdev, opcode, plen, param, event, timeout, sk);
264
265 /* If command return a status event, skb will be set to -ENODATA */
266 if (skb == ERR_PTR(-ENODATA))

   267                  return 0;
                        ^^^^^^^^

Zero, sure.

268
269 if (IS_ERR(skb)) {
270 if (!event)
271 bt_dev_err(hdev, "Opcode 0x%4.4x failed: %ld", opcode,
272 PTR_ERR(skb));

   273                  return PTR_ERR(skb);
                        ^^^^^^^^^^^^^^^^^^^

Error pointer. Fine.

274 }
275
276 status = skb->data[0];
277
278 kfree_skb(skb);
279

   280          return status;
                ^^^^^^^^^^^^^

But this seems like it could be a positive...

281 }

regards,
dan carpenter

#4 lore raw
Quoted 19 lines · Dan Carpenter

Zero, sure.

   268  
   269          if (IS_ERR(skb)) {
   270                  if (!event)
   271                          bt_dev_err(hdev, "Opcode 0x%4.4x failed: %ld", opcode,
   272                                     PTR_ERR(skb));
   273                  return PTR_ERR(skb);
                        ^^^^^^^^^^^^^^^^^^^

Error pointer. Fine.

   274          }
   275  
   276          status = skb->data[0];
   277  
   278          kfree_skb(skb);
   279  
   280          return status;
                ^^^^^^^^^^^^^
Quoted 2 lines

But this seems like it could be a positive...

For HCI_OP_RESET, execution cannot reach this point when status != 0.

Quoted 1 line
   281  }
#5 lore raw
Quoted 23 lines · Zijun Hu
Quoted 19 lines · Dan Carpenter

Zero, sure.

   268  
   269          if (IS_ERR(skb)) {
   270                  if (!event)
   271                          bt_dev_err(hdev, "Opcode 0x%4.4x failed: %ld", opcode,
   272                                     PTR_ERR(skb));
   273                  return PTR_ERR(skb);
                        ^^^^^^^^^^^^^^^^^^^

Error pointer. Fine.

   274          }
   275  
   276          status = skb->data[0];
   277  
   278          kfree_skb(skb);
   279  
   280          return status;
                ^^^^^^^^^^^^^
Quoted 2 lines

But this seems like it could be a positive...

Quoted 3 lines

For HCI_OP_RESET, execution cannot reach this point when status != 0.

Quoted 1 line
   281  }

Actually even for the other opcodes it looks like doing:

	status = skb->data[0];
	return status;

is just a more complicated way to write "return 0;". :/

regards,
dan carpenter