summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPuthikorn Voravootivat <puthik@chromium.org>2014-09-19 15:38:04 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-09-23 00:05:03 +0000
commitbe0bd9b83538427cc350ad38d64b821dfcad82a0 (patch)
tree8d379fe9f7df10c25269f8309e0cb94570fd2d6b
parent23ad46d3b8b9bce7f122abb4356e2c09b5dfc0c6 (diff)
downloadchrome-ec-be0bd9b83538427cc350ad38d64b821dfcad82a0.tar.gz
ectool: Do not increase buffer size after probe max size from ec
During the communication init, ectool will probe max request and response packet size from ec and set packet size accordind to that. However, with older kernel's ec driver, the buffer allocated by kernel is not large enough and this will cause kernel bug. BUG=chrome-os-partner:31989 TEST=ectool version runs fine on blaze BRANCH=ToT Change-Id: I499a5305c8fa8b0fd6f3be8554c9cf066b7e0828 Signed-off-by: Puthikorn Voravootivat <puthik@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/219114 Reviewed-by: Mohammed Habibulla <moch@chromium.org>
-rw-r--r--util/comm-host.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/util/comm-host.c b/util/comm-host.c
index 7da86316fb..b5cd51adfe 100644
--- a/util/comm-host.c
+++ b/util/comm-host.c
@@ -78,6 +78,7 @@ int ec_command(int command, int version,
int comm_init(int interfaces, const char *device_name)
{
struct ec_response_get_protocol_info info;
+ int new_size;
/* Default memmap access */
ec_readmem = fake_readmem;
@@ -108,16 +109,25 @@ int comm_init(int interfaces, const char *device_name)
return 1;
}
- /* read max request / response size from ec for protocol v3+ */
+ /*
+ * read max request / response size from ec and reduce buffer size
+ * if the size supported by ec is less than the default value.
+ */
if (ec_command(EC_CMD_GET_PROTOCOL_INFO, 0, NULL, 0, &info,
sizeof(info)) == sizeof(info)) {
- ec_max_outsize = info.max_request_packet_size -
- sizeof(struct ec_host_request);
- ec_max_insize = info.max_response_packet_size -
+ new_size = info.max_request_packet_size -
+ sizeof(struct ec_host_request);
+ if (ec_max_outsize > new_size) {
+ ec_max_outsize = new_size;
+ ec_outbuf = realloc(ec_outbuf, ec_max_outsize);
+ }
+ new_size = info.max_response_packet_size -
sizeof(struct ec_host_response);
- ec_outbuf = realloc(ec_outbuf, ec_max_outsize);
- ec_inbuf = realloc(ec_inbuf, ec_max_insize);
+ if (ec_max_insize > new_size) {
+ ec_max_insize = new_size;
+ ec_inbuf = realloc(ec_inbuf, ec_max_insize);
+ }
if (!ec_outbuf || !ec_inbuf) {
fprintf(stderr, "Unable to reallocate buffers\n");