From 7777e1c30b5c9d47388627c080ff86a4e043ec7e Mon Sep 17 00:00:00 2001 From: Tim Wawrzynczak Date: Tue, 14 Jul 2020 13:30:46 -0600 Subject: 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 Change-Id: I6a7cfa64545f3d313de24407f0a91b48368f2a8a Reviewed-on: https://review.coreboot.org/c/coreboot/+/43460 Tested-by: build bot (Jenkins) Reviewed-by: Furquan Shaikh Reviewed-by: Karthik Ramasubramanian --- src/ec/google/chromeec/ec.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/ec/google') 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); } -- cgit v1.2.3