mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/2] file_list: implement file_list_add_cdev_entry
@ 2023-06-09  7:52 Ahmad Fatoum
  2023-06-09  7:52 ` [PATCH v2 2/2] file-list: support special 'auto', 'block' specifiers Ahmad Fatoum
  0 siblings, 1 reply; 3+ messages in thread
From: Ahmad Fatoum @ 2023-06-09  7:52 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Follow-up commit will add a first user that wants to add a cdev
and more may follow, so let's provide a common
file_list_add_cdev_entry they can call.

The benefit of doing that in common/file-list.c is that we can avoid
an extra allocation for prefixing /dev.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> 2:
  - slightly reworded commit message to align it with 2nd commit
---
 common/file-list.c  | 21 +++++++++++++++++----
 include/file-list.h |  5 +++++
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/common/file-list.c b/common/file-list.c
index 1dc7cd8266b1..5c7020111145 100644
--- a/common/file-list.c
+++ b/common/file-list.c
@@ -26,8 +26,8 @@ struct file_list_entry *file_list_entry_by_name(struct file_list *files, const c
 	return NULL;
 }
 
-int file_list_add_entry(struct file_list *files, const char *name, const char *filename,
-			unsigned long flags)
+static int __file_list_add_entry(struct file_list *files, char *name, char *filename,
+				 unsigned long flags)
 {
 	struct file_list_entry *entry;
 
@@ -37,8 +37,8 @@ int file_list_add_entry(struct file_list *files, const char *name, const char *f
 
 	entry = xzalloc(sizeof(*entry));
 
-	entry->name = xstrdup(name);
-	entry->filename = xstrdup(filename);
+	entry->name = name;
+	entry->filename = filename;
 	entry->flags = flags;
 
 	list_add_tail(&entry->list, &files->list);
@@ -46,6 +46,19 @@ int file_list_add_entry(struct file_list *files, const char *name, const char *f
 	return 0;
 }
 
+int file_list_add_entry(struct file_list *files, const char *name, const char *filename,
+			unsigned long flags)
+{
+	return __file_list_add_entry(files, xstrdup(name), xstrdup(filename), flags);
+}
+
+int file_list_add_cdev_entry(struct file_list *files, struct cdev *cdev,
+			     unsigned long flags)
+{
+	return __file_list_add_entry(files, xstrdup(cdev->name),
+				     xasprintf("/dev/%s", cdev->name), flags);
+}
+
 static int file_list_parse_one(struct file_list *files, const char *partstr, const char **endstr)
 {
 	int i = 0, state = PARSE_DEVICE;
diff --git a/include/file-list.h b/include/file-list.h
index 2b2003971f32..79190b0f191d 100644
--- a/include/file-list.h
+++ b/include/file-list.h
@@ -4,6 +4,8 @@
 
 #include <linux/list.h>
 
+struct cdev;
+
 #define FILE_LIST_FLAG_SAFE	(1 << 0)
 #define FILE_LIST_FLAG_READBACK	(1 << 1)
 #define FILE_LIST_FLAG_CREATE	(1 << 2)
@@ -30,6 +32,9 @@ void file_list_free(struct file_list *);
 int file_list_add_entry(struct file_list *files, const char *name, const char *filename,
 			unsigned long flags);
 
+int file_list_add_cdev_entry(struct file_list *files, struct cdev *cdev,
+			     unsigned long flags);
+
 struct file_list *file_list_new(void);
 struct file_list *file_list_dup(struct file_list *old);
 
-- 
2.39.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-09  7:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-09  7:52 [PATCH v2 1/2] file_list: implement file_list_add_cdev_entry Ahmad Fatoum
2023-06-09  7:52 ` [PATCH v2 2/2] file-list: support special 'auto', 'block' specifiers Ahmad Fatoum
2023-06-09  7:55   ` Ahmad Fatoum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox