[Skiboot] [PATCH 3/4] nvram: add nvram_query_def()

Oliver O'Halloran oohall at gmail.com
Wed Sep 28 14:56:31 AEST 2016


Adds a helper function that will return a default value if the key is
not found in the skiboot NVRAM partition.

Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
---
 core/nvram-format.c | 10 ++++++++++
 include/nvram.h     |  1 +
 2 files changed, 11 insertions(+)

diff --git a/core/nvram-format.c b/core/nvram-format.c
index b110d804ffb7..7ebfef72dd98 100644
--- a/core/nvram-format.c
+++ b/core/nvram-format.c
@@ -273,3 +273,13 @@ bool nvram_query_eq(const char *key, const char *value)
 
 	return !strcmp(s, value);
 }
+
+const char *nvram_query_def(const char *key, const char *def)
+{
+	const char *s = nvram_query(key);
+
+	if (!s)
+		return def;
+
+	return s;
+}
diff --git a/include/nvram.h b/include/nvram.h
index 288b536827b5..1be771ec9a52 100644
--- a/include/nvram.h
+++ b/include/nvram.h
@@ -23,6 +23,7 @@ void nvram_reinit(void);
 bool nvram_validate(void);
 
 const char *nvram_query(const char *name);
+const char *nvram_query_def(const char *key, const char *def);
 bool nvram_query_eq(const char *key, const char *value);
 
 #endif /* __NVRAM_H */
-- 
2.5.5



More information about the Skiboot mailing list