[PATCH 29/44] security: blobgen: add easy way to check for existent providers
Ahmad Fatoum
a.fatoum at barebox.org
Mon Aug 11 05:28:09 PDT 2025
blobgen_get() expects the user to name the blobgen instance to be used.
For general informational purposes, it would be nice to just check if
any provider is registered at all, so make that possible by accepting a
NULL filter argument.
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
include/blobgen.h | 7 +++++++
security/blobgen.c | 18 +++++++++++-------
2 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/include/blobgen.h b/include/blobgen.h
index 9f8876cee045..00674ef40f73 100644
--- a/include/blobgen.h
+++ b/include/blobgen.h
@@ -44,7 +44,14 @@ struct blobgen {
int blob_gen_register(struct device *dev, struct blobgen *bg);
+#ifdef CONFIG_BLOBGEN
struct blobgen *blobgen_get(const char *name);
+#else
+static inline struct blobgen *blobgen_get(const char *name)
+{
+ return NULL;
+}
+#endif
int blob_encrypt(struct blobgen *blg, const char *modifier, const void *plain,
int plainsize, void **blob, int *blobsize);
diff --git a/security/blobgen.c b/security/blobgen.c
index 0a4e192a271f..df42c8f6f1bc 100644
--- a/security/blobgen.c
+++ b/security/blobgen.c
@@ -50,24 +50,28 @@ int blob_gen_register(struct device *dev, struct blobgen *bg)
/**
* blobgen_get - get a blob generator of given name
- * @name: The name of the blob generator to look for
+ * @name: The name of the blob generator to look for or NULL
*
- * Finds a blob generator by name and returns it. Returns NULL if none is found.
+ * Finds a blob generator by name and returns it.
+ * If name is NULL, returns the first blob generator encountered.
+ * Returns NULL if none is found.
*/
struct blobgen *blobgen_get(const char *name)
{
- struct device *dev;
+ struct device *dev = NULL;
struct blobgen *bg;
if (!name)
return bg_default;
- dev = get_device_by_name(name);
- if (!dev)
- return NULL;
+ if (name) {
+ dev = get_device_by_name(name);
+ if (!dev)
+ return NULL;
+ }
list_for_each_entry(bg, &blobs, list) {
- if (dev == &bg->dev)
+ if (!dev || dev == &bg->dev)
return bg;
}
--
2.39.5
More information about the barebox
mailing list