From 0f76d0d57ec700b835e1715200f4520fde1c11c4 Mon Sep 17 00:00:00 2001 From: Nithin G Date: Tue, 23 Apr 2024 12:41:00 +0530 Subject: [PATCH 1/7] fix(arm-drivers): typecast expression to match data type This corrects the MISRA violation C2012-10.6: The value of a composite expression shall not be assigned to an object with wider essential type. Explicitly type casted to match the data type of composite expression. Change-Id: I2ec044ff7fd7a8d0cdc8db5f71f30872fb8d9e81 Signed-off-by: Nithin G Signed-off-by: Maheedhar Bollapalli --- drivers/arm/gic/v2/gicdv2_helpers.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/arm/gic/v2/gicdv2_helpers.c b/drivers/arm/gic/v2/gicdv2_helpers.c index db9ba87c4..2f3f7f8dc 100644 --- a/drivers/arm/gic/v2/gicdv2_helpers.c +++ b/drivers/arm/gic/v2/gicdv2_helpers.c @@ -8,6 +8,7 @@ #include #include +#include #include "../common/gic_common_private.h" @@ -256,7 +257,7 @@ void gicd_set_igroupr(uintptr_t base, unsigned int id) unsigned int bit_num = id & ((1U << IGROUPR_SHIFT) - 1U); unsigned int reg_val = gicd_read_igroupr(base, id); - gicd_write_igroupr(base, id, reg_val | (1U << bit_num)); + gicd_write_igroupr(base, id, reg_val | BIT_32(bit_num)); } void gicd_clr_igroupr(uintptr_t base, unsigned int id) @@ -264,35 +265,35 @@ void gicd_clr_igroupr(uintptr_t base, unsigned int id) unsigned int bit_num = id & ((1U << IGROUPR_SHIFT) - 1U); unsigned int reg_val = gicd_read_igroupr(base, id); - gicd_write_igroupr(base, id, reg_val & ~(1U << bit_num)); + gicd_write_igroupr(base, id, reg_val & ~BIT_32(bit_num)); } void gicd_set_isenabler(uintptr_t base, unsigned int id) { unsigned int bit_num = id & ((1U << ISENABLER_SHIFT) - 1U); - gicd_write_isenabler(base, id, (1U << bit_num)); + gicd_write_isenabler(base, id, BIT_32(bit_num)); } void gicd_set_icenabler(uintptr_t base, unsigned int id) { unsigned int bit_num = id & ((1U << ICENABLER_SHIFT) - 1U); - gicd_write_icenabler(base, id, (1U << bit_num)); + gicd_write_icenabler(base, id, BIT_32(bit_num)); } void gicd_set_ispendr(uintptr_t base, unsigned int id) { unsigned int bit_num = id & ((1U << ISPENDR_SHIFT) - 1U); - gicd_write_ispendr(base, id, (1U << bit_num)); + gicd_write_ispendr(base, id, BIT_32(bit_num)); } void gicd_set_icpendr(uintptr_t base, unsigned int id) { unsigned int bit_num = id & ((1U << ICPENDR_SHIFT) - 1U); - gicd_write_icpendr(base, id, (1U << bit_num)); + gicd_write_icpendr(base, id, BIT_32(bit_num)); } unsigned int gicd_get_isactiver(uintptr_t base, unsigned int id) @@ -307,14 +308,14 @@ void gicd_set_isactiver(uintptr_t base, unsigned int id) { unsigned int bit_num = id & ((1U << ISACTIVER_SHIFT) - 1U); - gicd_write_isactiver(base, id, (1U << bit_num)); + gicd_write_isactiver(base, id, BIT_32(bit_num)); } void gicd_set_icactiver(uintptr_t base, unsigned int id) { unsigned int bit_num = id & ((1U << ICACTIVER_SHIFT) - 1U); - gicd_write_icactiver(base, id, (1U << bit_num)); + gicd_write_icactiver(base, id, BIT_32(bit_num)); } void gicd_set_ipriorityr(uintptr_t base, unsigned int id, unsigned int pri) From bec4a2c9c3919c4a3012c7a10f4fa75a861f8150 Mon Sep 17 00:00:00 2001 From: Nithin G Date: Tue, 23 Apr 2024 15:29:52 +0530 Subject: [PATCH 2/7] fix(arm-drivers): align essential type categories This corrects the MISRA violation C2012-10.7: If a composite expression is used as one operand of an operator in which the usual arithmetic conversions are performed then the other operand shall not have wider essential type. Explicitly type casted to match the data type of both the operands. Change-Id: I89fef817ad672f310de9bc0e93646cd2ba04793b Signed-off-by: Nithin G Signed-off-by: Maheedhar Bollapalli --- drivers/arm/gic/v2/gicv2_helpers.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/arm/gic/v2/gicv2_helpers.c b/drivers/arm/gic/v2/gicv2_helpers.c index a9ae0b53a..34154996b 100644 --- a/drivers/arm/gic/v2/gicv2_helpers.c +++ b/drivers/arm/gic/v2/gicv2_helpers.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "../common/gic_common_private.h" #include "gicv2_private.h" @@ -203,7 +204,7 @@ void gicv2_secure_ppi_sgi_setup_props(uintptr_t gicd_base, } /* We have an SGI or a PPI. They are Group0 at reset */ - sec_ppi_sgi_mask |= (1u << prop_desc->intr_num); + sec_ppi_sgi_mask |= BIT_32((uint32_t)prop_desc->intr_num); /* Set the priority of this interrupt */ gicd_set_ipriorityr(gicd_base, prop_desc->intr_num, From edecc70331ec5e7583972f66f0e8dc6cf039c686 Mon Sep 17 00:00:00 2001 From: Nithin G Date: Tue, 23 Apr 2024 17:38:25 +0530 Subject: [PATCH 3/7] fix(arm-drivers): 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: I1500e2b3628313e68f94bce701a057b80bc2f933 Signed-off-by: Nithin G Signed-off-by: Maheedhar Bollapalli --- drivers/arm/cci/cci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/arm/cci/cci.c b/drivers/arm/cci/cci.c index 40d2efdeb..ae2b9bb04 100644 --- a/drivers/arm/cci/cci.c +++ b/drivers/arm/cci/cci.c @@ -143,7 +143,7 @@ void cci_enable_snoop_dvm_reqs(unsigned int master_id) * rest of bits are write ignore */ mmio_write_32(cci_base + - SLAVE_IFACE_OFFSET(slave_if_id) + SNOOP_CTRL_REG, + SLAVE_IFACE_OFFSET((u_register_t)slave_if_id) + SNOOP_CTRL_REG, DVM_EN_BIT | SNOOP_EN_BIT); /* @@ -171,7 +171,7 @@ void cci_disable_snoop_dvm_reqs(unsigned int master_id) * rest of bits are write ignore. */ mmio_write_32(cci_base + - SLAVE_IFACE_OFFSET(slave_if_id) + SNOOP_CTRL_REG, + SLAVE_IFACE_OFFSET((u_register_t)slave_if_id) + SNOOP_CTRL_REG, ~(DVM_EN_BIT | SNOOP_EN_BIT)); /* From 97eefd9989aeb2ce2093e873ceab535df9559a59 Mon Sep 17 00:00:00 2001 From: Nithin G Date: Tue, 23 Apr 2024 17:54:08 +0530 Subject: [PATCH 4/7] 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) From e358089d8382e4239a4b606b0e97cf5475da4976 Mon Sep 17 00:00:00 2001 From: Nithin G Date: Fri, 19 Apr 2024 17:53:01 +0530 Subject: [PATCH 5/7] fix(bl31): add const qualifier This corrects the MISRA violation C2012-8.13: A pointer should point to a const-qualified type whenever possible. Added const qualifier to pointer in the function arguments. Change-Id: Ia323a2b2946d61a639696e2559f88e376beda861 Signed-off-by: Nithin G Signed-off-by: Maheedhar Bollapalli --- bl31/bl31_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bl31/bl31_main.c b/bl31/bl31_main.c index db0ea6cb1..0cd0c7958 100644 --- a/bl31/bl31_main.c +++ b/bl31/bl31_main.c @@ -255,7 +255,7 @@ uint32_t bl31_get_next_image_type(void) ******************************************************************************/ void __init bl31_prepare_next_image_entry(void) { - entry_point_info_t *next_image_info; + const entry_point_info_t *next_image_info; uint32_t image_type; #if CTX_INCLUDE_AARCH32_REGS From 54c9c68a49bc7b3aaa29207f798b1973e3cdb542 Mon Sep 17 00:00:00 2001 From: Nithin G Date: Fri, 19 Apr 2024 18:02:02 +0530 Subject: [PATCH 6/7] fix(el3-runtime): add const qualifier This corrects the MISRA violation C2012-8.13: A pointer should point to a const-qualified type whenever possible. Added const qualifier to pointer in the function arguments. Change-Id: Idf4b8ea7842304849242a06d6ada73f11afc8cde Signed-off-by: Nithin G Signed-off-by: Maheedhar Bollapalli --- lib/el3_runtime/aarch64/context_mgmt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/el3_runtime/aarch64/context_mgmt.c b/lib/el3_runtime/aarch64/context_mgmt.c index 3388f1c52..9745c3c1b 100644 --- a/lib/el3_runtime/aarch64/context_mgmt.c +++ b/lib/el3_runtime/aarch64/context_mgmt.c @@ -2069,8 +2069,8 @@ void cm_write_scr_el3_bit(uint32_t security_state, ******************************************************************************/ u_register_t cm_get_scr_el3(uint32_t security_state) { - cpu_context_t *ctx; - el3_state_t *state; + const cpu_context_t *ctx; + const el3_state_t *state; ctx = cm_get_context(security_state); assert(ctx != NULL); From 7b970841ad1c9925e72c170734ca30016813743d Mon Sep 17 00:00:00 2001 From: Nithin G Date: Fri, 19 Apr 2024 18:06:36 +0530 Subject: [PATCH 7/7] fix(psci): add const qualifier This corrects the MISRA violation C2012-8.13: A pointer should point to a const-qualified type whenever possible. Added const qualifier to pointer in the function arguments. Change-Id: Id3d4aa528f275973a37c0b9af04495632cb2dda3 Signed-off-by: Nithin G Signed-off-by: Maheedhar Bollapalli --- lib/psci/psci_common.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/psci/psci_common.c b/lib/psci/psci_common.c index 234a19509..2d3335031 100644 --- a/lib/psci/psci_common.c +++ b/lib/psci/psci_common.c @@ -546,7 +546,7 @@ void psci_do_state_coordination(unsigned int cpu_idx, unsigned int end_pwrlvl, unsigned int lvl, parent_idx; unsigned int start_idx; unsigned int ncpus; - plat_local_state_t target_state, *req_states; + plat_local_state_t target_state; assert(end_pwrlvl <= PLAT_MAX_PWR_LVL); parent_idx = psci_cpu_pd_nodes[cpu_idx].parent_node; @@ -561,7 +561,8 @@ void psci_do_state_coordination(unsigned int cpu_idx, unsigned int end_pwrlvl, /* Get the requested power states for this power level */ start_idx = psci_non_cpu_pd_nodes[parent_idx].cpu_start_idx; - req_states = psci_get_req_local_pwr_states(lvl, start_idx); + plat_local_state_t const *req_states = psci_get_req_local_pwr_states(lvl, + start_idx); /* * Let the platform coordinate amongst the requested states at