fix: UINTxx_C macro usage
UINTxx_C macro from standard library [1] accepts a scalar/constant value
and concatenates the C standard modifier (U, UL) to make it an unsigned
integer value.
The macro is not meant to be fed with expressions such as masks
e.g. UINT32_C(1 << 3)
The end result is concatenation of the U modifier to the tail of the
expression which is probably not the desired operation.
Most of the code base uses UINTxx_C macro with a single integer value as
parameter, although there are few places where expressions are used.
This change updates the latter to only use constants.
[1] https://git.trustedfirmware.org/hafnium/prebuilts.git/tree/linux-x64/clang/lib64/clang/12.0.5/include/stdint.h#n378
Signed-off-by: Olivier Deprez <olivier.deprez@arm.com>
Change-Id: I205646171e4b673b6507838f2211efa4c275753c
diff --git a/inc/hf/ffa_internal.h b/inc/hf/ffa_internal.h
index fa28251..fb8d7bc 100644
--- a/inc/hf/ffa_internal.h
+++ b/inc/hf/ffa_internal.h
@@ -14,7 +14,8 @@
#include "vmapi/hf/ffa.h"
-#define FFA_VERSION_RESERVED_BIT UINT32_C(1U << 31)
+#define FFA_VERSION_RESERVED_BIT (UINT32_C(1) << 31)
+
static inline struct ffa_value ffa_error(int32_t error_code)
{
return (struct ffa_value){.func = FFA_ERROR_32,
diff --git a/inc/hf/sp_pkg.h b/inc/hf/sp_pkg.h
index 2a38dbf..182840a 100644
--- a/inc/hf/sp_pkg.h
+++ b/inc/hf/sp_pkg.h
@@ -16,7 +16,7 @@
#define SP_PKG_HEADER_VERSION_1 0x1U
#define SP_PKG_HEADER_VERSION_2 0x2U
-#define SP_PKG_FLAG_BOOT_INFO UINT32_C(0x1U << 0)
+#define SP_PKG_FLAG_BOOT_INFO (UINT32_C(1) << 0)
/**
* Header for a SP Partition Package.
diff --git a/inc/vmapi/hf/ffa.h b/inc/vmapi/hf/ffa.h
index 6109bb4..759c498 100644
--- a/inc/vmapi/hf/ffa.h
+++ b/inc/vmapi/hf/ffa.h
@@ -99,7 +99,7 @@
* 13.2.
*/
-#define FFA_FEATURES_FUNC_ID_MASK UINT32_C(0x1 << 31)
+#define FFA_FEATURES_FUNC_ID_MASK (UINT32_C(1) << 31)
#define FFA_FEATURES_FEATURE_ID_MASK UINT32_C(0x7F)
/* Query interrupt ID of Notification Pending Interrupt. */
@@ -559,7 +559,7 @@
* Flag for notification bind and set, to specify call is about per-vCPU
* notifications.
*/
-#define FFA_NOTIFICATION_FLAG_PER_VCPU UINT32_C(1 << 0)
+#define FFA_NOTIFICATION_FLAG_PER_VCPU (UINT32_C(1) << 0)
/**
* Helper function to assemble a 64-bit sized bitmap, from the 32-bit sized lo
@@ -588,17 +588,19 @@
/**
* Flags used in calls to FFA_NOTIFICATION_GET interface.
*/
-#define FFA_NOTIFICATION_FLAG_BITMAP_SP UINT32_C(0x1 << 0)
-#define FFA_NOTIFICATION_FLAG_BITMAP_VM UINT32_C(0x1 << 1)
-#define FFA_NOTIFICATION_FLAG_BITMAP_SPM UINT32_C(0x1 << 2)
-#define FFA_NOTIFICATION_FLAG_BITMAP_HYP UINT32_C(0x1 << 3)
+#define FFA_NOTIFICATION_FLAG_BITMAP_SP (UINT32_C(1) << 0)
+#define FFA_NOTIFICATION_FLAG_BITMAP_VM (UINT32_C(1) << 1)
+#define FFA_NOTIFICATION_FLAG_BITMAP_SPM (UINT32_C(1) << 2)
+#define FFA_NOTIFICATION_FLAG_BITMAP_HYP (UINT32_C(1) << 3)
/* Flag to configure notification as being per vCPU. */
-#define FFA_NOTIFICATIONS_FLAG_PER_VCPU UINT32_C(0x1 << 0)
+#define FFA_NOTIFICATIONS_FLAG_PER_VCPU (UINT32_C(1) << 0)
/** Flag for FFA_NOTIFICATION_SET to delay Schedule Receiver Interrupt */
-#define FFA_NOTIFICATIONS_FLAG_DELAY_SRI UINT32_C(0x1 << 1)
-#define FFA_NOTIFICATIONS_FLAGS_VCPU_ID(id) UINT32_C((id & 0xFFFF) << 16)
+#define FFA_NOTIFICATIONS_FLAG_DELAY_SRI (UINT32_C(1) << 1)
+
+#define FFA_NOTIFICATIONS_FLAGS_VCPU_ID(id) \
+ ((((uint32_t)(id)) & UINT32_C(0xffff)) << 16)
static inline ffa_vcpu_index_t ffa_notifications_get_vcpu(struct ffa_value args)
{
diff --git a/src/arch/aarch64/hypervisor/handler.c b/src/arch/aarch64/hypervisor/handler.c
index cd64d68..9323ff5 100644
--- a/src/arch/aarch64/hypervisor/handler.c
+++ b/src/arch/aarch64/hypervisor/handler.c
@@ -59,7 +59,7 @@
/*
* Target function IDs for framework messages from the SPMD.
*/
-#define SPMD_FWK_MSG_BIT UINT64_C(1 << 31)
+#define SPMD_FWK_MSG_BIT (UINT64_C(1) << 31)
#define SPMD_FWK_MSG_FUNC_MASK UINT64_C(0xFF)
#define SPMD_FWK_MSG_PSCI UINT8_C(0)
#define SPMD_FWK_MSG_FFA_VERSION_REQ UINT8_C(0x8)
diff --git a/src/arch/aarch64/mm.c b/src/arch/aarch64/mm.c
index faccd67..64adfef 100644
--- a/src/arch/aarch64/mm.c
+++ b/src/arch/aarch64/mm.c
@@ -94,7 +94,7 @@
/* The following construct and destruct stage-2 memory attributes. */
#define STAGE2_MEMATTR(outer, inner) ((((outer) << 2) | (inner)) << 2)
-#define STAGE2_MEMATTR_TYPE_MASK UINT64_C(3 << 4)
+#define STAGE2_MEMATTR_TYPE_MASK (UINT64_C(3) << 4)
#define STAGE2_ACCESS_READ UINT64_C(1)
#define STAGE2_ACCESS_WRITE UINT64_C(2)
diff --git a/test/vmapi/ffa_secure_partitions/notifications.c b/test/vmapi/ffa_secure_partitions/notifications.c
index 4e9fab4..e78e82b 100644
--- a/test/vmapi/ffa_secure_partitions/notifications.c
+++ b/test/vmapi/ffa_secure_partitions/notifications.c
@@ -122,8 +122,9 @@
struct notif_cpu_entry_args *test_args =
// NOLINTNEXTLINE(performance-no-int-to-ptr)
(struct notif_cpu_entry_args *)arg;
- ffa_vcpu_index_t sp_vcpu_id =
- test_args->is_sp_up ? 0U : test_args->vcpu_id;
+ ffa_vcpu_index_t sp_vcpu_id = test_args->is_sp_up
+ ? ((ffa_vcpu_index_t)0)
+ : test_args->vcpu_id;
/*
* Make receiver SP reach message loop.
@@ -154,8 +155,9 @@
struct notif_cpu_entry_args *test_args =
// NOLINTNEXTLINE(performance-no-int-to-ptr)
(struct notif_cpu_entry_args *)arg;
- ffa_vcpu_index_t sp_vcpu_id =
- test_args->is_sp_up ? 0U : test_args->vcpu_id;
+ ffa_vcpu_index_t sp_vcpu_id = test_args->is_sp_up
+ ? ((ffa_vcpu_index_t)0)
+ : test_args->vcpu_id;
/*
* Make sender SP reach message loop.