summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2016-08-06 10:02:37 -0500
committerMartin Roth <martinroth@google.com>2016-08-09 19:53:21 +0200
commiteec1c28bd424ece0b60abda21912c4e8f51ff3ba (patch)
tree4eb83b8aa0f4b5bac7cafbd673727313cf3e096f /src
parent18fedb360f7ac3347782d97150657239632d3f3a (diff)
downloadcoreboot-eec1c28bd424ece0b60abda21912c4e8f51ff3ba.tar.xz
drivers/elog: provide return status for all operations
Instead of relying on global state to determine if an error occurred provide the ability to know if an add or shrink operation is successful. Now the call chains report the error back up the stack and out to the callers. BUG=chrome-os-partner:55932 Change-Id: Id4ed4d93e331f1bf16e038df69ef067446d00102 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/16104 Tested-by: build bot (Jenkins) Reviewed-by: Furquan Shaikh <furquan@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/drivers/elog/elog.c49
-rw-r--r--src/include/elog.h25
2 files changed, 36 insertions, 38 deletions
diff --git a/src/drivers/elog/elog.c b/src/drivers/elog/elog.c
index 9024cda89e..0981d777cc 100644
--- a/src/drivers/elog/elog.c
+++ b/src/drivers/elog/elog.c
@@ -503,7 +503,7 @@ static size_t elog_do_shrink(size_t requested_size, size_t last_write)
* Shrink the log, deleting old entries and moving the
* remaining ones to the front of the log.
*/
-static void elog_shrink_by_size(size_t requested_size)
+static int elog_shrink_by_size(size_t requested_size)
{
size_t shrunk_size;
size_t captured_last_write;
@@ -528,24 +528,20 @@ static void elog_shrink_by_size(size_t requested_size)
captured_last_write);
/* Add clear event */
- elog_add_event_word(ELOG_TYPE_LOG_CLEAR, shrunk_size);
+ return elog_add_event_word(ELOG_TYPE_LOG_CLEAR, shrunk_size);
}
static int elog_prepare_empty(void)
{
elog_debug("elog_prepare_empty()\n");
- elog_shrink_by_size(elog_events_total_space());
-
- if (elog_initialized != ELOG_INITIALIZED)
- return -1;
-
- return 0;
+ return elog_shrink_by_size(elog_events_total_space());
}
-static void elog_shrink(void)
+static int elog_shrink(void)
{
if (elog_should_shrink())
- elog_shrink_by_size(shrink_size);
+ return elog_shrink_by_size(shrink_size);
+ return 0;
}
/*
@@ -808,7 +804,7 @@ static void elog_fill_timestamp(struct event_header *event)
/*
* Add an event to the log
*/
-void elog_add_event_raw(u8 event_type, void *data, u8 data_size)
+int elog_add_event_raw(u8 event_type, void *data, u8 data_size)
{
struct event_header *event;
u8 event_size;
@@ -817,14 +813,14 @@ void elog_add_event_raw(u8 event_type, void *data, u8 data_size)
/* Make sure ELOG structures are initialized */
if (elog_init() < 0)
- return;
+ return -1;
/* Header + Data + Checksum */
event_size = sizeof(*event) + data_size + 1;
if (event_size > MAX_EVENT_SIZE) {
printk(BIOS_ERR, "ELOG: Event(%X) data size too "
"big (%d)\n", event_type, event_size);
- return;
+ return -1;
}
/* Make sure event data can fit */
@@ -832,7 +828,7 @@ void elog_add_event_raw(u8 event_type, void *data, u8 data_size)
if (event == NULL) {
printk(BIOS_ERR, "ELOG: Event(%X) does not fit\n",
event_type);
- return;
+ return -1;
}
/* Fill out event data */
@@ -854,37 +850,38 @@ void elog_add_event_raw(u8 event_type, void *data, u8 data_size)
event_type, event_size);
/* Shrink the log if we are getting too full */
- elog_shrink();
+ if (elog_shrink() < 0)
+ return -1;
/* Ensure the updates hit the non-volatile storage. */
- elog_sync_to_nv();
+ return elog_sync_to_nv();
}
-void elog_add_event(u8 event_type)
+int elog_add_event(u8 event_type)
{
- elog_add_event_raw(event_type, NULL, 0);
+ return elog_add_event_raw(event_type, NULL, 0);
}
-void elog_add_event_byte(u8 event_type, u8 data)
+int elog_add_event_byte(u8 event_type, u8 data)
{
- elog_add_event_raw(event_type, &data, sizeof(data));
+ return elog_add_event_raw(event_type, &data, sizeof(data));
}
-void elog_add_event_word(u8 event_type, u16 data)
+int elog_add_event_word(u8 event_type, u16 data)
{
- elog_add_event_raw(event_type, &data, sizeof(data));
+ return elog_add_event_raw(event_type, &data, sizeof(data));
}
-void elog_add_event_dword(u8 event_type, u32 data)
+int elog_add_event_dword(u8 event_type, u32 data)
{
- elog_add_event_raw(event_type, &data, sizeof(data));
+ return elog_add_event_raw(event_type, &data, sizeof(data));
}
-void elog_add_event_wake(u8 source, u32 instance)
+int elog_add_event_wake(u8 source, u32 instance)
{
struct elog_event_data_wake wake = {
.source = source,
.instance = instance
};
- elog_add_event_raw(ELOG_TYPE_WAKE_SOURCE, &wake, sizeof(wake));
+ return elog_add_event_raw(ELOG_TYPE_WAKE_SOURCE, &wake, sizeof(wake));
}
diff --git a/src/include/elog.h b/src/include/elog.h
index 3f949bf384..504c52e9a2 100644
--- a/src/include/elog.h
+++ b/src/include/elog.h
@@ -146,23 +146,24 @@ struct elog_event_data_me_extended {
/* Eventlog backing storage must be initialized before calling elog_init(). */
extern int elog_init(void);
extern int elog_clear(void);
-extern void elog_add_event_raw(u8 event_type, void *data, u8 data_size);
-extern void elog_add_event(u8 event_type);
-extern void elog_add_event_byte(u8 event_type, u8 data);
-extern void elog_add_event_word(u8 event_type, u16 data);
-extern void elog_add_event_dword(u8 event_type, u32 data);
-extern void elog_add_event_wake(u8 source, u32 instance);
+/* Event addition functions return < 0 on failure and 0 on success. */
+extern int elog_add_event_raw(u8 event_type, void *data, u8 data_size);
+extern int elog_add_event(u8 event_type);
+extern int elog_add_event_byte(u8 event_type, u8 data);
+extern int elog_add_event_word(u8 event_type, u16 data);
+extern int elog_add_event_dword(u8 event_type, u32 data);
+extern int elog_add_event_wake(u8 source, u32 instance);
extern int elog_smbios_write_type15(unsigned long *current, int handle);
#else
/* Stubs to help avoid littering sources with #if CONFIG_ELOG */
static inline int elog_init(void) { return -1; }
static inline int elog_clear(void) { return -1; }
-static inline void elog_add_event_raw(void) { return; }
-static inline void elog_add_event(u8 event_type) { return; }
-static inline void elog_add_event_byte(u8 event_type, u8 data) { return; }
-static inline void elog_add_event_word(u8 event_type, u16 data) { return; }
-static inline void elog_add_event_dword(u8 event_type, u32 data) { return; }
-static inline void elog_add_event_wake(u8 source, u32 instance) { return; }
+static inline int elog_add_event_raw(void) { return 0; }
+static inline int elog_add_event(u8 event_type) { return 0; }
+static inline int elog_add_event_byte(u8 event_type, u8 data) { return 0; }
+static inline int elog_add_event_word(u8 event_type, u16 data) { return 0; }
+static inline int elog_add_event_dword(u8 event_type, u32 data) { return 0; }
+static inline int elog_add_event_wake(u8 source, u32 instance) { return 0; }
static inline int elog_smbios_write_type15(unsigned long *current,
int handle) {
return 0;