Bluetooth: Make hci_req_add returning void
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / net / bluetooth / hci_core.c
index 5c64398472868acd2efbed56db78053b168a23e5..1c678757c83a10940c25fb6d8a19279e2e53feeb 100644 (file)
@@ -100,13 +100,16 @@ static int __hci_req_sync(struct hci_dev *hdev,
        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);
@@ -2440,6 +2443,7 @@ void hci_req_init(struct hci_request *req, struct hci_dev *hdev)
 {
        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)
@@ -2450,9 +2454,17 @@ 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;
@@ -2517,7 +2529,7 @@ int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param)
 }
 
 /* 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;
@@ -2526,16 +2538,16 @@ int hci_req_add(struct hci_request *req, u16 opcode, u32 plen, void *param)
 
        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 */