Skip to content

Commit a5d6f7d

Browse files
committed
Merge branch 'for-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth
Johan Hedberg says: ==================== pull request: bluetooth 2015-10-16 First of all, sorry for the late set of patches for the 4.3 cycle. We just finished an intensive week of testing at the Bluetooth UnPlugFest and discovered (and fixed) issues there. Unfortunately a few issues affect 4.3-rc5 in a way that they break existing Bluetooth LE mouse and keyboard support. The regressions result from supporting LE privacy in conjunction with scanning for Resolvable Private Addresses before connecting. A feature that has been tested heavily (including automated unit tests), but sadly some regressions slipped in. The UnPlugFest with its multitude of test platforms is a good battle testing ground for uncovering every corner case. The patches in this pull request focus only on fixing the regressions in 4.3-rc5. The patches look a bit larger since we also added comments in the critical sections of the fixes to improve clarity. I would appreciate if we can get these regression fixes to Linus quickly. Please let me know if there are any issues pulling. Thanks. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 833b8f1 + 5157b8a commit a5d6f7d

File tree

4 files changed

+99
-42
lines changed

4 files changed

+99
-42
lines changed

net/bluetooth/hci_conn.c

Lines changed: 71 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,64 @@ static void hci_connect_le_scan_cleanup(struct hci_conn *conn)
9191
* autoconnect action, remove them completely. If they are, just unmark
9292
* them as waiting for connection, by clearing explicit_connect field.
9393
*/
94-
if (params->auto_connect == HCI_AUTO_CONN_EXPLICIT)
94+
params->explicit_connect = false;
95+
96+
list_del_init(&params->action);
97+
98+
switch (params->auto_connect) {
99+
case HCI_AUTO_CONN_EXPLICIT:
95100
hci_conn_params_del(conn->hdev, bdaddr, bdaddr_type);
96-
else
97-
params->explicit_connect = false;
101+
/* return instead of break to avoid duplicate scan update */
102+
return;
103+
case HCI_AUTO_CONN_DIRECT:
104+
case HCI_AUTO_CONN_ALWAYS:
105+
list_add(&params->action, &conn->hdev->pend_le_conns);
106+
break;
107+
case HCI_AUTO_CONN_REPORT:
108+
list_add(&params->action, &conn->hdev->pend_le_reports);
109+
break;
110+
default:
111+
break;
112+
}
113+
114+
hci_update_background_scan(conn->hdev);
115+
}
116+
117+
static void hci_conn_cleanup(struct hci_conn *conn)
118+
{
119+
struct hci_dev *hdev = conn->hdev;
120+
121+
if (test_bit(HCI_CONN_PARAM_REMOVAL_PEND, &conn->flags))
122+
hci_conn_params_del(conn->hdev, &conn->dst, conn->dst_type);
123+
124+
hci_chan_list_flush(conn);
125+
126+
hci_conn_hash_del(hdev, conn);
127+
128+
if (hdev->notify)
129+
hdev->notify(hdev, HCI_NOTIFY_CONN_DEL);
130+
131+
hci_conn_del_sysfs(conn);
132+
133+
debugfs_remove_recursive(conn->debugfs);
134+
135+
hci_dev_put(hdev);
136+
137+
hci_conn_put(conn);
98138
}
99139

100140
/* This function requires the caller holds hdev->lock */
101141
static void hci_connect_le_scan_remove(struct hci_conn *conn)
102142
{
103143
hci_connect_le_scan_cleanup(conn);
104144

105-
hci_conn_hash_del(conn->hdev, conn);
106-
hci_update_background_scan(conn->hdev);
145+
/* We can't call hci_conn_del here since that would deadlock
146+
* with trying to call cancel_delayed_work_sync(&conn->disc_work).
147+
* Instead, call just hci_conn_cleanup() which contains the bare
148+
* minimum cleanup operations needed for a connection in this
149+
* state.
150+
*/
151+
hci_conn_cleanup(conn);
107152
}
108153

109154
static void hci_acl_create_connection(struct hci_conn *conn)
@@ -581,27 +626,17 @@ int hci_conn_del(struct hci_conn *conn)
581626
}
582627
}
583628

584-
hci_chan_list_flush(conn);
585-
586629
if (conn->amp_mgr)
587630
amp_mgr_put(conn->amp_mgr);
588631

589-
hci_conn_hash_del(hdev, conn);
590-
if (hdev->notify)
591-
hdev->notify(hdev, HCI_NOTIFY_CONN_DEL);
592-
593632
skb_queue_purge(&conn->data_q);
594633

595-
hci_conn_del_sysfs(conn);
596-
597-
debugfs_remove_recursive(conn->debugfs);
598-
599-
if (test_bit(HCI_CONN_PARAM_REMOVAL_PEND, &conn->flags))
600-
hci_conn_params_del(conn->hdev, &conn->dst, conn->dst_type);
601-
602-
hci_dev_put(hdev);
603-
604-
hci_conn_put(conn);
634+
/* Remove the connection from the list and cleanup its remaining
635+
* state. This is a separate function since for some cases like
636+
* BT_CONNECT_SCAN we *only* want the cleanup part without the
637+
* rest of hci_conn_del.
638+
*/
639+
hci_conn_cleanup(conn);
605640

606641
return 0;
607642
}
@@ -973,15 +1008,23 @@ static int hci_explicit_conn_params_set(struct hci_request *req,
9731008
if (is_connected(hdev, addr, addr_type))
9741009
return -EISCONN;
9751010

976-
params = hci_conn_params_add(hdev, addr, addr_type);
977-
if (!params)
978-
return -EIO;
1011+
params = hci_conn_params_lookup(hdev, addr, addr_type);
1012+
if (!params) {
1013+
params = hci_conn_params_add(hdev, addr, addr_type);
1014+
if (!params)
1015+
return -ENOMEM;
9791016

980-
/* If we created new params, or existing params were marked as disabled,
981-
* mark them to be used just once to connect.
982-
*/
983-
if (params->auto_connect == HCI_AUTO_CONN_DISABLED) {
1017+
/* If we created new params, mark them to be deleted in
1018+
* hci_connect_le_scan_cleanup. It's different case than
1019+
* existing disabled params, those will stay after cleanup.
1020+
*/
9841021
params->auto_connect = HCI_AUTO_CONN_EXPLICIT;
1022+
}
1023+
1024+
/* We're trying to connect, so make sure params are at pend_le_conns */
1025+
if (params->auto_connect == HCI_AUTO_CONN_DISABLED ||
1026+
params->auto_connect == HCI_AUTO_CONN_REPORT ||
1027+
params->auto_connect == HCI_AUTO_CONN_EXPLICIT) {
9851028
list_del_init(&params->action);
9861029
list_add(&params->action, &hdev->pend_le_conns);
9871030
}

net/bluetooth/hci_core.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,13 +2861,6 @@ struct hci_conn_params *hci_explicit_connect_lookup(struct hci_dev *hdev,
28612861
return param;
28622862
}
28632863

2864-
list_for_each_entry(param, &hdev->pend_le_reports, action) {
2865-
if (bacmp(&param->addr, addr) == 0 &&
2866-
param->addr_type == addr_type &&
2867-
param->explicit_connect)
2868-
return param;
2869-
}
2870-
28712864
return NULL;
28722865
}
28732866

net/bluetooth/hci_event.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb)
5555
wake_up_bit(&hdev->flags, HCI_INQUIRY);
5656

5757
hci_dev_lock(hdev);
58-
hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
58+
/* Set discovery state to stopped if we're not doing LE active
59+
* scanning.
60+
*/
61+
if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) ||
62+
hdev->le_scan_type != LE_SCAN_ACTIVE)
63+
hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
5964
hci_dev_unlock(hdev);
6065

6166
hci_conn_check_pending(hdev);
@@ -4648,8 +4653,8 @@ static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
46484653
/* If we're not connectable only connect devices that we have in
46494654
* our pend_le_conns list.
46504655
*/
4651-
params = hci_explicit_connect_lookup(hdev, addr, addr_type);
4652-
4656+
params = hci_pend_le_action_lookup(&hdev->pend_le_conns, addr,
4657+
addr_type);
46534658
if (!params)
46544659
return NULL;
46554660

net/bluetooth/mgmt.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3545,6 +3545,7 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
35453545
auth_type);
35463546
} else {
35473547
u8 addr_type;
3548+
struct hci_conn_params *p;
35483549

35493550
/* Convert from L2CAP channel address type to HCI address type
35503551
*/
@@ -3562,7 +3563,10 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
35623563
* If connection parameters already exist, then they
35633564
* will be kept and this function does nothing.
35643565
*/
3565-
hci_conn_params_add(hdev, &cp->addr.bdaddr, addr_type);
3566+
p = hci_conn_params_add(hdev, &cp->addr.bdaddr, addr_type);
3567+
3568+
if (p->auto_connect == HCI_AUTO_CONN_EXPLICIT)
3569+
p->auto_connect = HCI_AUTO_CONN_DISABLED;
35663570

35673571
conn = hci_connect_le_scan(hdev, &cp->addr.bdaddr,
35683572
addr_type, sec_level,
@@ -6117,14 +6121,21 @@ static int hci_conn_params_set(struct hci_request *req, bdaddr_t *addr,
61176121
__hci_update_background_scan(req);
61186122
break;
61196123
case HCI_AUTO_CONN_REPORT:
6120-
list_add(&params->action, &hdev->pend_le_reports);
6124+
if (params->explicit_connect)
6125+
list_add(&params->action, &hdev->pend_le_conns);
6126+
else
6127+
list_add(&params->action, &hdev->pend_le_reports);
61216128
__hci_update_background_scan(req);
61226129
break;
61236130
case HCI_AUTO_CONN_DIRECT:
61246131
case HCI_AUTO_CONN_ALWAYS:
61256132
if (!is_connected(hdev, addr, addr_type)) {
61266133
list_add(&params->action, &hdev->pend_le_conns);
6127-
__hci_update_background_scan(req);
6134+
/* If we are in scan phase of connecting, we were
6135+
* already added to pend_le_conns and scanning.
6136+
*/
6137+
if (params->auto_connect != HCI_AUTO_CONN_EXPLICIT)
6138+
__hci_update_background_scan(req);
61286139
}
61296140
break;
61306141
}
@@ -6379,7 +6390,8 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev,
63796390
goto unlock;
63806391
}
63816392

6382-
if (params->auto_connect == HCI_AUTO_CONN_DISABLED) {
6393+
if (params->auto_connect == HCI_AUTO_CONN_DISABLED ||
6394+
params->auto_connect == HCI_AUTO_CONN_EXPLICIT) {
63836395
err = cmd->cmd_complete(cmd,
63846396
MGMT_STATUS_INVALID_PARAMS);
63856397
mgmt_pending_remove(cmd);
@@ -6415,6 +6427,10 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev,
64156427
if (p->auto_connect == HCI_AUTO_CONN_DISABLED)
64166428
continue;
64176429
device_removed(sk, hdev, &p->addr, p->addr_type);
6430+
if (p->explicit_connect) {
6431+
p->auto_connect = HCI_AUTO_CONN_EXPLICIT;
6432+
continue;
6433+
}
64186434
list_del(&p->action);
64196435
list_del(&p->list);
64206436
kfree(p);

0 commit comments

Comments
 (0)