Skip to content

Commit a182d9c

Browse files
committed
Bluetooth: MGMT: Fix Add Device to responding before completing
Add Device with LE type requires updating resolving/accept list which requires quite a number of commands to complete and each of them may fail, so instead of pretending it would always work this checks the return of hci_update_passive_scan_sync which indicates if everything worked as intended. Fixes: e8907f7 ("Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 3") Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent c2994b0 commit a182d9c

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

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);

0 commit comments

Comments
 (0)