mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: Michael Olbrich <mol@pengutronix.de>
Subject: [PATCH 7/8] cdev: create iterator for cdev list
Date: Mon,  7 Feb 2022 10:49:52 +0100	[thread overview]
Message-ID: <20220207094953.949868-7-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20220207094953.949868-1-s.hauer@pengutronix.de>

This creates an iterator to iterate over all availabe cdevs.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/devfs-core.c  | 10 +++++-----
 fs/devfs.c       |  4 +---
 include/driver.h |  4 ++++
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index c9a8529737..2f2882dcc8 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -37,7 +37,7 @@ int devfs_partition_complete(struct string_list *sl, char *instr)
 
 	len = strlen(instr);
 
-	list_for_each_entry(cdev, &cdev_list, list) {
+	for_each_cdev(cdev) {
 		if (cdev->master &&
 		    !strncmp(instr, cdev->name, len)) {
 			string_list_add_asprintf(sl, "%s ", cdev->name);
@@ -62,7 +62,7 @@ struct cdev *lcdev_by_name(const char *filename)
 {
 	struct cdev *cdev;
 
-	list_for_each_entry(cdev, &cdev_list, list) {
+	for_each_cdev(cdev) {
 		if (!strcmp(cdev->name, filename))
 			return cdev;
 	}
@@ -84,7 +84,7 @@ struct cdev *cdev_by_device_node(struct device_node *node)
 {
 	struct cdev *cdev;
 
-	list_for_each_entry(cdev, &cdev_list, list) {
+	for_each_cdev(cdev) {
 		if (!cdev->device_node)
 			continue;
 		if (cdev->device_node == node)
@@ -100,7 +100,7 @@ struct cdev *cdev_by_partuuid(const char *partuuid)
 	if (!partuuid)
 		return NULL;
 
-	list_for_each_entry(cdev, &cdev_list, list) {
+	for_each_cdev(cdev) {
 		if (cdev->master && !strcasecmp(cdev->uuid, partuuid))
 			return cdev;
 	}
@@ -114,7 +114,7 @@ struct cdev *cdev_by_diskuuid(const char *diskuuid)
 	if (!diskuuid)
 		return NULL;
 
-	list_for_each_entry(cdev, &cdev_list, list) {
+	for_each_cdev(cdev) {
 		if (!cdev->master && !strcasecmp(cdev->uuid, diskuuid))
 			return cdev;
 	}
diff --git a/fs/devfs.c b/fs/devfs.c
index d205881765..deb244feea 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -35,8 +35,6 @@ struct devfs_inode {
 	struct cdev *cdev;
 };
 
-extern struct list_head cdev_list;
-
 static int devfs_read(struct device_d *_dev, FILE *f, void *buf, size_t size)
 {
 	struct cdev *cdev = f->priv;
@@ -179,7 +177,7 @@ static int devfs_iterate(struct file *file, struct dir_context *ctx)
 
 	dir_emit_dots(file, ctx);
 
-	list_for_each_entry(cdev, &cdev_list, list) {
+	for_each_cdev(cdev) {
 		dir_emit(ctx, cdev->name, strlen(cdev->name),
 				1 /* FIXME */, DT_REG);
 	}
diff --git a/include/driver.h b/include/driver.h
index b9b0b8497d..79d287ec31 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -510,6 +510,10 @@ int cdev_memmap(struct cdev*, void **map, int flags);
 int cdev_truncate(struct cdev*, size_t size);
 loff_t cdev_unallocated_space(struct cdev *cdev);
 
+extern struct list_head cdev_list;
+#define for_each_cdev(c) \
+	list_for_each_entry(cdev, &cdev_list, list)
+
 #define DEVFS_PARTITION_FIXED		(1U << 0)
 #define DEVFS_PARTITION_READONLY	(1U << 1)
 #define DEVFS_IS_CHARACTER_DEV		(1U << 3)
-- 
2.30.2


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


  parent reply	other threads:[~2022-02-07  9:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-07  9:49 [PATCH 1/8] cdev: rename partuuid to uuid Sascha Hauer
2022-02-07  9:49 ` [PATCH 2/8] cdev: add diskuuid support Sascha Hauer
2022-02-07  9:49 ` [PATCH 3/8] rename cdev_open() -> cdev_open_name() Sascha Hauer
2022-02-07 10:43   ` Ahmad Fatoum
2022-02-07  9:49 ` [PATCH 4/8] cdev: implement cdev_open() Sascha Hauer
2022-02-07 10:46   ` Ahmad Fatoum
2022-02-07  9:49 ` [PATCH 5/8] driver: Add functions to free devices Sascha Hauer
2022-02-07  9:49 ` [PATCH 6/8] cdev: Create missing cdev_* functions Sascha Hauer
2022-02-07  9:49 ` Sascha Hauer [this message]
2022-02-07  9:49 ` [PATCH 8/8] misc: Add storage-by-uuid driver Sascha Hauer
2022-02-07  9:52   ` Sascha Hauer
2022-02-07 10:59   ` [PATCH] efi: probe devices from the device-tree Michael Olbrich
2022-02-08  9:29   ` [PATCH 8/8] misc: Add storage-by-uuid driver Michael Olbrich
2022-02-08 12:27     ` 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=20220207094953.949868-7-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=mol@pengutronix.de \
    /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