Skip to content

Commit 4239144

Browse files
committed
Merge tag 'for-net-2024-06-28' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth into main
bluetooth pull request for net: - Ignore too large handle values in BIG - L2CAP: sync sock recv cb and release - hci_bcm4377: Fix msgid release - ISO: Check socket flag instead of hcon - hci_event: Fix setting of unicast qos interval - hci: disallow setting handle bigger than HCI_CONN_HANDLE_MAX - Add quirk to ignore reserved PHY bits in LE Extended Adv Report - hci_core: cancel all works upon hci_unregister_dev - btintel_pcie: Fix REVERSE_INULL issue reported by coverity - qca: Fix BT enable failure again for QCA6390 after warm reboot Signed-off-by: David S. Miller <[email protected]>
2 parents 66be40e + f1a8f40 commit 4239144

File tree

13 files changed

+131
-71
lines changed

13 files changed

+131
-71
lines changed

drivers/bluetooth/btintel_pcie.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ static int btintel_pcie_recv_frame(struct btintel_pcie_data *data,
382382

383383
/* The first 4 bytes indicates the Intel PCIe specific packet type */
384384
pdata = skb_pull_data(skb, BTINTEL_PCIE_HCI_TYPE_LEN);
385-
if (!data) {
385+
if (!pdata) {
386386
bt_dev_err(hdev, "Corrupted packet received");
387387
ret = -EILSEQ;
388388
goto exit_error;

drivers/bluetooth/btnxpuart.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ static u8 crc8_table[CRC8_TABLE_SIZE];
281281

282282
/* Default configurations */
283283
#define DEFAULT_H2C_WAKEUP_MODE WAKEUP_METHOD_BREAK
284-
#define DEFAULT_PS_MODE PS_MODE_DISABLE
284+
#define DEFAULT_PS_MODE PS_MODE_ENABLE
285285
#define FW_INIT_BAUDRATE HCI_NXP_PRI_BAUDRATE
286286

287287
static struct sk_buff *nxp_drv_send_cmd(struct hci_dev *hdev, u16 opcode,

drivers/bluetooth/hci_bcm4377.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,10 @@ struct bcm4377_data;
495495
* extended scanning
496496
* broken_mws_transport_config: Set to true if the chip erroneously claims to
497497
* support MWS Transport Configuration
498+
* broken_le_ext_adv_report_phy: Set to true if this chip stuffs flags inside
499+
* reserved bits of Primary/Secondary_PHY inside
500+
* LE Extended Advertising Report events which
501+
* have to be ignored
498502
* send_calibration: Optional callback to send calibration data
499503
* send_ptb: Callback to send "PTB" regulatory/calibration data
500504
*/
@@ -513,6 +517,7 @@ struct bcm4377_hw {
513517
unsigned long broken_ext_scan : 1;
514518
unsigned long broken_mws_transport_config : 1;
515519
unsigned long broken_le_coded : 1;
520+
unsigned long broken_le_ext_adv_report_phy : 1;
516521

517522
int (*send_calibration)(struct bcm4377_data *bcm4377);
518523
int (*send_ptb)(struct bcm4377_data *bcm4377,
@@ -716,7 +721,7 @@ static void bcm4377_handle_ack(struct bcm4377_data *bcm4377,
716721
ring->events[msgid] = NULL;
717722
}
718723

719-
bitmap_release_region(ring->msgids, msgid, ring->n_entries);
724+
bitmap_release_region(ring->msgids, msgid, 0);
720725

721726
unlock:
722727
spin_unlock_irqrestore(&ring->lock, flags);
@@ -2373,6 +2378,8 @@ static int bcm4377_probe(struct pci_dev *pdev, const struct pci_device_id *id)
23732378
set_bit(HCI_QUIRK_BROKEN_EXT_SCAN, &hdev->quirks);
23742379
if (bcm4377->hw->broken_le_coded)
23752380
set_bit(HCI_QUIRK_BROKEN_LE_CODED, &hdev->quirks);
2381+
if (bcm4377->hw->broken_le_ext_adv_report_phy)
2382+
set_bit(HCI_QUIRK_FIXUP_LE_EXT_ADV_REPORT_PHY, &hdev->quirks);
23762383

23772384
pci_set_drvdata(pdev, bcm4377);
23782385
hci_set_drvdata(hdev, bcm4377);
@@ -2477,6 +2484,7 @@ static const struct bcm4377_hw bcm4377_hw_variants[] = {
24772484
.clear_pciecfg_subsystem_ctrl_bit19 = true,
24782485
.broken_mws_transport_config = true,
24792486
.broken_le_coded = true,
2487+
.broken_le_ext_adv_report_phy = true,
24802488
.send_calibration = bcm4387_send_calibration,
24812489
.send_ptb = bcm4378_send_ptb,
24822490
},

drivers/bluetooth/hci_qca.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,15 +2450,27 @@ static void qca_serdev_shutdown(struct device *dev)
24502450
struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev);
24512451
struct hci_uart *hu = &qcadev->serdev_hu;
24522452
struct hci_dev *hdev = hu->hdev;
2453-
struct qca_data *qca = hu->priv;
24542453
const u8 ibs_wake_cmd[] = { 0xFD };
24552454
const u8 edl_reset_soc_cmd[] = { 0x01, 0x00, 0xFC, 0x01, 0x05 };
24562455

24572456
if (qcadev->btsoc_type == QCA_QCA6390) {
2458-
if (test_bit(QCA_BT_OFF, &qca->flags) ||
2459-
!test_bit(HCI_RUNNING, &hdev->flags))
2457+
/* The purpose of sending the VSC is to reset SOC into a initial
2458+
* state and the state will ensure next hdev->setup() success.
2459+
* if HCI_QUIRK_NON_PERSISTENT_SETUP is set, it means that
2460+
* hdev->setup() can do its job regardless of SoC state, so
2461+
* don't need to send the VSC.
2462+
* if HCI_SETUP is set, it means that hdev->setup() was never
2463+
* invoked and the SOC is already in the initial state, so
2464+
* don't also need to send the VSC.
2465+
*/
2466+
if (test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks) ||
2467+
hci_dev_test_flag(hdev, HCI_SETUP))
24602468
return;
24612469

2470+
/* The serdev must be in open state when conrol logic arrives
2471+
* here, so also fix the use-after-free issue caused by that
2472+
* the serdev is flushed or wrote after it is closed.
2473+
*/
24622474
serdev_device_write_flush(serdev);
24632475
ret = serdev_device_write_buf(serdev, ibs_wake_cmd,
24642476
sizeof(ibs_wake_cmd));

include/net/bluetooth/hci.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,17 @@ enum {
324324
* claim to support it.
325325
*/
326326
HCI_QUIRK_BROKEN_READ_ENC_KEY_SIZE,
327+
328+
/*
329+
* When this quirk is set, the reserved bits of Primary/Secondary_PHY
330+
* inside the LE Extended Advertising Report events are discarded.
331+
* This is required for some Apple/Broadcom controllers which
332+
* abuse these reserved bits for unrelated flags.
333+
*
334+
* This quirk can be set before hci_register_dev is called or
335+
* during the hdev->setup vendor callback.
336+
*/
337+
HCI_QUIRK_FIXUP_LE_EXT_ADV_REPORT_PHY,
327338
};
328339

329340
/* HCI device flags */

include/net/bluetooth/hci_sync.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ int __hci_cmd_sync_status(struct hci_dev *hdev, u16 opcode, u32 plen,
3838
int __hci_cmd_sync_status_sk(struct hci_dev *hdev, u16 opcode, u32 plen,
3939
const void *param, u8 event, u32 timeout,
4040
struct sock *sk);
41+
int hci_cmd_sync_status(struct hci_dev *hdev, u16 opcode, u32 plen,
42+
const void *param, u32 timeout);
4143

4244
void hci_cmd_sync_init(struct hci_dev *hdev);
4345
void hci_cmd_sync_clear(struct hci_dev *hdev);

net/bluetooth/hci_conn.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,8 @@ static int hci_conn_hash_alloc_unset(struct hci_dev *hdev)
899899
U16_MAX, GFP_ATOMIC);
900900
}
901901

902-
struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
903-
u8 role, u16 handle)
902+
static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
903+
u8 role, u16 handle)
904904
{
905905
struct hci_conn *conn;
906906

@@ -1041,7 +1041,16 @@ struct hci_conn *hci_conn_add_unset(struct hci_dev *hdev, int type,
10411041
if (unlikely(handle < 0))
10421042
return ERR_PTR(-ECONNREFUSED);
10431043

1044-
return hci_conn_add(hdev, type, dst, role, handle);
1044+
return __hci_conn_add(hdev, type, dst, role, handle);
1045+
}
1046+
1047+
struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
1048+
u8 role, u16 handle)
1049+
{
1050+
if (handle > HCI_CONN_HANDLE_MAX)
1051+
return ERR_PTR(-EINVAL);
1052+
1053+
return __hci_conn_add(hdev, type, dst, role, handle);
10451054
}
10461055

10471056
static void hci_conn_cleanup_child(struct hci_conn *conn, u8 reason)

net/bluetooth/hci_core.c

Lines changed: 22 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -63,50 +63,6 @@ DEFINE_MUTEX(hci_cb_list_lock);
6363
/* HCI ID Numbering */
6464
static DEFINE_IDA(hci_index_ida);
6565

66-
static int hci_scan_req(struct hci_request *req, unsigned long opt)
67-
{
68-
__u8 scan = opt;
69-
70-
BT_DBG("%s %x", req->hdev->name, scan);
71-
72-
/* Inquiry and Page scans */
73-
hci_req_add(req, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan);
74-
return 0;
75-
}
76-
77-
static int hci_auth_req(struct hci_request *req, unsigned long opt)
78-
{
79-
__u8 auth = opt;
80-
81-
BT_DBG("%s %x", req->hdev->name, auth);
82-
83-
/* Authentication */
84-
hci_req_add(req, HCI_OP_WRITE_AUTH_ENABLE, 1, &auth);
85-
return 0;
86-
}
87-
88-
static int hci_encrypt_req(struct hci_request *req, unsigned long opt)
89-
{
90-
__u8 encrypt = opt;
91-
92-
BT_DBG("%s %x", req->hdev->name, encrypt);
93-
94-
/* Encryption */
95-
hci_req_add(req, HCI_OP_WRITE_ENCRYPT_MODE, 1, &encrypt);
96-
return 0;
97-
}
98-
99-
static int hci_linkpol_req(struct hci_request *req, unsigned long opt)
100-
{
101-
__le16 policy = cpu_to_le16(opt);
102-
103-
BT_DBG("%s %x", req->hdev->name, policy);
104-
105-
/* Default link policy */
106-
hci_req_add(req, HCI_OP_WRITE_DEF_LINK_POLICY, 2, &policy);
107-
return 0;
108-
}
109-
11066
/* Get HCI device by index.
11167
* Device is held on return. */
11268
struct hci_dev *hci_dev_get(int index)
@@ -735,6 +691,7 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg)
735691
{
736692
struct hci_dev *hdev;
737693
struct hci_dev_req dr;
694+
__le16 policy;
738695
int err = 0;
739696

740697
if (copy_from_user(&dr, arg, sizeof(dr)))
@@ -761,8 +718,8 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg)
761718

762719
switch (cmd) {
763720
case HCISETAUTH:
764-
err = hci_req_sync(hdev, hci_auth_req, dr.dev_opt,
765-
HCI_INIT_TIMEOUT, NULL);
721+
err = __hci_cmd_sync_status(hdev, HCI_OP_WRITE_AUTH_ENABLE,
722+
1, &dr.dev_opt, HCI_CMD_TIMEOUT);
766723
break;
767724

768725
case HCISETENCRYPT:
@@ -773,19 +730,23 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg)
773730

774731
if (!test_bit(HCI_AUTH, &hdev->flags)) {
775732
/* Auth must be enabled first */
776-
err = hci_req_sync(hdev, hci_auth_req, dr.dev_opt,
777-
HCI_INIT_TIMEOUT, NULL);
733+
err = __hci_cmd_sync_status(hdev,
734+
HCI_OP_WRITE_AUTH_ENABLE,
735+
1, &dr.dev_opt,
736+
HCI_CMD_TIMEOUT);
778737
if (err)
779738
break;
780739
}
781740

782-
err = hci_req_sync(hdev, hci_encrypt_req, dr.dev_opt,
783-
HCI_INIT_TIMEOUT, NULL);
741+
err = __hci_cmd_sync_status(hdev, HCI_OP_WRITE_ENCRYPT_MODE,
742+
1, &dr.dev_opt,
743+
HCI_CMD_TIMEOUT);
784744
break;
785745

786746
case HCISETSCAN:
787-
err = hci_req_sync(hdev, hci_scan_req, dr.dev_opt,
788-
HCI_INIT_TIMEOUT, NULL);
747+
err = __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SCAN_ENABLE,
748+
1, &dr.dev_opt,
749+
HCI_CMD_TIMEOUT);
789750

790751
/* Ensure that the connectable and discoverable states
791752
* get correctly modified as this was a non-mgmt change.
@@ -795,8 +756,11 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg)
795756
break;
796757

797758
case HCISETLINKPOL:
798-
err = hci_req_sync(hdev, hci_linkpol_req, dr.dev_opt,
799-
HCI_INIT_TIMEOUT, NULL);
759+
policy = cpu_to_le16(dr.dev_opt);
760+
761+
err = __hci_cmd_sync_status(hdev, HCI_OP_WRITE_DEF_LINK_POLICY,
762+
2, &policy,
763+
HCI_CMD_TIMEOUT);
800764
break;
801765

802766
case HCISETLINKMODE:
@@ -2751,7 +2715,11 @@ void hci_unregister_dev(struct hci_dev *hdev)
27512715
list_del(&hdev->list);
27522716
write_unlock(&hci_dev_list_lock);
27532717

2718+
cancel_work_sync(&hdev->rx_work);
2719+
cancel_work_sync(&hdev->cmd_work);
2720+
cancel_work_sync(&hdev->tx_work);
27542721
cancel_work_sync(&hdev->power_on);
2722+
cancel_work_sync(&hdev->error_reset);
27552723

27562724
hci_cmd_sync_clear(hdev);
27572725

net/bluetooth/hci_event.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6311,6 +6311,13 @@ static void hci_le_ext_adv_report_evt(struct hci_dev *hdev, void *data,
63116311

63126312
evt_type = __le16_to_cpu(info->type) & LE_EXT_ADV_EVT_TYPE_MASK;
63136313
legacy_evt_type = ext_evt_type_to_legacy(hdev, evt_type);
6314+
6315+
if (test_bit(HCI_QUIRK_FIXUP_LE_EXT_ADV_REPORT_PHY,
6316+
&hdev->quirks)) {
6317+
info->primary_phy &= 0x1f;
6318+
info->secondary_phy &= 0x1f;
6319+
}
6320+
63146321
if (legacy_evt_type != LE_ADV_INVALID) {
63156322
process_adv_report(hdev, legacy_evt_type, &info->bdaddr,
63166323
info->bdaddr_type, NULL, 0,
@@ -6660,6 +6667,7 @@ static void hci_le_cis_estabilished_evt(struct hci_dev *hdev, void *data,
66606667
struct bt_iso_qos *qos;
66616668
bool pending = false;
66626669
u16 handle = __le16_to_cpu(ev->handle);
6670+
u32 c_sdu_interval, p_sdu_interval;
66636671

66646672
bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
66656673

@@ -6684,12 +6692,25 @@ static void hci_le_cis_estabilished_evt(struct hci_dev *hdev, void *data,
66846692

66856693
pending = test_and_clear_bit(HCI_CONN_CREATE_CIS, &conn->flags);
66866694

6687-
/* Convert ISO Interval (1.25 ms slots) to SDU Interval (us) */
6688-
qos->ucast.in.interval = le16_to_cpu(ev->interval) * 1250;
6689-
qos->ucast.out.interval = qos->ucast.in.interval;
6695+
/* BLUETOOTH CORE SPECIFICATION Version 5.4 | Vol 6, Part G
6696+
* page 3075:
6697+
* Transport_Latency_C_To_P = CIG_Sync_Delay + (FT_C_To_P) ×
6698+
* ISO_Interval + SDU_Interval_C_To_P
6699+
* ...
6700+
* SDU_Interval = (CIG_Sync_Delay + (FT) x ISO_Interval) -
6701+
* Transport_Latency
6702+
*/
6703+
c_sdu_interval = (get_unaligned_le24(ev->cig_sync_delay) +
6704+
(ev->c_ft * le16_to_cpu(ev->interval) * 1250)) -
6705+
get_unaligned_le24(ev->c_latency);
6706+
p_sdu_interval = (get_unaligned_le24(ev->cig_sync_delay) +
6707+
(ev->p_ft * le16_to_cpu(ev->interval) * 1250)) -
6708+
get_unaligned_le24(ev->p_latency);
66906709

66916710
switch (conn->role) {
66926711
case HCI_ROLE_SLAVE:
6712+
qos->ucast.in.interval = c_sdu_interval;
6713+
qos->ucast.out.interval = p_sdu_interval;
66936714
/* Convert Transport Latency (us) to Latency (msec) */
66946715
qos->ucast.in.latency =
66956716
DIV_ROUND_CLOSEST(get_unaligned_le24(ev->c_latency),
@@ -6703,6 +6724,8 @@ static void hci_le_cis_estabilished_evt(struct hci_dev *hdev, void *data,
67036724
qos->ucast.out.phy = ev->p_phy;
67046725
break;
67056726
case HCI_ROLE_MASTER:
6727+
qos->ucast.in.interval = p_sdu_interval;
6728+
qos->ucast.out.interval = c_sdu_interval;
67066729
/* Convert Transport Latency (us) to Latency (msec) */
67076730
qos->ucast.out.latency =
67086731
DIV_ROUND_CLOSEST(get_unaligned_le24(ev->c_latency),
@@ -6893,6 +6916,10 @@ static void hci_le_big_sync_established_evt(struct hci_dev *hdev, void *data,
68936916

68946917
bis = hci_conn_hash_lookup_handle(hdev, handle);
68956918
if (!bis) {
6919+
if (handle > HCI_CONN_HANDLE_MAX) {
6920+
bt_dev_dbg(hdev, "ignore too large handle %u", handle);
6921+
continue;
6922+
}
68966923
bis = hci_conn_add(hdev, ISO_LINK, BDADDR_ANY,
68976924
HCI_ROLE_SLAVE, handle);
68986925
if (IS_ERR(bis))

net/bluetooth/hci_sync.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,19 @@ int __hci_cmd_sync_status(struct hci_dev *hdev, u16 opcode, u32 plen,
280280
}
281281
EXPORT_SYMBOL(__hci_cmd_sync_status);
282282

283+
int hci_cmd_sync_status(struct hci_dev *hdev, u16 opcode, u32 plen,
284+
const void *param, u32 timeout)
285+
{
286+
int err;
287+
288+
hci_req_sync_lock(hdev);
289+
err = __hci_cmd_sync_status(hdev, opcode, plen, param, timeout);
290+
hci_req_sync_unlock(hdev);
291+
292+
return err;
293+
}
294+
EXPORT_SYMBOL(hci_cmd_sync_status);
295+
283296
static void hci_cmd_sync_work(struct work_struct *work)
284297
{
285298
struct hci_dev *hdev = container_of(work, struct hci_dev, cmd_sync_work);

0 commit comments

Comments
 (0)