From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/2] file_list: implement file_list_add_cdev_entry
Date: Thu, 8 Jun 2023 09:24:17 +0200 [thread overview]
Message-ID: <20230608072418.3275633-1-a.fatoum@pengutronix.de> (raw)
Follow-up commit will add the two users that want to add a cdev,
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>
---
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
next reply other threads:[~2023-06-08 7:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-08 7:24 Ahmad Fatoum [this message]
2023-06-08 7:24 ` [PATCH 2/2] file-list: support special 'auto', 'block', 'nvmem' specifiers Ahmad Fatoum
2023-06-09 7:29 ` Sascha Hauer
2023-06-09 7:37 ` Ahmad Fatoum
2023-06-12 6:31 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230608072418.3275633-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox