Skip to content

Commit

Permalink
errorlog: endian conversion
Browse files Browse the repository at this point in the history
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
  • Loading branch information
npiggin authored and oohal committed Dec 16, 2019
1 parent e3934d8 commit 4ec92ec
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
14 changes: 8 additions & 6 deletions core/errorlog.c
Expand Up @@ -93,10 +93,10 @@ void log_add_section(struct errorlog *buf, uint32_t tag)
tmp = (struct elog_user_data_section *)(buf->user_data_dump +
buf->user_section_size);
/* Use DESC if no other tag provided */
tmp->tag = tag ? tag : 0x44455343;
tmp->size = size;
tmp->tag = tag ? cpu_to_be32(tag) : cpu_to_be32(0x44455343);
tmp->size = cpu_to_be16(size);

buf->user_section_size += tmp->size;
buf->user_section_size += size;
buf->user_section_count++;
}

Expand Down Expand Up @@ -133,6 +133,7 @@ void log_append_data(struct errorlog *buf, unsigned char *data, uint16_t size)
struct elog_user_data_section *section;
uint8_t n_sections;
char *buffer;
uint16_t ssize;

if (!buf) {
prerror("ELOG: Cannot update user data. Buffer is invalid\n");
Expand All @@ -154,13 +155,14 @@ void log_append_data(struct errorlog *buf, unsigned char *data, uint16_t size)

while (--n_sections) {
section = (struct elog_user_data_section *)buffer;
buffer += section->size;
buffer += be16_to_cpu(section->size);
}

section = (struct elog_user_data_section *)buffer;
buffer += section->size;
ssize = be16_to_cpu(section->size);
buffer += ssize;
memcpy(buffer, data, size);
section->size += size;
section->size = cpu_to_be16(ssize + size);
buf->user_section_size += size;
}

Expand Down
15 changes: 10 additions & 5 deletions core/pel.c
Expand Up @@ -211,16 +211,19 @@ static void create_user_defined_section(struct errorlog *elog_data,
opal_usr_data = (struct elog_user_data_section *)opal_buf;

usrhdr->v6header.id = ELOG_SID_USER_DEFINED;
usrhdr->v6header.length = cpu_to_be16(
sizeof(struct opal_v6_header) +
be16_to_cpu(opal_usr_data->size));
usrhdr->v6header.version = OPAL_ELOG_VERSION;
usrhdr->v6header.length = sizeof(struct opal_v6_header) +
opal_usr_data->size;
usrhdr->v6header.subtype = OPAL_ELOG_SST;
usrhdr->v6header.component_id = elog_data->component_id;

memcpy(usrhdr->dump, opal_buf, opal_usr_data->size);
memcpy(usrhdr->dump, opal_buf, be16_to_cpu(opal_usr_data->size));
*pel_offset += usrhdr->v6header.length;
dump += usrhdr->v6header.length;
opal_buf += opal_usr_data->size;
opal_buf += be16_to_cpu(opal_usr_data->size);
privhdr->section_count++;
}
}
Expand All @@ -233,10 +236,12 @@ static size_t pel_user_section_size(struct errorlog *elog_data)
struct elog_user_data_section *opal_usr_data;

for (i = 0; i < elog_data->user_section_count; i++) {
u16 s;

opal_usr_data = (struct elog_user_data_section *)opal_buf;
total += sizeof(struct opal_v6_header) +
opal_usr_data->size;
opal_buf += opal_usr_data->size;
s = be16_to_cpu(opal_usr_data->size);
total += sizeof(struct opal_v6_header) + s;
opal_buf += s;
}

return total;
Expand Down
12 changes: 6 additions & 6 deletions include/errorlog.h
Expand Up @@ -94,19 +94,19 @@
#define ORG_POWERNV 2

/* Multiple user data sections */
struct __attribute__((__packed__))elog_user_data_section {
uint32_t tag;
uint16_t size;
uint16_t component_id;
struct elog_user_data_section {
__be32 tag;
__be16 size;
__be16 component_id;
char data_dump[1];
};
} __packed;

/*
* All the information regarding an error/event to be reported
* needs to populate this structure using pre-defined interfaces
* only
*/
struct __attribute__((__packed__)) __attribute__ ((aligned (8))) errorlog {
struct errorlog {

uint16_t component_id;
uint8_t error_event_type;
Expand Down

0 comments on commit 4ec92ec

Please sign in to comment.