From 97eefd9989aeb2ce2093e873ceab535df9559a59 Mon Sep 17 00:00:00 2001 From: Nithin G Date: Tue, 23 Apr 2024 17:54:08 +0530 Subject: [PATCH] fix(console): typecast expressions to match data type This corrects the MISRA violation C2012-10.4: Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category. The condition is explicitly checked against 0U, appending 'U' and typecasting for unsigned comparison. Change-Id: I4276035b3e7a223e80712e023457662689a011a1 Signed-off-by: Nithin G Signed-off-by: Maheedhar Bollapalli --- drivers/console/multi_console.c | 4 ++-- include/drivers/console.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/console/multi_console.c b/drivers/console/multi_console.c index 5ecbaed1d..59a4a868b 100644 --- a/drivers/console/multi_console.c +++ b/drivers/console/multi_console.c @@ -79,8 +79,8 @@ static int do_putc(int c, console_t *console) { int ret; - if ((c == '\n') && - ((console->flags & CONSOLE_FLAG_TRANSLATE_CRLF) != 0)) { + if ((c == (int)'\n') && + ((console->flags & CONSOLE_FLAG_TRANSLATE_CRLF) != 0U)) { ret = console->putc('\r', console); if (ret < 0) return ret; diff --git a/include/drivers/console.h b/include/drivers/console.h index fa4eb9462..0de2c99b7 100644 --- a/include/drivers/console.h +++ b/include/drivers/console.h @@ -27,7 +27,7 @@ #define CONSOLE_FLAG_RUNTIME (U(1) << 1) #define CONSOLE_FLAG_CRASH (U(1) << 2) /* Bits 3 to 7 reserved for additional scopes in future expansion. */ -#define CONSOLE_FLAG_SCOPE_MASK ((U(1) << 8) - 1) +#define CONSOLE_FLAG_SCOPE_MASK GENMASK(7, 0) /* Bits 8 to 31 for non-scope use. */ #define CONSOLE_FLAG_TRANSLATE_CRLF (U(1) << 8)