Skip to content

Commit 9f3956d

Browse files
committed
Merge tag 'for-net-2022-03-03' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth
Luiz Augusto von Dentz says: ==================== bluetooth pull request for net: - Fix regression with processing of MGMT commands - Fix unbalanced unlock in Set Device Flags * tag 'for-net-2022-03-03' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth: Bluetooth: hci_sync: Fix not processing all entries on cmd_sync_work Bluetooth: hci_core: Fix unbalanced unlock in set_device_flags() ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents b949c21 + 008ee9e commit 9f3956d

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

net/bluetooth/hci_sync.c

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -276,40 +276,37 @@ EXPORT_SYMBOL(__hci_cmd_sync_status);
276276
static void hci_cmd_sync_work(struct work_struct *work)
277277
{
278278
struct hci_dev *hdev = container_of(work, struct hci_dev, cmd_sync_work);
279-
struct hci_cmd_sync_work_entry *entry;
280-
hci_cmd_sync_work_func_t func;
281-
hci_cmd_sync_work_destroy_t destroy;
282-
void *data;
283279

284280
bt_dev_dbg(hdev, "");
285281

286-
mutex_lock(&hdev->cmd_sync_work_lock);
287-
entry = list_first_entry(&hdev->cmd_sync_work_list,
288-
struct hci_cmd_sync_work_entry, list);
289-
if (entry) {
290-
list_del(&entry->list);
291-
func = entry->func;
292-
data = entry->data;
293-
destroy = entry->destroy;
294-
kfree(entry);
295-
} else {
296-
func = NULL;
297-
data = NULL;
298-
destroy = NULL;
299-
}
300-
mutex_unlock(&hdev->cmd_sync_work_lock);
282+
/* Dequeue all entries and run them */
283+
while (1) {
284+
struct hci_cmd_sync_work_entry *entry;
301285

302-
if (func) {
303-
int err;
286+
mutex_lock(&hdev->cmd_sync_work_lock);
287+
entry = list_first_entry_or_null(&hdev->cmd_sync_work_list,
288+
struct hci_cmd_sync_work_entry,
289+
list);
290+
if (entry)
291+
list_del(&entry->list);
292+
mutex_unlock(&hdev->cmd_sync_work_lock);
293+
294+
if (!entry)
295+
break;
304296

305-
hci_req_sync_lock(hdev);
297+
bt_dev_dbg(hdev, "entry %p", entry);
306298

307-
err = func(hdev, data);
299+
if (entry->func) {
300+
int err;
308301

309-
if (destroy)
310-
destroy(hdev, data, err);
302+
hci_req_sync_lock(hdev);
303+
err = entry->func(hdev, entry->data);
304+
if (entry->destroy)
305+
entry->destroy(hdev, entry->data, err);
306+
hci_req_sync_unlock(hdev);
307+
}
311308

312-
hci_req_sync_unlock(hdev);
309+
kfree(entry);
313310
}
314311
}
315312

net/bluetooth/mgmt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4541,9 +4541,9 @@ static int set_device_flags(struct sock *sk, struct hci_dev *hdev, void *data,
45414541
}
45424542
}
45434543

4544-
done:
45454544
hci_dev_unlock(hdev);
45464545

4546+
done:
45474547
if (status == MGMT_STATUS_SUCCESS)
45484548
device_flags_changed(sk, hdev, &cp->addr.bdaddr, cp->addr.type,
45494549
supported_flags, current_flags);

0 commit comments

Comments
 (0)