diff options
Diffstat (limited to 'net/bluetooth/hci_conn.c')
-rw-r--r-- | net/bluetooth/hci_conn.c | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 2dda439c8cb8..ec4836f243bc 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c | |||
@@ -137,18 +137,51 @@ static void hci_conn_cleanup(struct hci_conn *conn) | |||
137 | hci_conn_put(conn); | 137 | hci_conn_put(conn); |
138 | } | 138 | } |
139 | 139 | ||
140 | /* This function requires the caller holds hdev->lock */ | 140 | static void le_scan_cleanup(struct work_struct *work) |
141 | static void hci_connect_le_scan_remove(struct hci_conn *conn) | ||
142 | { | 141 | { |
143 | hci_connect_le_scan_cleanup(conn); | 142 | struct hci_conn *conn = container_of(work, struct hci_conn, |
143 | le_scan_cleanup); | ||
144 | struct hci_dev *hdev = conn->hdev; | ||
145 | struct hci_conn *c = NULL; | ||
144 | 146 | ||
145 | /* We can't call hci_conn_del here since that would deadlock | 147 | BT_DBG("%s hcon %p", hdev->name, conn); |
146 | * with trying to call cancel_delayed_work_sync(&conn->disc_work). | 148 | |
147 | * Instead, call just hci_conn_cleanup() which contains the bare | 149 | hci_dev_lock(hdev); |
148 | * minimum cleanup operations needed for a connection in this | 150 | |
149 | * state. | 151 | /* Check that the hci_conn is still around */ |
152 | rcu_read_lock(); | ||
153 | list_for_each_entry_rcu(c, &hdev->conn_hash.list, list) { | ||
154 | if (c == conn) | ||
155 | break; | ||
156 | } | ||
157 | rcu_read_unlock(); | ||
158 | |||
159 | if (c == conn) { | ||
160 | hci_connect_le_scan_cleanup(conn); | ||
161 | hci_conn_cleanup(conn); | ||
162 | } | ||
163 | |||
164 | hci_dev_unlock(hdev); | ||
165 | hci_dev_put(hdev); | ||
166 | hci_conn_put(conn); | ||
167 | } | ||
168 | |||
169 | static void hci_connect_le_scan_remove(struct hci_conn *conn) | ||
170 | { | ||
171 | BT_DBG("%s hcon %p", conn->hdev->name, conn); | ||
172 | |||
173 | /* We can't call hci_conn_del/hci_conn_cleanup here since that | ||
174 | * could deadlock with another hci_conn_del() call that's holding | ||
175 | * hci_dev_lock and doing cancel_delayed_work_sync(&conn->disc_work). | ||
176 | * Instead, grab temporary extra references to the hci_dev and | ||
177 | * hci_conn and perform the necessary cleanup in a separate work | ||
178 | * callback. | ||
150 | */ | 179 | */ |
151 | hci_conn_cleanup(conn); | 180 | |
181 | hci_dev_hold(conn->hdev); | ||
182 | hci_conn_get(conn); | ||
183 | |||
184 | schedule_work(&conn->le_scan_cleanup); | ||
152 | } | 185 | } |
153 | 186 | ||
154 | static void hci_acl_create_connection(struct hci_conn *conn) | 187 | static void hci_acl_create_connection(struct hci_conn *conn) |
@@ -580,6 +613,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst, | |||
580 | INIT_DELAYED_WORK(&conn->auto_accept_work, hci_conn_auto_accept); | 613 | INIT_DELAYED_WORK(&conn->auto_accept_work, hci_conn_auto_accept); |
581 | INIT_DELAYED_WORK(&conn->idle_work, hci_conn_idle); | 614 | INIT_DELAYED_WORK(&conn->idle_work, hci_conn_idle); |
582 | INIT_DELAYED_WORK(&conn->le_conn_timeout, le_conn_timeout); | 615 | INIT_DELAYED_WORK(&conn->le_conn_timeout, le_conn_timeout); |
616 | INIT_WORK(&conn->le_scan_cleanup, le_scan_cleanup); | ||
583 | 617 | ||
584 | atomic_set(&conn->refcnt, 0); | 618 | atomic_set(&conn->refcnt, 0); |
585 | 619 | ||