aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasant Hegde <hegdevasant@linux.vnet.ibm.com>2016-08-30 21:10:56 +0530
committerStewart Smith <stewart@linux.vnet.ibm.com>2016-10-11 15:40:22 +1100
commitedf57684bd6821d4d01515b6e599f477e04ca01d (patch)
tree84dd177a7f65ebc1ed103b1bd14bb5d688b3500f
parent5b43f79e3bebf4f504013c1155c2d23856324d91 (diff)
downloadskiboot-edf57684bd6821d4d01515b6e599f477e04ca01d.zip
skiboot-edf57684bd6821d4d01515b6e599f477e04ca01d.tar.gz
skiboot-edf57684bd6821d4d01515b6e599f477e04ca01d.tar.bz2
core/pel: Validate 'system-id' DT property before using
Platforms like mambo doesn't populate 'system-id' DT property. Validate these properties before using. Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com> [stewart@linux.vnet.ibm.com, memset(0) for not found dt props, fix unit test] Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
-rw-r--r--core/pel.c18
-rw-r--r--core/test/run-pel.c24
2 files changed, 33 insertions, 9 deletions
diff --git a/core/pel.c b/core/pel.c
index 5df3e91..d8c4b98 100644
--- a/core/pel.c
+++ b/core/pel.c
@@ -9,6 +9,8 @@
static void create_mtms_section(struct errorlog *elog_data,
char *pel_buffer, int *pel_offset)
{
+ const struct dt_property *p;
+
struct opal_mtms_section *mtms = (struct opal_mtms_section *)
(pel_buffer + *pel_offset);
@@ -20,10 +22,14 @@ static void create_mtms_section(struct errorlog *elog_data,
memset(mtms->model, 0x00, sizeof(mtms->model));
memcpy(mtms->model, dt_prop_get(dt_root, "model"), OPAL_SYS_MODEL_LEN);
+
memset(mtms->serial_no, 0x00, sizeof(mtms->serial_no));
+ p = dt_find_property(dt_root, "system-id");
+ if (p)
+ memcpy(mtms->serial_no, p->prop, OPAL_SYS_SERIAL_LEN);
+ else
+ memset(mtms->serial_no, 0, OPAL_SYS_SERIAL_LEN);
- memcpy(mtms->serial_no, dt_prop_get(dt_root, "system-id"),
- OPAL_SYS_SERIAL_LEN);
*pel_offset += MTMS_SECTION_SIZE;
}
@@ -32,6 +38,7 @@ static void create_extended_header_section(struct errorlog *elog_data,
char *pel_buffer, int *pel_offset)
{
const char *opalmodel = NULL;
+ const struct dt_property *p;
uint64_t extd_time;
struct opal_extended_header_section *extdhdr =
@@ -49,8 +56,11 @@ static void create_extended_header_section(struct errorlog *elog_data,
memcpy(extdhdr->model, opalmodel, OPAL_SYS_MODEL_LEN);
memset(extdhdr->serial_no, 0x00, sizeof(extdhdr->serial_no));
- memcpy(extdhdr->serial_no, dt_prop_get(dt_root, "system-id"),
- OPAL_SYS_SERIAL_LEN);
+ p = dt_find_property(dt_root, "system-id");
+ if (p)
+ memcpy(extdhdr->serial_no, p->prop, OPAL_SYS_SERIAL_LEN);
+ else
+ memset(extdhdr->serial_no, 0, OPAL_SYS_SERIAL_LEN);
memset(extdhdr->opal_release_version, 0x00,
sizeof(extdhdr->opal_release_version));
diff --git a/core/test/run-pel.c b/core/test/run-pel.c
index ab1fa05..433842b 100644
--- a/core/test/run-pel.c
+++ b/core/test/run-pel.c
@@ -25,6 +25,7 @@
#include <assert.h>
#include <pel.h>
#include <errorlog.h>
+#include <device.h>
#define TEST_ERROR 0x1234
#define TEST_SUBSYS 0x5678
@@ -33,14 +34,24 @@ DEFINE_LOG_ENTRY(TEST_ERROR, OPAL_PLATFORM_ERR_EVT, TEST_SUBSYS,
OPAL_PLATFORM_FIRMWARE, OPAL_INFO,
OPAL_NA);
+/* Override this for testing. */
+#define is_rodata(p) fake_is_rodata(p)
+
+char __rodata_start[16];
+#define __rodata_end (__rodata_start + sizeof(__rodata_start))
+
+static inline bool fake_is_rodata(const void *p)
+{
+ return ((char *)p >= __rodata_start && (char *)p < __rodata_end);
+}
+
+#define zalloc(bytes) calloc((bytes), 1)
+
+#include "../device.c"
#include "../pel.c"
struct dt_node *dt_root = NULL;
char dt_prop[] = "DUMMY DT PROP";
-const void *dt_prop_get(const struct dt_node *node __unused, const char *prop __unused)
-{
- return dt_prop;
-}
int rtc_cache_get_datetime(uint32_t *year_month_day,
uint64_t *hour_minute_second_millisecond)
@@ -60,6 +71,9 @@ int main(void)
char *buffer;
struct elog_user_data_section *tmp;
+ dt_root = dt_new_root("");
+ dt_add_property_string(dt_root, "model", "run-pel-unittest");
+
elog = malloc(sizeof(struct errorlog));
pel_buf = malloc(PEL_MIN_SIZE + 4);
assert(elog);
@@ -96,7 +110,7 @@ int main(void)
size = pel_size(elog);
pel_buf = realloc(pel_buf, size);
assert(pel_buf);
-
+
buffer = elog->user_data_dump + elog->user_section_size;
tmp = (struct elog_user_data_section *)buffer;
tmp->tag = 0x44455343; /* ASCII of DESC */