summaryrefslogtreecommitdiff
path: root/common/usb_update.c
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@google.com>2017-04-16 16:44:54 +0800
committerchrome-bot <chrome-bot@chromium.org>2017-04-17 22:50:20 -0700
commit5a5c38c2e9d62e6c0f45c2fb7f9df8b995379c46 (patch)
tree81f24b39ef50701c6d8889ed9c39bbb7c87eff4e /common/usb_update.c
parente3b520b27a57198bf12670311b7b9bc39af3ad76 (diff)
downloadchrome-ec-5a5c38c2e9d62e6c0f45c2fb7f9df8b995379c46.tar.gz
common/usb_update: Statically allocate update buffer
This makes error handling simpler, and also guarantees at compile time that EC will be able to allocate that much memory. BRANCH=none BUG=b:35587171 TEST=Update hammer using usb_updater2 Change-Id: Ifd4c5da80e98ee93b558679ab1cac8d5d89512e3 Reviewed-on: https://chromium-review.googlesource.com/479175 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Nick Sanders <nsanders@chromium.org> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
Diffstat (limited to 'common/usb_update.c')
-rw-r--r--common/usb_update.c28
1 files changed, 3 insertions, 25 deletions
diff --git a/common/usb_update.c b/common/usb_update.c
index 6a85f19424..cf1f205763 100644
--- a/common/usb_update.c
+++ b/common/usb_update.c
@@ -9,7 +9,6 @@
#include "consumer.h"
#include "extension.h"
#include "queue_policies.h"
-#include "shared_mem.h"
#include "system.h"
#include "update_fw.h"
#include "usb-stream.h"
@@ -70,7 +69,8 @@ enum rx_state {
};
enum rx_state rx_state_ = rx_idle;
-static uint8_t *block_buffer;
+static uint8_t block_buffer[sizeof(struct update_command) +
+ CONFIG_UPDATE_PDU_SIZE];
static uint32_t block_size;
static uint32_t block_index;
@@ -131,10 +131,6 @@ static void send_error_reset(uint8_t resp_value)
QUEUE_ADD_UNITS(&update_to_usb, &resp_value, 1);
rx_state_ = rx_idle;
data_was_transferred = 0;
- if (block_buffer) {
- shared_mem_release(block_buffer);
- block_buffer = NULL;
- }
}
/* Called to deal with data from the host */
@@ -151,14 +147,6 @@ static void update_out_handler(struct consumer const *consumer, size_t count)
/* If timeout exceeds 5 seconds - let's start over. */
if ((delta_time > 5000000) && (rx_state_ != rx_idle)) {
- if (block_buffer) {
- /*
- * Previous transfer could have been aborted mid
- * block.
- */
- shared_mem_release(block_buffer);
- block_buffer = NULL;
- }
rx_state_ = rx_idle;
CPRINTS("FW update: recovering after timeout");
}
@@ -263,20 +251,12 @@ static void update_out_handler(struct consumer const *consumer, size_t count)
* Only update start PDU is allowed to have a size 0 payload.
*/
if (block_size <= sizeof(struct update_command) ||
- block_size > (UPDATE_PDU_SIZE +
- sizeof(struct update_command))) {
+ block_size > sizeof(block_buffer)) {
CPRINTS("Invalid block size (%d).", block_size);
send_error_reset(UPDATE_GEN_ERROR);
return;
}
- if (shared_mem_acquire(block_size, (char **)&block_buffer)
- != EC_SUCCESS) {
- CPRINTS("Alloc error (%d).", block_size);
- send_error_reset(UPDATE_MALLOC_ERROR);
- return;
- }
-
/*
* Copy the rest of the message into the block buffer to pass
* to the updater.
@@ -321,8 +301,6 @@ static void update_out_handler(struct consumer const *consumer, size_t count)
resp_value = block_buffer[0];
QUEUE_ADD_UNITS(&update_to_usb, &resp_value, sizeof(resp_value));
rx_state_ = rx_outside_block;
- shared_mem_release(block_buffer);
- block_buffer = NULL;
}
static void update_flush(struct consumer const *consumer)