[coreboot-gerrit] New patch to review for coreboot: 9fe6f67 libpayload: cbfs: Fix ram_media map() error return value

Patrick Georgi (pgeorgi@google.com) gerrit at coreboot.org
Thu Mar 19 13:12:42 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/8758

-gerrit

commit 9fe6f672b4d89774ac6fb5d31b375f0a45bafbe3
Author: Julius Werner <jwerner at chromium.org>
Date:   Tue Jan 6 21:34:19 2015 -0800

    libpayload: cbfs: Fix ram_media map() error return value
    
    The correct return value for errors on a cbfs_media->map() call is
    CBFS_MEDIA_INVALID_MAP_ADDRESS, not NULL. Not sure if that's the best
    choice (since 0xffffffff is probably a more likely valid address than 0
    there), but that's what the upper layers expect right now.
    
    BRANCH=veyron
    BUG=None
    TEST=Press CTRL+L with an RW_LEGACY section filled with 0xff. Observe
    how cbfs_get_header() returns failure without doing a bunch of NULL
    pointer accesses first (not that those have any visible effect on
    Veyron, but that's another problem...)
    
    Change-Id: I3d012fc9af9da6e01159990a6bdd62c38fc22329
    Signed-off-by: Patrick Georgi <pgeorgi at chromium.org>
    Original-Commit-Id: 3a609e17bb9b0ef4d3a833f72fa4fbfd8e8cb0ab
    Original-Change-Id: I0793434116a8c568e19fe0dee24f13942fc50f25
    Original-Signed-off-by: Julius Werner <jwerner at chromium.org>
    Original-Reviewed-on: https://chromium-review.googlesource.com/238991
    Original-Reviewed-by: Hung-Te Lin <hungte at chromium.org>
---
 payloads/libpayload/libcbfs/ram_media.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/payloads/libpayload/libcbfs/ram_media.c b/payloads/libpayload/libcbfs/ram_media.c
index 3d9abf0..d5469f6 100644
--- a/payloads/libpayload/libcbfs/ram_media.c
+++ b/payloads/libpayload/libcbfs/ram_media.c
@@ -51,7 +51,7 @@ static void *ram_map(struct cbfs_media *media, size_t offset, size_t count) {
 	if (offset + count > m->size) {
 		printf("ERROR: ram_map: request out of range (0x%zx+0x%zx)\n",
 		       offset, count);
-		return NULL;
+		return CBFS_MEDIA_INVALID_MAP_ADDRESS;
 	}
 	return (void*)(m->start + offset);
 }
@@ -63,6 +63,8 @@ static void *ram_unmap(struct cbfs_media *media, const void *address) {
 static size_t ram_read(struct cbfs_media *media, void *dest, size_t offset,
 			   size_t count) {
 	void *ptr = ram_map(media, offset, count);
+	if (ptr == CBFS_MEDIA_INVALID_MAP_ADDRESS)
+		return 0;
 	memcpy(dest, ptr, count);
 	ram_unmap(media, ptr);
 	return count;



More information about the coreboot-gerrit mailing list