summaryrefslogtreecommitdiff
path: root/src/ec/google
diff options
context:
space:
mode:
authorTim Wawrzynczak <twawrzynczak@chromium.org>2020-07-14 13:30:46 -0600
committerTim Wawrzynczak <twawrzynczak@chromium.org>2020-07-22 21:06:56 +0000
commit7777e1c30b5c9d47388627c080ff86a4e043ec7e (patch)
tree08a66a6484f3267dd90a27b6c6b66efd24eae447 /src/ec/google
parent60c619f6a3c0fbe2f53095a029cd07a11f5cf5e1 (diff)
ec/google/chromeec: Fix Coverity Scan error (BAD_SHIFT)
A recent Coverity scan found an issue with the way the EC_HOST_EVENT_MASK macro was being used. It was being passed values between 0 and 63, but since it is doing basically (1ULL << (value - 1)), this caused a shift of -1 when `i` is 0 and also doesn't reach the 63rd bit of the mask. This is fixed by incrementing the start and end conditions of the loop by 1, so the event mask ranges from bits 0 to 63, instead of -1 to 62. Found-by: Coverity CID 1430218 Signed-off-by: Tim Wawrzynczak <twawrzynczak@chromium.org> Change-Id: I6a7cfa64545f3d313de24407f0a91b48368f2a8a Reviewed-on: https://review.coreboot.org/c/coreboot/+/43460 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Furquan Shaikh <furquan@google.com> Reviewed-by: Karthik Ramasubramanian <kramasub@google.com>
Diffstat (limited to 'src/ec/google')
-rw-r--r--src/ec/google/chromeec/ec.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c
index a97dfb355e..954e6490f7 100644
--- a/src/ec/google/chromeec/ec.c
+++ b/src/ec/google/chromeec/ec.c
@@ -393,7 +393,14 @@ void google_chromeec_log_events(uint64_t mask)
return;
events = google_chromeec_get_events_b() & mask;
- for (i = 0; i < sizeof(events) * 8; i++) {
+
+ /*
+ * This loop starts at 1 because the EC_HOST_EVENT_MASK macro subtracts
+ * 1 from its argument before applying the left-shift operator. This
+ * prevents a left-shift of -1 happening, and covers the entire 64-bit
+ * range of the event mask.
+ */
+ for (i = 1; i <= sizeof(events) * 8; i++) {
if (EC_HOST_EVENT_MASK(i) & events)
elog_add_event_byte(ELOG_TYPE_EC_EVENT, i);
}