You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/07/08 02:52:06 UTC

incubator-mynewt-core git commit: NimBLE - Host frees HCI cmd buf on ev alloc fail.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 9b008aa84 -> 53d7e653b


NimBLE - Host frees HCI cmd buf on ev alloc fail.

Old behavior: when ble_hci_transport_host_cmd_send() failed to allocate
an event for the HCI command, it tried to free the command buffer to the
g_hci_cmd_pool pool.  This became a problem when the host started using
a single statically-allocated buffer for all of its HCI commands.

New behavior: ble_hci_transport_host_cmd_send() doesn't free the buffer
on failure.  Instead, it is up to the caller to check the return code
and free the buffer on failure.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/53d7e653
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/53d7e653
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/53d7e653

Branch: refs/heads/develop
Commit: 53d7e653b9239f1f17e99e7d757dad8b74c805a4
Parents: 9b008aa
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jul 7 19:49:33 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Jul 7 19:49:33 2016 -0700

----------------------------------------------------------------------
 apps/blehci/src/main.c                 |  7 ++++++-
 net/nimble/controller/src/ble_ll_hci.c | 10 +++++++---
 2 files changed, 13 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/53d7e653/apps/blehci/src/main.c
----------------------------------------------------------------------
diff --git a/apps/blehci/src/main.c b/apps/blehci/src/main.c
index ca2e39d..f0736b7 100755
--- a/apps/blehci/src/main.c
+++ b/apps/blehci/src/main.c
@@ -263,6 +263,8 @@ uart_rx_pkt_type(uint8_t data)
 static int
 uart_rx_cmd(uint8_t data)
 {
+    int rc;
+
     hci.tx_cmd.data[hci.tx_cmd.cur++] = data;
 
     if (hci.tx_cmd.cur < HCI_CMD_HDR_LEN) {
@@ -272,7 +274,10 @@ uart_rx_cmd(uint8_t data)
     }
 
     if (hci.tx_cmd.cur == hci.tx_cmd.len) {
-        ble_hci_transport_host_cmd_send(hci.tx_cmd.data);
+        rc = ble_hci_transport_host_cmd_send(hci.tx_cmd.data);
+        if (rc != 0) {
+            os_memblock_put(&g_hci_cmd_pool, hci.tx_cmd.data);
+        }
         hci.tx_type = H4_NONE;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/53d7e653/net/nimble/controller/src/ble_ll_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_hci.c b/net/nimble/controller/src/ble_ll_hci.c
index a17515f..1d73465 100644
--- a/net/nimble/controller/src/ble_ll_hci.c
+++ b/net/nimble/controller/src/ble_ll_hci.c
@@ -983,20 +983,24 @@ ble_ll_hci_cmd_proc(struct os_event *ev)
 }
 
 /**
+ * Sends an HCI command to the controller.  On success, the supplied buffer is
+ * relinquished to the controller task.  On failure, the caller must free the
+ * buffer.
+ *
+ * @param cmd                   A flat buffer containing the HCI command to
+ *                                  send.
+ *
  * @return                      0 on success;
  *                              BLE_ERR_MEM_CAPACITY on HCI buffer exhaustion.
  */
 int
 ble_hci_transport_host_cmd_send(uint8_t *cmd)
 {
-    os_error_t err;
     struct os_event *ev;
 
     /* Get an event structure off the queue */
     ev = (struct os_event *)os_memblock_get(&g_hci_os_event_pool);
     if (!ev) {
-        err = os_memblock_put(&g_hci_cmd_pool, cmd);
-        assert(err == OS_OK);
         return BLE_ERR_MEM_CAPACITY;
     }