From ac77140b7f4f42075d2377fc9d956a636b05aacf Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Mon, 11 Mar 2019 16:07:55 -0700 Subject: common: bit change 1 << constants with BIT(constants) Mechanical replacement of bit operation where operand is a constant. More bit operation exist, but prone to errors. Reveal a bug in npcx: chip/npcx/system-npcx7.c:114:54: error: conversion from 'long unsigned int' to 'uint8_t' {aka 'volatile unsigned char'} changes value from '16777215' to '255' [-Werror=overflow] BUG=None BRANCH=None TEST=None Change-Id: I006614026143fa180702ac0d1cc2ceb1b3c6eeb0 Signed-off-by: Gwendal Grignou Reviewed-on: https://chromium-review.googlesource.com/1518660 Reviewed-by: Daisuke Nojiri --- common/keyboard_scan.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'common/keyboard_scan.c') diff --git a/common/keyboard_scan.c b/common/keyboard_scan.c index 24fc7bc73c..a8f843e0a2 100644 --- a/common/keyboard_scan.c +++ b/common/keyboard_scan.c @@ -197,10 +197,10 @@ static void simulate_key(int row, int col, int pressed) { int old_polls; - if ((simulated_key[col] & (1 << row)) == ((pressed ? 1 : 0) << row)) + if ((simulated_key[col] & BIT(row)) == ((pressed ? 1 : 0) << row)) return; /* No change */ - simulated_key[col] ^= (1 << row); + simulated_key[col] ^= BIT(row); /* Keep track of polls now that we've got keys simulated */ old_polls = kbd_polls; @@ -481,7 +481,7 @@ static int check_keys_changed(uint8_t *state) continue; for (i = 0; i < KEYBOARD_ROWS; i++) { - if (diff & (1 << i)) + if (diff & BIT(i)) scan_edge_index[c][i] = scan_time_index; } @@ -601,7 +601,7 @@ static uint32_t check_key_list(const uint8_t *state) k = boot_key_list; for (c = 0; c < ARRAY_SIZE(boot_key_list); c++, k++) { if (curr_state[k->mask_index] & k->mask_value) { - boot_key_mask |= (1 << c); + boot_key_mask |= BIT(c); curr_state[k->mask_index] &= ~k->mask_value; } } @@ -1005,7 +1005,7 @@ static int command_keyboard_press(int argc, char **argv) if (simulated_key[i] == 0) continue; for (j = 0; j < KEYBOARD_ROWS; ++j) - if (simulated_key[i] & (1 << j)) + if (simulated_key[i] & BIT(j)) ccprintf("\t%d %d\n", i, j); } -- cgit v1.2.1