Bluetooth: Track received events in hdev
authorJohan Hedberg <johan.hedberg@intel.com>
Tue, 2 Apr 2013 10:34:31 +0000 (13:34 +0300)
committerJohan Hedberg <johan.hedberg@intel.com>
Thu, 4 Apr 2013 16:16:04 +0000 (19:16 +0300)
This patch adds tracking of received HCI events to the hci_dev struct.
This is necessary so that a subsequent patch can implement a function
for sending a single command synchronously and returning the resulting
command complete parameters in the function return value.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
include/net/bluetooth/hci_core.h
net/bluetooth/hci_core.c
net/bluetooth/hci_event.c

index 0e7ee892d7aba678876328457e79c777aeb2a4a8..89eda2ef23809bbad602ddfb7076ec17e72907ba 100644 (file)
@@ -244,6 +244,7 @@ struct hci_dev {
        struct sk_buff_head     raw_q;
        struct sk_buff_head     cmd_q;
 
+       struct sk_buff          *recv_evt;
        struct sk_buff          *sent_cmd;
        struct sk_buff          *reassembly[NUM_REASSEMBLY];
 
index a199d631e31cfd8cc82b0a509e12debf9a0bce2f..7c323bd112ff68e16fbdebeb9184fd038ccc4801 100644 (file)
@@ -1136,6 +1136,9 @@ static int hci_dev_do_close(struct hci_dev *hdev)
                hdev->sent_cmd = NULL;
        }
 
+       kfree_skb(hdev->recv_evt);
+       hdev->recv_evt = NULL;
+
        /* After this point our queues are empty
         * and no tasks are scheduled. */
        hdev->close(hdev);
index 7e7fbca59439cc10be62d15ca65630db66bc6979..ed0efb7255b064cb6f520ae9b89925d5e0f71f17 100644 (file)
@@ -3699,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) {