mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Lucas Stach <l.stach@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 06/12] fs: efivar: switch to standard list implementation
Date: Mon,  8 Dec 2014 14:42:33 +0100	[thread overview]
Message-ID: <1418046159-29843-6-git-send-email-l.stach@pengutronix.de> (raw)
In-Reply-To: <1418046159-29843-1-git-send-email-l.stach@pengutronix.de>

Cleans the code a bit and will allow us to implement
removing of vars quite a bit easier.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
 fs/efivarfs.c | 34 +++++++++++++---------------------
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/fs/efivarfs.c b/fs/efivarfs.c
index 4e13c8365e0e..fda5d7449e4f 100644
--- a/fs/efivarfs.c
+++ b/fs/efivarfs.c
@@ -196,12 +196,12 @@ static loff_t efivarfs_lseek(struct device_d *dev, FILE *f, loff_t pos)
 
 struct efivarfs_dir_entry {
 	char *name;
-	struct efivarfs_dir_entry *next;
+	struct list_head node;
 };
 
 struct efivarfs_dir {
-	struct efivarfs_dir_entry *first;
-	struct efivarfs_dir_entry *current;
+	struct list_head entries;
+	struct list_head *current;
 	DIR dir;
 };
 
@@ -217,6 +217,7 @@ static DIR *efivarfs_opendir(struct device_d *dev, const char *pathname)
 	name[0] = 0;
 
 	edir = xzalloc(sizeof(*edir));
+	INIT_LIST_HEAD(&edir->entries);
 
 	while (1) {
 		struct efivarfs_dir_entry *entry;
@@ -230,19 +231,12 @@ static DIR *efivarfs_opendir(struct device_d *dev, const char *pathname)
 		name8 = strdup_wchar_to_char(name);
 
 		entry->name = asprintf("%s-%pUl", name8, &vendor);
-
 		free(name8);
 
-		if (!edir->first)
-			edir->first = entry;
-
-		if (edir->current)
-			edir->current->next = entry;
-
-		edir->current = entry;
+		list_add_tail(&entry->node, &edir->entries);
 	}
 
-	edir->current = edir->first;
+	edir->current = edir->entries.next;
 
 	return &edir->dir;
 }
@@ -250,11 +244,14 @@ static DIR *efivarfs_opendir(struct device_d *dev, const char *pathname)
 static struct dirent *efivarfs_readdir(struct device_d *dev, DIR *dir)
 {
 	struct efivarfs_dir *edir = container_of(dir, struct efivarfs_dir, dir);
+	struct efivarfs_dir_entry *entry;
 
-	if (!edir->current)
+	if (edir->current == &edir->entries)
 		return NULL;
 
-	strcpy(dir->d.d_name, edir->current->name);
+	entry = list_entry(edir->current, struct efivarfs_dir_entry, node);
+
+	strcpy(dir->d.d_name, entry->name);
 
 	edir->current = edir->current->next;
 
@@ -264,16 +261,11 @@ static struct dirent *efivarfs_readdir(struct device_d *dev, DIR *dir)
 static int efivarfs_closedir(struct device_d *dev, DIR *dir)
 {
 	struct efivarfs_dir *edir = container_of(dir, struct efivarfs_dir, dir);
-	struct efivarfs_dir_entry *entry;
-
-	entry = edir->first;
+	struct efivarfs_dir_entry *entry, *tmp;
 
-	while (entry) {
-		struct efivarfs_dir_entry *tmp;
+	list_for_each_entry_safe(entry, tmp, &edir->entries, node) {
 		free(entry->name);
-		tmp = entry->next;
 		free(entry);
-		entry = tmp;
 	}
 
 	free(edir);
-- 
2.1.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2014-12-08 13:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-08 13:42 [PATCH 01/12] efi: add function to determine type of device path Lucas Stach
2014-12-08 13:42 ` [PATCH 02/12] efi: add proper reset hook Lucas Stach
2014-12-08 13:42 ` [PATCH 03/12] efi: move exit to EFI into own command Lucas Stach
2014-12-08 13:42 ` [PATCH 04/12] efi: add Barebox GUID Lucas Stach
2014-12-08 13:42 ` [PATCH 05/12] fs: efivars: cosmetic changes Lucas Stach
2014-12-08 13:42 ` Lucas Stach [this message]
2014-12-08 13:42 ` [PATCH 07/12] fs: efivar: move variable discovery into probe Lucas Stach
2014-12-08 13:42 ` [PATCH 08/12] lib: add wchar strdup Lucas Stach
2014-12-08 13:42 ` [PATCH 09/12] fs: efivar: preserve more info in inode Lucas Stach
2014-12-08 13:42 ` [PATCH 10/12] fs: efivars: don't store attributes in file Lucas Stach
2014-12-08 13:42 ` [PATCH 11/12] fs: efivars: implement write support Lucas Stach
2014-12-08 13:42 ` [PATCH 12/12] efi: mount efivarfs by default if enabled Lucas Stach
2014-12-09  8:59 ` [PATCH 01/12] efi: add function to determine type of device path 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=1418046159-29843-6-git-send-email-l.stach@pengutronix.de \
    --to=l.stach@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