diff options
-rw-r--r-- | util/comm-host.c | 22 |
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"); |