OSDN Git Service

HID: Use dynamic memory while sending report
authorZhihai Xu <zhihaixu@google.com>
Mon, 21 Apr 2014 19:05:42 +0000 (00:35 +0530)
committerMatthew Xie <mattx@google.com>
Tue, 6 May 2014 08:14:23 +0000 (01:14 -0700)
This patch uses dynamic memory allocation while sending HID output data to
remote device depending on size of data to be sent. Without this patch
fixed size static buffer of 200 bytes was being used for sending data to
remote device, which was resulting in crash in case data size to be sent
to remote device was greater than 200 bytes.

CL from qcom(Hemant Gupta)
Change-Id: Icc8cd4a4ecfd4bc30cbf848a7c865fcf9308ddf8

btif/src/btif_hh.c

index f296c61..5357387 100644 (file)
@@ -1636,11 +1636,18 @@ static bt_status_t set_report (bt_bdaddr_t *bd_addr, bthh_report_type_t reportTy
     }
     else {
         int    hex_bytes_filled;
-        UINT8  hexbuf[200];
+        UINT8  *hexbuf;
         UINT16 len = (strlen(report) + 1) / 2;
 
+        hexbuf = GKI_getbuf(len);
+        if (hexbuf == NULL) {
+            BTIF_TRACE_ERROR2("%s: Error, failed to allocate RPT buffer, len = %d",
+                __FUNCTION__, len);
+            return BT_STATUS_FAIL;
+        }
+
         /* Build a SetReport data buffer */
-        memset(hexbuf, 0, 200);
+        memset(hexbuf, 0, len);
         //TODO
         hex_bytes_filled = ascii_2_hex(report, len, hexbuf);
         BTIF_TRACE_DEBUG1("Hex bytes filled, hex value: %d", hex_bytes_filled);
@@ -1649,11 +1656,15 @@ static bt_status_t set_report (bt_bdaddr_t *bd_addr, bthh_report_type_t reportTy
             if (p_buf == NULL) {
                 BTIF_TRACE_ERROR2("%s: Error, failed to allocate RPT buffer, len = %d",
                                   __FUNCTION__, hex_bytes_filled);
+                GKI_freebuf(hexbuf);
                 return BT_STATUS_FAIL;
             }
             BTA_HhSetReport(p_dev->dev_handle, reportType, p_buf);
+            GKI_freebuf(hexbuf);
+            return BT_STATUS_SUCCESS;
         }
-        return BT_STATUS_SUCCESS;
+        GKI_freebuf(hexbuf);
+        return BT_STATUS_FAIL;
     }
 }