[PATCH 03/12] file_list: Allow only unique names on list

Sascha Hauer s.hauer at pengutronix.de
Wed Sep 27 05:09:01 PDT 2017


The key to a file_list is it's name, so ensure it's unique.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/file-list.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/common/file-list.c b/common/file-list.c
index 0b760c1aec..e13d5af659 100644
--- a/common/file-list.c
+++ b/common/file-list.c
@@ -23,7 +23,13 @@ struct file_list_entry *file_list_entry_by_name(struct file_list *files, const c
 int file_list_add_entry(struct file_list *files, const char *name, const char *filename,
 			unsigned long flags)
 {
-	struct file_list_entry *entry = xzalloc(sizeof(*entry));
+	struct file_list_entry *entry;
+
+	entry = file_list_entry_by_name(files, name);
+	if (entry)
+		return -EEXIST;
+
+	entry = xzalloc(sizeof(*entry));
 
 	entry->name = xstrdup(name);
 	entry->filename = xstrdup(filename);
-- 
2.11.0




More information about the barebox mailing list