From 1290662034578b4e52443c79f34dfd7c284c0435 Mon Sep 17 00:00:00 2001 From: Yann Gautier Date: Tue, 21 Jun 2022 14:34:00 +0200 Subject: [PATCH 1/5] fix(partition): add missing curly braces Add braces to correct MISRA C2012 15.6 warning: The body of an iteration-statement or a selection-statement shall be a compound-statement. Signed-off-by: Yann Gautier Change-Id: I4041b0080b678f5ffdbe074e3cee9ac0afd5e176 --- drivers/partition/gpt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/partition/gpt.c b/drivers/partition/gpt.c index 4fe832244..8b1046d00 100644 --- a/drivers/partition/gpt.c +++ b/drivers/partition/gpt.c @@ -26,14 +26,16 @@ static int unicode_to_ascii(unsigned short *str_in, unsigned char *str_out) /* check whether the unicode string is valid */ for (i = 1; i < (EFI_NAMELEN << 1); i += 2) { - if (name[i] != '\0') + if (name[i] != '\0') { return -EINVAL; + } } /* convert the unicode string to ascii string */ for (i = 0; i < (EFI_NAMELEN << 1); i += 2) { str_out[i >> 1] = name[i]; - if (name[i] == '\0') + if (name[i] == '\0') { break; + } } return 0; } From d1c6c495541b6e387179f987acbef274a12c7535 Mon Sep 17 00:00:00 2001 From: Yann Gautier Date: Fri, 18 Nov 2022 13:43:32 +0100 Subject: [PATCH 2/5] fix(partition): add U suffix for unsigned numbers This corrects MISRA c2012-7.2 violation: A "u" or "U" suffix shall be applied to all integer constants that are represented in an unsigned type. Signed-off-by: Yann Gautier Change-Id: I5508a7d482213fc4d22e3e7ac53defb4135af596 --- include/drivers/partition/efi.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/drivers/partition/efi.h b/include/drivers/partition/efi.h index e463f9657..96c285737 100644 --- a/include/drivers/partition/efi.h +++ b/include/drivers/partition/efi.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Linaro Limited + * Copyright (c) 2022, STMicroelectronics - All Rights Reserved * * SPDX-License-Identifier: BSD-3-Clause * @@ -25,13 +26,13 @@ static inline void *guidcpy(void *dst, const void *src) } #define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \ - { (a) & 0xffffffff, \ - (b) & 0xffff, \ - (c) & 0xffff, \ + { (a) & 0xffffffffU, \ + (b) & 0xffffU, \ + (c) & 0xffffU, \ { (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) } } #define NULL_GUID \ - EFI_GUID(0x00000000, 0x0000, 0x0000, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00) + EFI_GUID(0x00000000U, 0x0000U, 0x0000U, 0x00U, 0x00U, \ + 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U) #endif /* DRIVERS_PARTITION_EFI_H */ From 14cda5168de45bbbcce1a5152140111d4fc8fd21 Mon Sep 17 00:00:00 2001 From: Yann Gautier Date: Fri, 18 Nov 2022 15:02:35 +0100 Subject: [PATCH 3/5] fix(mmc): explicitly check operators precedence This corrects the MISRA violation C2012-12.1: The precedence of operators within expressions should be made explicit While at it put the test on one line. Signed-off-by: Yann Gautier Change-Id: Id19231faaf033c1e7dbe703690e0dddc7aa8f346 --- drivers/mmc/mmc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 8e83464d5..1a63f6185 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -780,8 +780,7 @@ int mmc_part_switch_current_boot(void) unsigned char current_boot_part = mmc_current_boot_part(); int ret; - if (current_boot_part != 1U && - current_boot_part != 2U) { + if ((current_boot_part != 1U) && (current_boot_part != 2U)) { ERROR("Got unexpected value for active boot partition, %u\n", current_boot_part); return -EIO; } From bf78a6504254be9bf2cee38828a72f84773d4aa7 Mon Sep 17 00:00:00 2001 From: Yann Gautier Date: Mon, 21 Nov 2022 11:38:50 +0100 Subject: [PATCH 4/5] fix(mmc): do not modify r_data in mmc_send_cmd() Fix MISRA C2012-17.8: A function parameter should not be modified Signed-off-by: Yann Gautier Change-Id: I08ed4c6768c7988a98de21da181b97b0885139de --- drivers/mmc/mmc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 1a63f6185..d6f442167 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -69,8 +69,7 @@ static int mmc_send_cmd(unsigned int idx, unsigned int arg, int i; for (i = 0; i < 4; i++) { - *r_data = cmd.resp_data[i]; - r_data++; + r_data[i] = cmd.resp_data[i]; } } From 53cbc949670877d1b661782ab452f6fac2302ce3 Mon Sep 17 00:00:00 2001 From: Yann Gautier Date: Mon, 20 Jun 2022 18:03:08 +0200 Subject: [PATCH 5/5] fix(mmc): align part config type This corrects MISRA C2012 10.3: The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category. Set part_config to be an unsigned char everywhere it is used. Signed-off-by: Yann Gautier Change-Id: I9cf87848fb016a5630b3c8091290419e3bc62b91 --- drivers/mmc/mmc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index d6f442167..2b727d4e7 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -111,7 +111,7 @@ static int mmc_device_state(void) return MMC_GET_STATE(resp_data[0]); } -static int mmc_send_part_switch_cmd(unsigned int part_config) +static int mmc_send_part_switch_cmd(unsigned char part_config) { int ret; unsigned int part_time = 0; @@ -759,9 +759,9 @@ size_t mmc_erase_blocks(int lba, size_t size) return size; } -static int mmc_part_switch(unsigned int part_type) +static int mmc_part_switch(unsigned char part_type) { - uint8_t part_config = mmc_ext_csd[CMD_EXTCSD_PARTITION_CONFIG]; + unsigned char part_config = mmc_ext_csd[CMD_EXTCSD_PARTITION_CONFIG]; part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK; part_config |= part_type;