Skip to content

Commit f60cb30

Browse files
Johan Hedbergholtmann
authored andcommitted
Bluetooth: Convert hci_req_sync family of function to new request API
Now that there's an API in place that allows passing the resulting skb to the request callback we can conveniently convert the hci_req_sync and related functions to use it. Since we still need to get the skb from the async callback into the sleeping _sync() function the patch adds another req_skb variable to hci_dev where the sync request state is tracked. Signed-off-by: Johan Hedberg <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent e621448 commit f60cb30

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

include/net/bluetooth/hci_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ struct hci_dev {
334334
wait_queue_head_t req_wait_q;
335335
__u32 req_status;
336336
__u32 req_result;
337+
struct sk_buff *req_skb;
337338

338339
void *smp_data;
339340
void *smp_bredr_data;

net/bluetooth/hci_core.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,16 @@ static const struct file_operations dut_mode_fops = {
141141

142142
/* ---- HCI requests ---- */
143143

144-
static void hci_req_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode)
144+
static void hci_req_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode,
145+
struct sk_buff *skb)
145146
{
146147
BT_DBG("%s result 0x%2.2x", hdev->name, result);
147148

148149
if (hdev->req_status == HCI_REQ_PEND) {
149150
hdev->req_result = result;
150151
hdev->req_status = HCI_REQ_DONE;
152+
if (skb)
153+
hdev->req_skb = skb_get(skb);
151154
wake_up_interruptible(&hdev->req_wait_q);
152155
}
153156
}
@@ -164,18 +167,10 @@ static void hci_req_cancel(struct hci_dev *hdev, int err)
164167
}
165168

166169
static struct sk_buff *hci_get_cmd_complete(struct hci_dev *hdev, u16 opcode,
167-
u8 event)
170+
u8 event, struct sk_buff *skb)
168171
{
169172
struct hci_ev_cmd_complete *ev;
170173
struct hci_event_hdr *hdr;
171-
struct sk_buff *skb;
172-
173-
hci_dev_lock(hdev);
174-
175-
skb = hdev->recv_evt;
176-
hdev->recv_evt = NULL;
177-
178-
hci_dev_unlock(hdev);
179174

180175
if (!skb)
181176
return ERR_PTR(-ENODATA);
@@ -223,6 +218,7 @@ struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen,
223218
{
224219
DECLARE_WAITQUEUE(wait, current);
225220
struct hci_request req;
221+
struct sk_buff *skb;
226222
int err = 0;
227223

228224
BT_DBG("%s", hdev->name);
@@ -236,7 +232,7 @@ struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen,
236232
add_wait_queue(&hdev->req_wait_q, &wait);
237233
set_current_state(TASK_INTERRUPTIBLE);
238234

239-
err = hci_req_run(&req, hci_req_sync_complete);
235+
err = hci_req_run_skb(&req, hci_req_sync_complete);
240236
if (err < 0) {
241237
remove_wait_queue(&hdev->req_wait_q, &wait);
242238
set_current_state(TASK_RUNNING);
@@ -265,13 +261,17 @@ struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen,
265261
}
266262

267263
hdev->req_status = hdev->req_result = 0;
264+
skb = hdev->req_skb;
265+
hdev->req_skb = NULL;
268266

269267
BT_DBG("%s end: err %d", hdev->name, err);
270268

271-
if (err < 0)
269+
if (err < 0) {
270+
kfree_skb(skb);
272271
return ERR_PTR(err);
272+
}
273273

274-
return hci_get_cmd_complete(hdev, opcode, event);
274+
return hci_get_cmd_complete(hdev, opcode, event, skb);
275275
}
276276
EXPORT_SYMBOL(__hci_cmd_sync_ev);
277277

@@ -303,7 +303,7 @@ static int __hci_req_sync(struct hci_dev *hdev,
303303
add_wait_queue(&hdev->req_wait_q, &wait);
304304
set_current_state(TASK_INTERRUPTIBLE);
305305

306-
err = hci_req_run(&req, hci_req_sync_complete);
306+
err = hci_req_run_skb(&req, hci_req_sync_complete);
307307
if (err < 0) {
308308
hdev->req_status = 0;
309309

0 commit comments

Comments
 (0)