aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Piggin <npiggin@gmail.com>2023-09-06 20:10:12 +1000
committerReza Arbab <arbab@linux.ibm.com>2023-10-11 15:07:23 -0500
commitf79dea508d90f8fdaded75a52106c79b3d392871 (patch)
tree93bdb3f6aa9e794b37bd199ccf0e96193ff6b1be
parent3e6a0e728f21465f0f0bcbf60da8f8e71c924894 (diff)
downloadskiboot-f79dea508d90f8fdaded75a52106c79b3d392871.zip
skiboot-f79dea508d90f8fdaded75a52106c79b3d392871.tar.gz
skiboot-f79dea508d90f8fdaded75a52106c79b3d392871.tar.bz2
hdata: Use common code for HDIF header check
Make the HDIF header check use a common function. Signed-off-by: Nicholas Piggin <npiggin@gmail.com> Signed-off-by: Reza Arbab <arbab@linux.ibm.com>
-rw-r--r--hdata/hdif.c2
-rw-r--r--hdata/hdif.h10
2 files changed, 8 insertions, 4 deletions
diff --git a/hdata/hdif.c b/hdata/hdif.c
index 2dfa94c..13c128c 100644
--- a/hdata/hdif.c
+++ b/hdata/hdif.c
@@ -10,7 +10,7 @@ const void *HDIF_get_idata(const struct HDIF_common_hdr *hdif, unsigned int di,
const struct HDIF_common_hdr *hdr = hdif;
const struct HDIF_idata_ptr *iptr;
- if (be16_to_cpu(hdr->d1f0) != 0xd1f0) {
+ if (!HDIF_check(hdif, NULL)) {
prerror("HDIF: Bad header format !\n");
backtrace();
return NULL;
diff --git a/hdata/hdif.h b/hdata/hdif.h
index 52df0f1..38df6c2 100644
--- a/hdata/hdif.h
+++ b/hdata/hdif.h
@@ -63,12 +63,16 @@ struct HDIF_child_ptr {
.size = CPU_TO_BE32(_size), \
}
-static inline bool HDIF_check(const void *hdif, const char id[])
+static inline bool HDIF_check(const void *hdif, const char *id)
{
const struct HDIF_common_hdr *hdr = hdif;
- return hdr->d1f0 == CPU_TO_BE16(0xd1f0) &&
- memcmp(hdr->id, id, sizeof(hdr->id)) == 0;
+ if (hdr->d1f0 != CPU_TO_BE16(0xd1f0))
+ return false;
+ if (id && memcmp(hdr->id, id, sizeof(hdr->id)) != 0)
+ return false;
+
+ return true;
}
/* HDIF_get_idata - Get a pointer to internal data block