util/ec_flash: avoid divide-by-zero

BUG=none
BRANCH=none
TEST=none

Change-Id: I514c2aa307e94be826e9c8e219eb471892b3fad6
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Found-by: Coverity Scan #201954
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1725951
Tested-by: Patrick Georgi <pgeorgi@chromium.org>
Auto-Submit: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Commit-Queue: Patrick Georgi <pgeorgi@chromium.org>
This commit is contained in:
Patrick Georgi 2019-07-30 15:25:37 +02:00 committed by Commit Bot
parent d754f92d3b
commit da820cb63d
1 changed files with 7 additions and 0 deletions

View File

@ -153,6 +153,13 @@ int ec_flash_write(const uint8_t *buf, int offset, int size)
if (write_size < 0)
return write_size;
/*
* shouldn't ever happen, but report an error rather than a division
* by zero in the next statement.
*/
if (write_size == 0)
return -1;
step = (pdata_max_size / write_size) * write_size;
if (!step) {