fix(libtl): typecast expression to match data type
This corrects the MISRA violation C2012-10.1:
Operands shall not be of an inappropriate essential type.
The original code used an expression of a non-Boolean essential type
in a Boolean context. To comply with the rule, the expression has been
replaced with an explicit comparison to a Boolean-compatible
value (e.g., == NULL, != 0U, ensuring clarity and type safety.
Change-Id: Iac29e26415267e6287b523e1535fcda1d4fcf0de
Signed-off-by: Pranav Tilak <pranav.vinaytilak@amd.com>
diff --git a/include/logging.h b/include/logging.h
index fdfb2cd..6cd1ab6 100644
--- a/include/logging.h
+++ b/include/logging.h
@@ -15,16 +15,16 @@
extern struct logger_interface *logger;
-#define info(...) \
- do { \
- if (logger && logger->info) \
- logger->info(__VA_ARGS__); \
+#define info(...) \
+ do { \
+ if ((logger != NULL) && (logger->info != NULL)) \
+ logger->info(__VA_ARGS__); \
} while (0)
-#define warn(...) \
- do { \
- if (logger && logger->warn) \
- logger->warn(__VA_ARGS__); \
+#define warn(...) \
+ do { \
+ if ((logger != NULL) && (logger->warn != NULL)) \
+ logger->warn(__VA_ARGS__); \
} while (0)
#define error(...) \
diff --git a/src/generic/transfer_list.c b/src/generic/transfer_list.c
index b9a676a..884db56 100644
--- a/src/generic/transfer_list.c
+++ b/src/generic/transfer_list.c
@@ -18,7 +18,7 @@
struct transfer_list_entry *te = NULL;
uint32_t i = 0U;
- if (!tl) {
+ if (tl == NULL) {
return;
}
info("Dump transfer list:\n");
@@ -32,7 +32,7 @@
info("flags 0x%x\n", tl->flags);
while (true) {
te = transfer_list_next(tl, te);
- if (!te) {
+ if (te == NULL) {
break;
}
@@ -120,7 +120,7 @@
enum transfer_list_ops
transfer_list_check_header(const struct transfer_list_header *tl)
{
- if (!tl) {
+ if (tl == NULL) {
return TL_OPS_NON;
}
@@ -130,7 +130,7 @@
return TL_OPS_NON;
}
- if (!tl->max_size) {
+ if (tl->max_size == 0U) {
warn("Bad transfer list max size %#" PRIx32 "\n", tl->max_size);
return TL_OPS_NON;
}
@@ -175,7 +175,7 @@
uintptr_t ev = 0;
size_t sz = 0;
- if (!tl) {
+ if (tl == NULL) {
return NULL;
}
@@ -263,15 +263,15 @@
bool transfer_list_verify_checksum(const struct transfer_list_header *tl)
{
- if (!tl) {
+ if (tl == NULL) {
return false;
}
- if (!(tl->flags & TL_FLAGS_HAS_CHECKSUM)) {
+ if ((tl->flags & TL_FLAGS_HAS_CHECKSUM) == 0U) {
return true;
}
- return !calc_byte_sum(tl);
+ return (calc_byte_sum(tl) == 0U);
}
bool transfer_list_set_data_size(struct transfer_list_header *tl,
@@ -488,14 +488,14 @@
do {
te = transfer_list_next(tl, te);
- } while (te && (te->tag_id != tag_id));
+ } while ((te != NULL) && (te->tag_id != tag_id));
return te;
}
void *transfer_list_entry_data(struct transfer_list_entry *entry)
{
- if (!entry) {
+ if (entry == NULL) {
return NULL;
}
return (uint8_t *)entry + entry->hdr_size;