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: I0793434116a8c568e19fe0dee24f13942fc50f25
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/238991
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/242150
This commit is contained in:
Julius Werner 2015-01-06 21:34:19 -08:00 committed by ChromeOS Commit Bot
commit d5a460c8c7

View file

@ -52,7 +52,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);
}
@ -64,6 +64,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;