[PATCH 08/13] android/hidhost: Use stack buffer in bt_hid_get_report

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Request size can be up to 4 bytes and this can be easily put on stack.
---
 android/hidhost.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/android/hidhost.c b/android/hidhost.c
index 5b98152..b94d284 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -958,8 +958,8 @@ static void bt_hid_get_report(const void *buf, uint16_t len)
 	GSList *l;
 	bdaddr_t dst;
 	int fd;
-	uint8_t *req;
-	uint8_t req_size;
+	uint8_t req[4];
+	uint8_t req_size = 2;
 
 	DBG("");
 
@@ -972,12 +972,6 @@ static void bt_hid_get_report(const void *buf, uint16_t len)
 	}
 
 	dev = l->data;
-	req_size = (cmd->buf_size > 0) ? 4 : 2;
-	req = g_try_malloc0(req_size);
-	if (!req) {
-		status = HAL_STATUS_NOMEM;
-		goto fail;
-	}
 
 	req[0] = HID_MSG_GET_REPORT | cmd->type;
 	req[1] = cmd->id;
@@ -985,6 +979,7 @@ static void bt_hid_get_report(const void *buf, uint16_t len)
 	if (cmd->buf_size > 0) {
 		req[0] = req[0] | HID_GET_REPORT_SIZE_FIELD;
 		bt_put_le16(cmd->buf_size, &req[2]);
+		req_size += sizeof(uint16_t);
 	}
 
 	fd = g_io_channel_unix_get_fd(dev->ctrl_io);
@@ -992,13 +987,11 @@ static void bt_hid_get_report(const void *buf, uint16_t len)
 	if (write(fd, req, req_size) < 0) {
 		error("error writing hid_get_report: %s (%d)",
 						strerror(errno), errno);
-		g_free(req);
 		status = HAL_STATUS_FAILED;
 		goto fail;
 	}
 
 	dev->last_hid_msg = HID_MSG_GET_REPORT;
-	g_free(req);
 
 fail:
 	ipc_send_rsp(command_sk, HAL_SERVICE_ID_HIDHOST,
-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux