fix(rmm): fix MISRA C:2012 Rule 10.4
Signed-off-by: AlexeiFedorov <Alexei.Fedorov@arm.com>
Change-Id: I03630ef02c8c294a552ad10523d9c78091ce161a
diff --git a/lib/realm/src/granule.c b/lib/realm/src/granule.c
index c3a99fa..5d278cf 100644
--- a/lib/realm/src/granule.c
+++ b/lib/realm/src/granule.c
@@ -136,17 +136,14 @@
/*
* Sort a set of granules by their address.
*/
-static void sort_granules(struct granule_set *granules,
- unsigned long n)
+static void sort_granules(struct granule_set *granules, unsigned long n)
{
- unsigned long i;
-
- for (i = 1UL; i < n; i++) {
+ for (unsigned long i = 1UL; i < n; i++) {
struct granule_set temp = granules[i];
unsigned long j = i;
- while ((j > 0UL) && (granules[j - 1].addr > temp.addr)) {
- granules[j] = granules[j - 1];
+ while ((j > 0UL) && (granules[j - 1UL].addr > temp.addr)) {
+ granules[j] = granules[j - 1UL];
j--;
}
if (i != j) {
@@ -183,16 +180,16 @@
* If the function fails, no lock is held and no *->g_ret pointers are
* modified.
*/
-static bool find_lock_granules(struct granule_set *granules,
- unsigned long n)
+static bool find_lock_granules(struct granule_set *granules, unsigned long n)
{
- long i;
+ unsigned long i;
sort_granules(granules, n);
- for (i = 0L; i < n; i++) {
+ for (i = 0UL; i < n; i++) {
/* Check for duplicates */
- if ((i > 0L) && (granules[i].addr == granules[i - 1].addr)) {
+ if ((i != 0UL) &&
+ (granules[i].addr == granules[i - 1UL].addr)) {
goto out_err;
}
@@ -203,14 +200,14 @@
}
}
- for (i = 0L; i < n; i++) {
+ for (i = 0UL; i < n; i++) {
*granules[i].g_ret = granules[i].g;
}
return true;
out_err:
- for (i = i - 1; i >= 0L; i--) {
+ while (i-- != 0UL) {
granule_unlock(granules[i].g);
}
diff --git a/lib/realm/src/include/buffer_private.h b/lib/realm/src/include/buffer_private.h
index 5034d08..77b1a2a 100644
--- a/lib/realm/src/include/buffer_private.h
+++ b/lib/realm/src/include/buffer_private.h
@@ -11,8 +11,8 @@
* needs to be a power of two, so round NR_CPU_SLOTS up to the closest
* power of two.
*/
-#define ROUNDED_NR_CPU_SLOTS \
- (1ULL << (64U - (unsigned int)__builtin_clzll((NR_CPU_SLOTS) - 1U)))
+#define ROUNDED_NR_CPU_SLOTS (1ULL << (64U - \
+ (unsigned int)__builtin_clzll(((unsigned long long)NR_CPU_SLOTS) - 1U)))
#define RMM_SLOT_BUF_VA_SIZE ((ROUNDED_NR_CPU_SLOTS) * (GRANULE_SIZE))
diff --git a/lib/realm/src/s2tt.c b/lib/realm/src/s2tt.c
index 9269a85..646bd65 100644
--- a/lib/realm/src/s2tt.c
+++ b/lib/realm/src/s2tt.c
@@ -26,7 +26,7 @@
* The maximum number of bits supported by the RMM for a stage 2 translation
* output address (including stage 2 table entries).
*/
-#define S2TTE_OA_BITS 48
+#define S2TTE_OA_BITS 48U
#define DESC_TYPE_MASK 3UL
#define S2TTE_Lx_INVALID 0UL
@@ -107,19 +107,19 @@
*/
#define S2TTE_INVALID_HIPAS_SHIFT 2
-#define S2TTE_INVALID_HIPAS_WIDTH 3
+#define S2TTE_INVALID_HIPAS_WIDTH 3U
#define S2TTE_INVALID_HIPAS_MASK MASK(S2TTE_INVALID_HIPAS)
-#define S2TTE_INVALID_HIPAS_UNASSIGNED (INPLACE(S2TTE_INVALID_HIPAS, 0))
-#define S2TTE_INVALID_HIPAS_ASSIGNED (INPLACE(S2TTE_INVALID_HIPAS, 1))
+#define S2TTE_INVALID_HIPAS_UNASSIGNED (INPLACE(S2TTE_INVALID_HIPAS, 0UL))
+#define S2TTE_INVALID_HIPAS_ASSIGNED (INPLACE(S2TTE_INVALID_HIPAS, 1UL))
#define S2TTE_INVALID_RIPAS_SHIFT 5
-#define S2TTE_INVALID_RIPAS_WIDTH 2
+#define S2TTE_INVALID_RIPAS_WIDTH 2U
#define S2TTE_INVALID_RIPAS_MASK MASK(S2TTE_INVALID_RIPAS)
-#define S2TTE_INVALID_RIPAS_EMPTY (INPLACE(S2TTE_INVALID_RIPAS, 0))
-#define S2TTE_INVALID_RIPAS_RAM (INPLACE(S2TTE_INVALID_RIPAS, 1))
-#define S2TTE_INVALID_RIPAS_DESTROYED (INPLACE(S2TTE_INVALID_RIPAS, 2))
+#define S2TTE_INVALID_RIPAS_EMPTY (INPLACE(S2TTE_INVALID_RIPAS, 0UL))
+#define S2TTE_INVALID_RIPAS_RAM (INPLACE(S2TTE_INVALID_RIPAS, 1UL))
+#define S2TTE_INVALID_RIPAS_DESTROYED (INPLACE(S2TTE_INVALID_RIPAS, 2UL))
#define S2TTE_INVALID_UNPROTECTED 0x0UL