Skip to content

Commit 09fd0de

Browse files
author
Gustavo F. Padovan
committed
Bluetooth: Replace spin_lock by mutex in hci_dev
Now we run everything in HCI in process context, so it's a better idea use mutex instead spin_lock. The macro remains hci_dev_lock() (and I got rid of hci_dev_lock_bh()), of course. Acked-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
1 parent b78752c commit 09fd0de

9 files changed

Lines changed: 100 additions & 102 deletions

File tree

‎include/net/bluetooth/hci_core.h‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ struct adv_entry {
117117
#define NUM_REASSEMBLY 4
118118
struct hci_dev {
119119
struct list_head list;
120-
spinlock_t lock;
120+
struct mutex lock;
121121
atomic_t refcnt;
122122

123123
char name[8];
@@ -566,10 +566,8 @@ static inline struct hci_dev *hci_dev_hold(struct hci_dev *d)
566566
return NULL;
567567
}
568568

569-
#define hci_dev_lock(d) spin_lock(&d->lock)
570-
#define hci_dev_unlock(d) spin_unlock(&d->lock)
571-
#define hci_dev_lock_bh(d) spin_lock_bh(&d->lock)
572-
#define hci_dev_unlock_bh(d) spin_unlock_bh(&d->lock)
569+
#define hci_dev_lock(d) mutex_lock(&d->lock)
570+
#define hci_dev_unlock(d) mutex_unlock(&d->lock)
573571

574572
struct hci_dev *hci_dev_get(int index);
575573
struct hci_dev *hci_get_route(bdaddr_t *src, bdaddr_t *dst);

‎net/bluetooth/hci_conn.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ int hci_get_conn_list(void __user *arg)
876876

877877
ci = cl->conn_info;
878878

879-
hci_dev_lock_bh(hdev);
879+
hci_dev_lock(hdev);
880880
list_for_each_entry(c, &hdev->conn_hash.list, list) {
881881
bacpy(&(ci + n)->bdaddr, &c->dst);
882882
(ci + n)->handle = c->handle;
@@ -887,7 +887,7 @@ int hci_get_conn_list(void __user *arg)
887887
if (++n >= req.conn_num)
888888
break;
889889
}
890-
hci_dev_unlock_bh(hdev);
890+
hci_dev_unlock(hdev);
891891

892892
cl->dev_id = hdev->id;
893893
cl->conn_num = n;
@@ -911,7 +911,7 @@ int hci_get_conn_info(struct hci_dev *hdev, void __user *arg)
911911
if (copy_from_user(&req, arg, sizeof(req)))
912912
return -EFAULT;
913913

914-
hci_dev_lock_bh(hdev);
914+
hci_dev_lock(hdev);
915915
conn = hci_conn_hash_lookup_ba(hdev, req.type, &req.bdaddr);
916916
if (conn) {
917917
bacpy(&ci.bdaddr, &conn->dst);
@@ -921,7 +921,7 @@ int hci_get_conn_info(struct hci_dev *hdev, void __user *arg)
921921
ci.state = conn->state;
922922
ci.link_mode = conn->link_mode;
923923
}
924-
hci_dev_unlock_bh(hdev);
924+
hci_dev_unlock(hdev);
925925

926926
if (!conn)
927927
return -ENOENT;
@@ -937,11 +937,11 @@ int hci_get_auth_info(struct hci_dev *hdev, void __user *arg)
937937
if (copy_from_user(&req, arg, sizeof(req)))
938938
return -EFAULT;
939939

940-
hci_dev_lock_bh(hdev);
940+
hci_dev_lock(hdev);
941941
conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &req.bdaddr);
942942
if (conn)
943943
req.type = conn->auth_type;
944-
hci_dev_unlock_bh(hdev);
944+
hci_dev_unlock(hdev);
945945

946946
if (!conn)
947947
return -ENOENT;

‎net/bluetooth/hci_core.c‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -433,14 +433,14 @@ int hci_inquiry(void __user *arg)
433433
if (!hdev)
434434
return -ENODEV;
435435

436-
hci_dev_lock_bh(hdev);
436+
hci_dev_lock(hdev);
437437
if (inquiry_cache_age(hdev) > INQUIRY_CACHE_AGE_MAX ||
438438
inquiry_cache_empty(hdev) ||
439439
ir.flags & IREQ_CACHE_FLUSH) {
440440
inquiry_cache_flush(hdev);
441441
do_inquiry = 1;
442442
}
443-
hci_dev_unlock_bh(hdev);
443+
hci_dev_unlock(hdev);
444444

445445
timeo = ir.length * msecs_to_jiffies(2000);
446446

@@ -462,9 +462,9 @@ int hci_inquiry(void __user *arg)
462462
goto done;
463463
}
464464

465-
hci_dev_lock_bh(hdev);
465+
hci_dev_lock(hdev);
466466
ir.num_rsp = inquiry_cache_dump(hdev, max_rsp, buf);
467-
hci_dev_unlock_bh(hdev);
467+
hci_dev_unlock(hdev);
468468

469469
BT_DBG("num_rsp %d", ir.num_rsp);
470470

@@ -541,9 +541,9 @@ int hci_dev_open(__u16 dev)
541541
set_bit(HCI_UP, &hdev->flags);
542542
hci_notify(hdev, HCI_DEV_UP);
543543
if (!test_bit(HCI_SETUP, &hdev->flags)) {
544-
hci_dev_lock_bh(hdev);
544+
hci_dev_lock(hdev);
545545
mgmt_powered(hdev, 1);
546-
hci_dev_unlock_bh(hdev);
546+
hci_dev_unlock(hdev);
547547
}
548548
} else {
549549
/* Init failed, cleanup */
@@ -597,10 +597,10 @@ static int hci_dev_do_close(struct hci_dev *hdev)
597597
if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->flags))
598598
cancel_delayed_work(&hdev->power_off);
599599

600-
hci_dev_lock_bh(hdev);
600+
hci_dev_lock(hdev);
601601
inquiry_cache_flush(hdev);
602602
hci_conn_hash_flush(hdev);
603-
hci_dev_unlock_bh(hdev);
603+
hci_dev_unlock(hdev);
604604

605605
hci_notify(hdev, HCI_DEV_DOWN);
606606

@@ -636,9 +636,9 @@ static int hci_dev_do_close(struct hci_dev *hdev)
636636
* and no tasks are scheduled. */
637637
hdev->close(hdev);
638638

639-
hci_dev_lock_bh(hdev);
639+
hci_dev_lock(hdev);
640640
mgmt_powered(hdev, 0);
641-
hci_dev_unlock_bh(hdev);
641+
hci_dev_unlock(hdev);
642642

643643
/* Clear flags */
644644
hdev->flags = 0;
@@ -681,10 +681,10 @@ int hci_dev_reset(__u16 dev)
681681
skb_queue_purge(&hdev->rx_q);
682682
skb_queue_purge(&hdev->cmd_q);
683683

684-
hci_dev_lock_bh(hdev);
684+
hci_dev_lock(hdev);
685685
inquiry_cache_flush(hdev);
686686
hci_conn_hash_flush(hdev);
687-
hci_dev_unlock_bh(hdev);
687+
hci_dev_unlock(hdev);
688688

689689
if (hdev->flush)
690690
hdev->flush(hdev);
@@ -967,13 +967,13 @@ static void hci_discov_off(struct work_struct *work)
967967

968968
BT_DBG("%s", hdev->name);
969969

970-
hci_dev_lock_bh(hdev);
970+
hci_dev_lock(hdev);
971971

972972
hci_send_cmd(hdev, HCI_OP_WRITE_SCAN_ENABLE, sizeof(scan), &scan);
973973

974974
hdev->discov_timeout = 0;
975975

976-
hci_dev_unlock_bh(hdev);
976+
hci_dev_unlock(hdev);
977977
}
978978

979979
int hci_uuids_clear(struct hci_dev *hdev)
@@ -1443,7 +1443,7 @@ int hci_register_dev(struct hci_dev *hdev)
14431443
list_add_tail(&hdev->list, head);
14441444

14451445
atomic_set(&hdev->refcnt, 1);
1446-
spin_lock_init(&hdev->lock);
1446+
mutex_init(&hdev->lock);
14471447

14481448
hdev->flags = 0;
14491449
hdev->dev_flags = 0;
@@ -1558,9 +1558,9 @@ void hci_unregister_dev(struct hci_dev *hdev)
15581558

15591559
if (!test_bit(HCI_INIT, &hdev->flags) &&
15601560
!test_bit(HCI_SETUP, &hdev->flags)) {
1561-
hci_dev_lock_bh(hdev);
1561+
hci_dev_lock(hdev);
15621562
mgmt_index_removed(hdev);
1563-
hci_dev_unlock_bh(hdev);
1563+
hci_dev_unlock(hdev);
15641564
}
15651565

15661566
/* mgmt_index_removed should take care of emptying the
@@ -1580,13 +1580,13 @@ void hci_unregister_dev(struct hci_dev *hdev)
15801580

15811581
destroy_workqueue(hdev->workqueue);
15821582

1583-
hci_dev_lock_bh(hdev);
1583+
hci_dev_lock(hdev);
15841584
hci_blacklist_clear(hdev);
15851585
hci_uuids_clear(hdev);
15861586
hci_link_keys_clear(hdev);
15871587
hci_remote_oob_data_clear(hdev);
15881588
hci_adv_entries_clear(hdev);
1589-
hci_dev_unlock_bh(hdev);
1589+
hci_dev_unlock(hdev);
15901590

15911591
__hci_dev_put(hdev);
15921592
}

‎net/bluetooth/hci_sock.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ static int hci_sock_blacklist_add(struct hci_dev *hdev, void __user *arg)
188188
if (copy_from_user(&bdaddr, arg, sizeof(bdaddr)))
189189
return -EFAULT;
190190

191-
hci_dev_lock_bh(hdev);
191+
hci_dev_lock(hdev);
192192

193193
err = hci_blacklist_add(hdev, &bdaddr);
194194

195-
hci_dev_unlock_bh(hdev);
195+
hci_dev_unlock(hdev);
196196

197197
return err;
198198
}
@@ -205,11 +205,11 @@ static int hci_sock_blacklist_del(struct hci_dev *hdev, void __user *arg)
205205
if (copy_from_user(&bdaddr, arg, sizeof(bdaddr)))
206206
return -EFAULT;
207207

208-
hci_dev_lock_bh(hdev);
208+
hci_dev_lock(hdev);
209209

210210
err = hci_blacklist_del(hdev, &bdaddr);
211211

212-
hci_dev_unlock_bh(hdev);
212+
hci_dev_unlock(hdev);
213213

214214
return err;
215215
}

‎net/bluetooth/hci_sysfs.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ static int inquiry_cache_show(struct seq_file *f, void *p)
402402
struct inquiry_cache *cache = &hdev->inq_cache;
403403
struct inquiry_entry *e;
404404

405-
hci_dev_lock_bh(hdev);
405+
hci_dev_lock(hdev);
406406

407407
for (e = cache->list; e; e = e->next) {
408408
struct inquiry_data *data = &e->data;
@@ -415,7 +415,7 @@ static int inquiry_cache_show(struct seq_file *f, void *p)
415415
data->rssi, data->ssp_mode, e->timestamp);
416416
}
417417

418-
hci_dev_unlock_bh(hdev);
418+
hci_dev_unlock(hdev);
419419

420420
return 0;
421421
}
@@ -437,12 +437,12 @@ static int blacklist_show(struct seq_file *f, void *p)
437437
struct hci_dev *hdev = f->private;
438438
struct bdaddr_list *b;
439439

440-
hci_dev_lock_bh(hdev);
440+
hci_dev_lock(hdev);
441441

442442
list_for_each_entry(b, &hdev->blacklist, list)
443443
seq_printf(f, "%s\n", batostr(&b->bdaddr));
444444

445-
hci_dev_unlock_bh(hdev);
445+
hci_dev_unlock(hdev);
446446

447447
return 0;
448448
}
@@ -481,12 +481,12 @@ static int uuids_show(struct seq_file *f, void *p)
481481
struct hci_dev *hdev = f->private;
482482
struct bt_uuid *uuid;
483483

484-
hci_dev_lock_bh(hdev);
484+
hci_dev_lock(hdev);
485485

486486
list_for_each_entry(uuid, &hdev->uuids, list)
487487
print_bt_uuid(f, uuid->uuid);
488488

489-
hci_dev_unlock_bh(hdev);
489+
hci_dev_unlock(hdev);
490490

491491
return 0;
492492
}
@@ -507,11 +507,11 @@ static int auto_accept_delay_set(void *data, u64 val)
507507
{
508508
struct hci_dev *hdev = data;
509509

510-
hci_dev_lock_bh(hdev);
510+
hci_dev_lock(hdev);
511511

512512
hdev->auto_accept_delay = val;
513513

514-
hci_dev_unlock_bh(hdev);
514+
hci_dev_unlock(hdev);
515515

516516
return 0;
517517
}
@@ -520,11 +520,11 @@ static int auto_accept_delay_get(void *data, u64 *val)
520520
{
521521
struct hci_dev *hdev = data;
522522

523-
hci_dev_lock_bh(hdev);
523+
hci_dev_lock(hdev);
524524

525525
*val = hdev->auto_accept_delay;
526526

527-
hci_dev_unlock_bh(hdev);
527+
hci_dev_unlock(hdev);
528528

529529
return 0;
530530
}

‎net/bluetooth/hidp/core.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,11 +795,11 @@ static struct hci_conn *hidp_get_connection(struct hidp_session *session)
795795
if (!hdev)
796796
return NULL;
797797

798-
hci_dev_lock_bh(hdev);
798+
hci_dev_lock(hdev);
799799
conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst);
800800
if (conn)
801801
hci_conn_hold_device(conn);
802-
hci_dev_unlock_bh(hdev);
802+
hci_dev_unlock(hdev);
803803

804804
hci_dev_put(hdev);
805805

‎net/bluetooth/l2cap_core.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan)
11711171
if (!hdev)
11721172
return -EHOSTUNREACH;
11731173

1174-
hci_dev_lock_bh(hdev);
1174+
hci_dev_lock(hdev);
11751175

11761176
auth_type = l2cap_get_auth_type(chan);
11771177

@@ -1214,7 +1214,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan)
12141214
err = 0;
12151215

12161216
done:
1217-
hci_dev_unlock_bh(hdev);
1217+
hci_dev_unlock(hdev);
12181218
hci_dev_put(hdev);
12191219
return err;
12201220
}

0 commit comments

Comments
 (0)