Angel Pons has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/47107 )
Change subject: option.h: Add strongly-typed `get_option` wrappers ......................................................................
option.h: Add strongly-typed `get_option` wrappers
Most users of `get_option` have a value to fall back to in case there's an error. Introduce `read_option_X` wrappers that return the CMOS value on success and a specified fallback value on failure. Furthermore, they are strongly-typed to ease dropping the highly-unsafe `get_option` API.
Change-Id: I6bbc51135216f34518cfd05c3dc90fb68404c1cc Signed-off-by: Angel Pons th3fanbus@gmail.com --- M src/include/option.h 1 file changed, 18 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/07/47107/1
diff --git a/src/include/option.h b/src/include/option.h index 6b4e6a9..77f7056 100644 --- a/src/include/option.h +++ b/src/include/option.h @@ -26,4 +26,22 @@ return CB_CMOS_OTABLE_DISABLED; }
+/* + * Convenient, strongly-typed helpers. To avoid redundancy, generate + * them using a macro. The odd name is intentional, to ease grepping. + */ +#define __MAKE_read_option_(type) \ + static inline type read_option_ ## type (const char *name, const type fallback) \ + { \ + type value; \ + return get_option(&value, name) == CB_SUCCESS ? value : fallback; \ + } \ + +__MAKE_read_option_(u8) + +__MAKE_read_option_(int) + +/* Clean up */ +#undef __MAKE_read_option_ + #endif /* _OPTION_H_ */