Attention is currently required from: Ricardo Quesada, Jack Rosenthal. Furquan Shaikh has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/57395 )
Change subject: elogtool: add next_available_event_offset function ......................................................................
Patch Set 1:
(2 comments)
File util/cbfstool/elogtool.c:
https://review.coreboot.org/c/coreboot/+/57395/comment/56f89b8a_54ce9e29 PS1, Line 118: static int next_available_event_offset(const struct buffer *buf) : { : const struct event_header *event; : int offset = sizeof(struct elog_header); : : event = buffer_get(buf) + offset; : while ((const void *)(event) < buffer_end(buf)) { : if (event->type == ELOG_TYPE_EOL || event->length == 0) : break; : : offset += event->length; : assert((size_t)offset <= buffer_size(buf) && "Out of bounds"); : event = elog_get_next_event(event); : } : return offset; : } Couple of things:
1. Instead of taking the input buffer as is, if this function takes a buffer that points to the first event, things can be somewhat simplified for this function and the caller.
2. The math for adjusting offset can be dropped (almost) completely by using buffer operations.
I am thinking something like this: ``` static size_t next_available_event_offset(const struct buffer *buf) { » const struct event_header *event; » struct buffer copy, *iter = ©
» while (buffer_size(iter) >= sizeof(struct event_header)) { » » event = buffer_get(iter); » » if (event->type == ELOG_TYPE_EOL || event->length == 0) » » » break;
» » assert(event->length <= buffer_size(iter)); » » buffer_seek(event->length); » }
» return buffer_offset(iter) - buffer_offset(buf); } ```
What do you think?
https://review.coreboot.org/c/coreboot/+/57395/comment/976672f0_16fafd53 PS1, Line 172: memset(start + sizeof(struct elog_header), ELOG_TYPE_EOL, : buffer_size(b) - sizeof(struct elog_header)); Continuing the comment above, this function can be reorganized as:
``` static int cmd_clear(const struct buffer *b) { » struct buffer buf; » size_t used_data_size;
» buffer_clone(&buf, b); » buffer_seek(&buf, sizeof(struct elog_header));
» used_data_size = next_available_event_offset(&buf); » memset(buffer_get(&buf), ELOG_TYPE_EOL, buffer_size(&buf));
» [...] } ```