err = hci_req_run(&req, hci_req_sync_complete);
if (err < 0) {
hdev->req_status = 0;
- /* req_run will fail if the request did not add any
- * commands to the queue, something that can happen when
- * a request with conditionals doesn't trigger any
- * commands to be sent. This is normal behavior and
- * should not trigger an error return.
+
+ /* ENODATA means the HCI request command queue is empty.
+ * This can happen when a request with conditionals doesn't
+ * trigger any commands to be sent. This is normal behavior
+ * and should not trigger an error return.
*/
- return 0;
+ if (err == -ENODATA)
+ return 0;
+
+ return err;
}
add_wait_queue(&hdev->req_wait_q, &wait);
{
skb_queue_head_init(&req->cmd_q);
req->hdev = hdev;
+ req->err = 0;
}
int hci_req_run(struct hci_request *req, hci_req_complete_t complete)
BT_DBG("length %u", skb_queue_len(&req->cmd_q));
+ /* If an error occured during request building, remove all HCI
+ * commands queued on the HCI request queue.
+ */
+ if (req->err) {
+ skb_queue_purge(&req->cmd_q);
+ return req->err;
+ }
+
/* Do not allow empty requests */
if (skb_queue_empty(&req->cmd_q))
- return -EINVAL;
+ return -ENODATA;
skb = skb_peek_tail(&req->cmd_q);
bt_cb(skb)->req.complete = complete;
}
/* Queue a command to an asynchronous HCI request */
-int hci_req_add(struct hci_request *req, u16 opcode, u32 plen, void *param)
+void hci_req_add(struct hci_request *req, u16 opcode, u32 plen, void *param)
{
struct hci_dev *hdev = req->hdev;
struct sk_buff *skb;
skb = hci_prepare_cmd(hdev, opcode, plen, param);
if (!skb) {
- BT_ERR("%s no memory for command", hdev->name);
- return -ENOMEM;
+ BT_ERR("%s no memory for command (opcode 0x%4.4x)",
+ hdev->name, opcode);
+ req->err = -ENOMEM;
+ return;
}
if (skb_queue_empty(&req->cmd_q))
bt_cb(skb)->req.start = true;
skb_queue_tail(&req->cmd_q, skb);
-
- return 0;
}
/* Get data from the previously sent command */