From d9e543a5f9e0aa3c844e82fedf2499f30c0f9e69 Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Sat, 24 Oct 2020 17:19:15 +0200 Subject: libpayload/keyboard: Use `bool` as return type Use `bool` whenever `0` was used to indicate an error. The mixing of different types for return values was mildly confusing and potentially dangerous with the i8042 API close by that uses `0` for success. Change-Id: I876bb5076c4921f36e3438f359be8ac4c09248cc Signed-off-by: Nico Huber Reviewed-on: https://review.coreboot.org/c/coreboot/+/46723 Tested-by: build bot (Jenkins) Reviewed-by: Paul Menzel Reviewed-by: Angel Pons --- payloads/libpayload/drivers/i8042/keyboard.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'payloads/libpayload/drivers') diff --git a/payloads/libpayload/drivers/i8042/keyboard.c b/payloads/libpayload/drivers/i8042/keyboard.c index eb94199ec0..2dec3a38f2 100644 --- a/payloads/libpayload/drivers/i8042/keyboard.c +++ b/payloads/libpayload/drivers/i8042/keyboard.c @@ -27,6 +27,8 @@ * SUCH DAMAGE. */ +#include + #include #include #include @@ -169,14 +171,14 @@ static struct layout_maps keyboard_layouts[] = { #endif }; -static unsigned char keyboard_cmd(unsigned char cmd) +static bool keyboard_cmd(unsigned char cmd) { i8042_write_data(cmd); return i8042_wait_read_ps2() == 0xfa; } -int keyboard_havechar(void) +bool keyboard_havechar(void) { return i8042_data_ready_ps2(); } @@ -306,13 +308,13 @@ int keyboard_set_layout(char *country) } static struct console_input_driver cons = { - .havekey = keyboard_havechar, + .havekey = (int (*)(void))keyboard_havechar, .getchar = keyboard_getchar, .input_type = CONSOLE_INPUT_TYPE_EC, }; /* Enable keyboard translated */ -static int enable_translated(void) +static bool enable_translated(void) { if (!i8042_cmd(I8042_CMD_RD_CMD_BYTE)) { int cmd = i8042_read_data_ps2(); @@ -321,19 +323,19 @@ static int enable_translated(void) i8042_write_data(cmd); } else { printf("ERROR: i8042_cmd WR_CMD failed!\n"); - return 0; + return false; } } else { printf("ERROR: i8042_cmd RD_CMD failed!\n"); - return 0; + return false; } - return 1; + return true; } /* Set scancode set 1 */ -static int set_scancode_set(void) +static bool set_scancode_set(void) { - unsigned int ret; + bool ret; ret = keyboard_cmd(I8042_KBCMD_SET_SCANCODE); if (!ret) { printf("ERROR: Keyboard set scancode failed!\n"); -- cgit v1.2.3