Bluetooth: Track received events in hdev
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / net / bluetooth / hci_event.c
index 8efb9c0d9b2c9b36428324d3f782b052e25fc25a..ed0efb7255b064cb6f520ae9b89925d5e0f71f17 100644 (file)
@@ -48,6 +48,8 @@ static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb)
        }
 
        clear_bit(HCI_INQUIRY, &hdev->flags);
+       smp_mb__after_clear_bit(); /* wake_up_bit advises about this barrier */
+       wake_up_bit(&hdev->flags, HCI_INQUIRY);
 
        hci_dev_lock(hdev);
        hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
@@ -1603,6 +1605,9 @@ static void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
        if (!test_and_clear_bit(HCI_INQUIRY, &hdev->flags))
                return;
 
+       smp_mb__after_clear_bit(); /* wake_up_bit advises about this barrier */
+       wake_up_bit(&hdev->flags, HCI_INQUIRY);
+
        if (!test_bit(HCI_MGMT, &hdev->dev_flags))
                return;
 
@@ -3694,6 +3699,18 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
        struct hci_event_hdr *hdr = (void *) skb->data;
        __u8 event = hdr->evt;
 
+       hci_dev_lock(hdev);
+
+       /* Received events are (currently) only needed when a request is
+        * ongoing so avoid unnecessary memory allocation.
+        */
+       if (hdev->req_status == HCI_REQ_PEND) {
+               kfree_skb(hdev->recv_evt);
+               hdev->recv_evt = skb_clone(skb, GFP_KERNEL);
+       }
+
+       hci_dev_unlock(hdev);
+
        skb_pull(skb, HCI_EVENT_HDR_SIZE);
 
        switch (event) {