From 60fd684698e7da894d539936307aea94d0c83bd1 Mon Sep 17 00:00:00 2001 From: "Ronald G. Minnich" Date: Mon, 14 May 2018 13:27:07 -0700 Subject: cbfs_locate: Optionally return file type In some cases callers want to know if a file exists and, if so, what its type is. Modify cbfs_locate so that if the pointer is non-NULL, but has the value 0, the type of the file that matches the name will be returned. Change-Id: Ic1349d358c3054207ccbccf3825db56784327ad0 Signed-off-by: Ronald G. Minnich Reviewed-on: https://review.coreboot.org/26279 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi --- src/commonlib/cbfs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/commonlib/cbfs.c b/src/commonlib/cbfs.c index 1db8d31acf2a..e14e6c5e6125 100644 --- a/src/commonlib/cbfs.c +++ b/src/commonlib/cbfs.c @@ -212,12 +212,18 @@ int cbfs_locate(struct cbfsf *fh, const struct region_device *cbfs, if (cbfsf_file_type(fh, &ftype)) break; - if (*type != ftype) { + if (*type != 0 && *type != ftype) { DEBUG(" Unmatched type %x at %zx\n", ftype, rdev_relative_offset(cbfs, &fh->metadata)); continue; } + // *type being 0 means we want to know ftype. + // We could just do a blind assignment but + // if type is pointing to read-only memory + // that might be bad. + if (*type == 0) + *type = ftype; } LOG("Found @ offset %zx size %zx\n", -- cgit v1.2.3