[coreboot-gerrit] New patch to review for coreboot: cbfstool: Add way to access entire backing data for a buffer

Patrick Georgi (pgeorgi@google.com) gerrit at coreboot.org
Thu Nov 12 00:09:58 CET 2015


Patrick Georgi (pgeorgi at google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/12415

-gerrit

commit 42f743c0b68a9eb3a2aee377ae1bbcffaa7a776c
Author: Patrick Georgi <pgeorgi at google.com>
Date:   Wed Nov 11 18:43:11 2015 +0100

    cbfstool: Add way to access entire backing data for a buffer
    
    This is required to handle certain relative-to-flash-start offsets.
    
    BUG=none
    BRANCH=tot
    TEST=none
    
    Change-Id: I8b30c7b532e330af5db4b8ed65b21774c6cbbd25
    Signed-off-by: Patrick Georgi <pgeorgi at chromium.org>
    Original-Commit-Id: 596ba1aaa62aedb2b214ca55444e3068b9cb1044
    Original-Change-Id: Idc9a5279f16951befec4d84aab35117988f7edb7
    Original-Signed-off-by: Patrick Georgi <pgeorgi at google.com>
    Original-Reviewed-on: https://chromium-review.googlesource.com/312220
    Original-Commit-Ready: Patrick Georgi <pgeorgi at chromium.org>
    Original-Tested-by: Patrick Georgi <pgeorgi at chromium.org>
    Original-Reviewed-by: Aaron Durbin <adurbin at chromium.org>
---
 util/cbfstool/common.c | 2 +-
 util/cbfstool/common.h | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c
index 44836ab..09a7449 100644
--- a/util/cbfstool/common.c
+++ b/util/cbfstool/common.c
@@ -115,7 +115,7 @@ void buffer_delete(struct buffer *buffer)
 		buffer->name = NULL;
 	}
 	if (buffer->data) {
-		free(buffer->data - buffer->offset);
+		free(buffer_get_original_backing(buffer));
 		buffer->data = NULL;
 	}
 	buffer->offset = 0;
diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h
index b61c2c0..561a17a 100644
--- a/util/cbfstool/common.h
+++ b/util/cbfstool/common.h
@@ -120,6 +120,14 @@ static inline bool buffer_check_magic(const struct buffer *b, const char *magic,
 					memcmp(b->data, magic, magic_len) == 0;
 }
 
+/* Returns the start of the underlying buffer, with the offset undone */
+static inline void *buffer_get_original_backing(const struct buffer *b)
+{
+	if (!b)
+		return NULL;
+	return b->data - b->offset;
+}
+
 /* Creates an empty memory buffer with given size.
  * Returns 0 on success, otherwise non-zero. */
 int buffer_create(struct buffer *buffer, size_t size, const char *name);



More information about the coreboot-gerrit mailing list