Skip to content

Commit 6730ee8

Browse files
committed
Merge tag 'for-net-2025-01-08' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth
Luiz Augusto von Dentz says: ==================== bluetooth pull request for net: - btmtk: Fix failed to send func ctrl for MediaTek devices. - hci_sync: Fix not setting Random Address when required - MGMT: Fix Add Device to responding before completing - btnxpuart: Fix driver sending truncated data * tag 'for-net-2025-01-08' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth: Bluetooth: btmtk: Fix failed to send func ctrl for MediaTek devices. Bluetooth: btnxpuart: Fix driver sending truncated data Bluetooth: MGMT: Fix Add Device to responding before completing Bluetooth: hci_sync: Fix not setting Random Address when required ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents f552b30 + 67dba2c commit 6730ee8

File tree

5 files changed

+52
-9
lines changed

5 files changed

+52
-9
lines changed

drivers/bluetooth/btmtk.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,10 +1472,15 @@ EXPORT_SYMBOL_GPL(btmtk_usb_setup);
14721472

14731473
int btmtk_usb_shutdown(struct hci_dev *hdev)
14741474
{
1475+
struct btmtk_data *data = hci_get_priv(hdev);
14751476
struct btmtk_hci_wmt_params wmt_params;
14761477
u8 param = 0;
14771478
int err;
14781479

1480+
err = usb_autopm_get_interface(data->intf);
1481+
if (err < 0)
1482+
return err;
1483+
14791484
/* Disable the device */
14801485
wmt_params.op = BTMTK_WMT_FUNC_CTRL;
14811486
wmt_params.flag = 0;
@@ -1486,9 +1491,11 @@ int btmtk_usb_shutdown(struct hci_dev *hdev)
14861491
err = btmtk_usb_hci_wmt_sync(hdev, &wmt_params);
14871492
if (err < 0) {
14881493
bt_dev_err(hdev, "Failed to send wmt func ctrl (%d)", err);
1494+
usb_autopm_put_interface(data->intf);
14891495
return err;
14901496
}
14911497

1498+
usb_autopm_put_interface(data->intf);
14921499
return 0;
14931500
}
14941501
EXPORT_SYMBOL_GPL(btmtk_usb_shutdown);

drivers/bluetooth/btnxpuart.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,7 @@ static void btnxpuart_tx_work(struct work_struct *work)
13811381

13821382
while ((skb = nxp_dequeue(nxpdev))) {
13831383
len = serdev_device_write_buf(serdev, skb->data, skb->len);
1384+
serdev_device_wait_until_sent(serdev, 0);
13841385
hdev->stat.byte_tx += len;
13851386

13861387
skb_pull(skb, len);

net/bluetooth/hci_sync.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,18 +1031,19 @@ static bool adv_use_rpa(struct hci_dev *hdev, uint32_t flags)
10311031

10321032
static int hci_set_random_addr_sync(struct hci_dev *hdev, bdaddr_t *rpa)
10331033
{
1034-
/* If we're advertising or initiating an LE connection we can't
1035-
* go ahead and change the random address at this time. This is
1036-
* because the eventual initiator address used for the
1034+
/* If a random_addr has been set we're advertising or initiating an LE
1035+
* connection we can't go ahead and change the random address at this
1036+
* time. This is because the eventual initiator address used for the
10371037
* subsequently created connection will be undefined (some
10381038
* controllers use the new address and others the one we had
10391039
* when the operation started).
10401040
*
10411041
* In this kind of scenario skip the update and let the random
10421042
* address be updated at the next cycle.
10431043
*/
1044-
if (hci_dev_test_flag(hdev, HCI_LE_ADV) ||
1045-
hci_lookup_le_connect(hdev)) {
1044+
if (bacmp(&hdev->random_addr, BDADDR_ANY) &&
1045+
(hci_dev_test_flag(hdev, HCI_LE_ADV) ||
1046+
hci_lookup_le_connect(hdev))) {
10461047
bt_dev_dbg(hdev, "Deferring random address update");
10471048
hci_dev_set_flag(hdev, HCI_RPA_EXPIRED);
10481049
return 0;

net/bluetooth/mgmt.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7655,6 +7655,24 @@ static void device_added(struct sock *sk, struct hci_dev *hdev,
76557655
mgmt_event(MGMT_EV_DEVICE_ADDED, hdev, &ev, sizeof(ev), sk);
76567656
}
76577657

7658+
static void add_device_complete(struct hci_dev *hdev, void *data, int err)
7659+
{
7660+
struct mgmt_pending_cmd *cmd = data;
7661+
struct mgmt_cp_add_device *cp = cmd->param;
7662+
7663+
if (!err) {
7664+
device_added(cmd->sk, hdev, &cp->addr.bdaddr, cp->addr.type,
7665+
cp->action);
7666+
device_flags_changed(NULL, hdev, &cp->addr.bdaddr,
7667+
cp->addr.type, hdev->conn_flags,
7668+
PTR_UINT(cmd->user_data));
7669+
}
7670+
7671+
mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_ADD_DEVICE,
7672+
mgmt_status(err), &cp->addr, sizeof(cp->addr));
7673+
mgmt_pending_free(cmd);
7674+
}
7675+
76587676
static int add_device_sync(struct hci_dev *hdev, void *data)
76597677
{
76607678
return hci_update_passive_scan_sync(hdev);
@@ -7663,6 +7681,7 @@ static int add_device_sync(struct hci_dev *hdev, void *data)
76637681
static int add_device(struct sock *sk, struct hci_dev *hdev,
76647682
void *data, u16 len)
76657683
{
7684+
struct mgmt_pending_cmd *cmd;
76667685
struct mgmt_cp_add_device *cp = data;
76677686
u8 auto_conn, addr_type;
76687687
struct hci_conn_params *params;
@@ -7743,9 +7762,24 @@ static int add_device(struct sock *sk, struct hci_dev *hdev,
77437762
current_flags = params->flags;
77447763
}
77457764

7746-
err = hci_cmd_sync_queue(hdev, add_device_sync, NULL, NULL);
7747-
if (err < 0)
7765+
cmd = mgmt_pending_new(sk, MGMT_OP_ADD_DEVICE, hdev, data, len);
7766+
if (!cmd) {
7767+
err = -ENOMEM;
77487768
goto unlock;
7769+
}
7770+
7771+
cmd->user_data = UINT_PTR(current_flags);
7772+
7773+
err = hci_cmd_sync_queue(hdev, add_device_sync, cmd,
7774+
add_device_complete);
7775+
if (err < 0) {
7776+
err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE,
7777+
MGMT_STATUS_FAILED, &cp->addr,
7778+
sizeof(cp->addr));
7779+
mgmt_pending_free(cmd);
7780+
}
7781+
7782+
goto unlock;
77497783

77507784
added:
77517785
device_added(sk, hdev, &cp->addr.bdaddr, cp->addr.type, cp->action);

net/bluetooth/rfcomm/tty.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,14 @@ static ssize_t address_show(struct device *tty_dev,
201201
struct device_attribute *attr, char *buf)
202202
{
203203
struct rfcomm_dev *dev = dev_get_drvdata(tty_dev);
204-
return sprintf(buf, "%pMR\n", &dev->dst);
204+
return sysfs_emit(buf, "%pMR\n", &dev->dst);
205205
}
206206

207207
static ssize_t channel_show(struct device *tty_dev,
208208
struct device_attribute *attr, char *buf)
209209
{
210210
struct rfcomm_dev *dev = dev_get_drvdata(tty_dev);
211-
return sprintf(buf, "%d\n", dev->channel);
211+
return sysfs_emit(buf, "%d\n", dev->channel);
212212
}
213213

214214
static DEVICE_ATTR_RO(address);

0 commit comments

Comments
 (0)