From 8f9625e71907b2d6400bcbd407414cd06302e85c Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Mon, 6 Aug 2018 18:08:16 +0300 Subject: [PATCH] bootrd_cpio: use SLIST from sys/queue.h There is no need to use double linked list and use the existing slist implementation. --- kernel/krtld/bootrd_cpio.c | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/kernel/krtld/bootrd_cpio.c b/kernel/krtld/bootrd_cpio.c index 4fb79b3d01..848e462133 100644 --- a/kernel/krtld/bootrd_cpio.c +++ b/kernel/krtld/bootrd_cpio.c @@ -20,6 +20,7 @@ #include #include #include +#include /* * A cpio archive is just a sequence of files, each consisting of a header @@ -55,8 +56,7 @@ struct cpio_file { off_t off; struct bootstat stat; - struct cpio_file *next; - struct cpio_file *prev; + SLIST_ENTRY(cpio_file) next; }; extern void *bkmem_alloc(size_t); @@ -65,7 +65,8 @@ extern void bkmem_free(void *, size_t); static void cpio_closeall(int flag); static bool mounted; -static struct cpio_file *open_files; +static SLIST_HEAD(cpio_file_list, cpio_file) + open_files = SLIST_HEAD_INITIALIZER(open_files); static int cpio_strcmp(const char *a, const char *b) @@ -153,21 +154,13 @@ get_int32(const uint8_t *str, size_t len, int32_t *out) static void add_open_file(struct cpio_file *file) { - file->next = open_files; - file->prev = NULL; - open_files = file; + SLIST_INSERT_HEAD(&open_files, file, next); } static void remove_open_file(struct cpio_file *file) { - if (file == open_files) - open_files = file->next; - else - file->prev->next = file->next; - - if (file->next != NULL) - file->next->prev = file->prev; + SLIST_REMOVE(&open_files, file, cpio_file, next); } static struct cpio_file * @@ -178,7 +171,7 @@ find_open_file(int fd) if (fd < 0) return NULL; - for (file = open_files; file != NULL; file = file->next) + SLIST_FOREACH(file, &open_files, next) if (file->fd == fd) return file; @@ -401,19 +394,13 @@ bcpio_close(int fd) static void bcpio_closeall(int flag) { - struct cpio_file *file, *next; - - file = open_files; - - while (file != NULL) { - int fd = file->fd; - - next = file->next; + struct cpio_file *file; - if (bcpio_close(fd) != 0) - printf("closeall invoked close(%d) failed\n", fd); + while (!SLIST_EMPTY(&open_files)) { + file = SLIST_FIRST(&open_files); - file = next; + if (bcpio_close(file->fd) != 0) + printf("closeall invoked close(%d) failed\n", file->fd); } } -- 2.11.4.GIT