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@xxxxxxxxxxxxxx> --- 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