summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorAngel Pons <th3fanbus@gmail.com>2020-11-02 20:35:05 +0100
committerPatrick Georgi <pgeorgi@google.com>2021-04-21 08:58:31 +0000
commit8d94b36eed2a182fab008e5477a4eddc4dd282df (patch)
tree3872a97b9593edc5fe91312f8f95453674dd9012 /src/include
parent7ac11ca3d64615d1c77e48d31b1730bd67582168 (diff)
downloadcoreboot-8d94b36eed2a182fab008e5477a4eddc4dd282df.tar.xz
option.h: Introduce {get,set}_int_option() functions
The {get,set}_option() functions are not type-safe: they take a pointer to void, without an associated length/size. Moreover, cmos_get_option() does not always fully initialise the destination value (it has no means to know how large it is), which can cause issues if the caller does not initialise the value beforehand. The idea behind this patch series is to replace the current type-unsafe API with a type-safe equivalent, and ultimately decouple the option API from CMOS. This would allow using different storage mechanisms with the same option system, maximising flexibility. Most, if not all users of get_option() have a value to fall back to, in case the option could not be read. Thus, get_int_option() takes a value to fall back to, which avoids repeating the same logic on call-sites. These new functions will be put to use in subsequent commits. Change-Id: I6bbc51135216f34518cfd05c3dc90fb68404c1cc Signed-off-by: Angel Pons <th3fanbus@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/47107 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Patrick Rudolph <siro@das-labor.org>
Diffstat (limited to 'src/include')
-rw-r--r--src/include/option.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/include/option.h b/src/include/option.h
index 6b4e6a9c9c..26cd0d5245 100644
--- a/src/include/option.h
+++ b/src/include/option.h
@@ -26,4 +26,15 @@ static inline enum cb_err get_option(void *dest, const char *name)
return CB_CMOS_OTABLE_DISABLED;
}
+static inline enum cb_err set_int_option(const char *name, int value)
+{
+ return set_option(name, &value);
+}
+
+static inline int get_int_option(const char *name, const int fallback)
+{
+ int value = 0;
+ return get_option(&value, name) == CB_SUCCESS ? value : fallback;
+}
+
#endif /* _OPTION_H_ */