summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Brandmeyer <jbrandmeyer@chromium.org>2018-07-19 16:37:14 -0600
committerchrome-bot <chrome-bot@chromium.org>2018-07-20 15:10:15 -0700
commit3fe8066ca9d4b50c04ba7d338b3feb4ebba5233b (patch)
tree63bbfa5f60513e2162641d386e3de9e5da17431f
parentb6bb2782ddd3f26c6ec2cc781758c76fb434a282 (diff)
downloadchrome-ec-3fe8066ca9d4b50c04ba7d338b3feb4ebba5233b.tar.gz
cleanup: Resolve some defects seen with Coverity.
- Correct two range checks in set_pwm_led_color(). The erroneous checks allowed a real array out-of-bounds error accessible via the EC console. Scope is limited to pre-release hardware that had enabled CONFIG_CMD_LEDTEST. - Correct comparisons of unsigned integers to a negative constant. - Add an explicit /* fallthrough */ on an un-recognized deliberate fallthrough. TEST=make -j buildall BUG=none BRANCH=none Change-Id: Ifc460427729ce597e945142f0256a1364b0a083e Signed-off-by: Jonathan Brandmeyer <jbrandmeyer@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1145051 Reviewed-by: Edward Hill <ecgh@chromium.org>
-rw-r--r--common/led_pwm.c4
-rw-r--r--common/motion_sense.c1
-rw-r--r--common/spi_flash_reg.c4
3 files changed, 5 insertions, 4 deletions
diff --git a/common/led_pwm.c b/common/led_pwm.c
index 17201fb03e..3faa92cafe 100644
--- a/common/led_pwm.c
+++ b/common/led_pwm.c
@@ -56,8 +56,8 @@ void set_pwm_led_color(enum pwm_led_id id, int color)
{
struct pwm_led duty = { 0 };
- if ((id > CONFIG_LED_PWM_COUNT) || (id < 0) ||
- (color > EC_LED_COLOR_COUNT) || (color < -1))
+ if ((id >= CONFIG_LED_PWM_COUNT) || (id < 0) ||
+ (color >= EC_LED_COLOR_COUNT) || (color < -1))
return;
if (color != -1) {
diff --git a/common/motion_sense.c b/common/motion_sense.c
index 1fe3aeb064..966c2da99e 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -1351,6 +1351,7 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
case 0:
case 1:
fifo_int_enabled = in->fifo_int_enable.enable;
+ /* fallthrough */
case EC_MOTION_SENSE_NO_VALUE:
out->fifo_int_enable.ret = fifo_int_enabled;
args->response_size = sizeof(out->fifo_int_enable);
diff --git a/common/spi_flash_reg.c b/common/spi_flash_reg.c
index 1301e19dc5..569bbd5072 100644
--- a/common/spi_flash_reg.c
+++ b/common/spi_flash_reg.c
@@ -111,7 +111,7 @@ int spi_flash_reg_to_protect(uint8_t sr1, uint8_t sr2, unsigned int *start,
>> 2;
/* Bad pointers or invalid data */
- if (!start || !len || sr1 == -1 || sr2 == -1)
+ if (!start || !len || sr1 == 0xff || sr2 == 0xff)
return EC_ERROR_INVAL;
for (i = 0; i < ARRAY_SIZE(spi_flash_protect_ranges); ++i) {
@@ -159,7 +159,7 @@ int spi_flash_protect_to_reg(unsigned int start, unsigned int len, uint8_t *sr1,
char bp = 0;
/* Bad pointers */
- if (!sr1 || !sr2 || *sr1 == -1 || *sr2 == -1)
+ if (!sr1 || !sr2)
return EC_ERROR_INVAL;
/* Invalid data */