mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 05/44] lib: param: add dev_for_each_param helpers
Date: Mon, 11 Aug 2025 14:27:45 +0200	[thread overview]
Message-ID: <20250811122824.1667791-6-a.fatoum@barebox.org> (raw)
In-Reply-To: <20250811122824.1667791-1-a.fatoum@barebox.org>

Instead of open-coding the linked list iterations, let's define some
macros to wrap them. This will come in handy when we associate the
parameters with the bobject instead of the device as we will only have
to adjust the macro definitions.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 commands/devinfo.c |  2 +-
 commands/varinfo.c |  2 +-
 common/complete.c  |  2 +-
 common/globalvar.c | 16 ++++++++--------
 include/device.h   |  5 +++++
 lib/parameter.c    |  2 +-
 6 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/commands/devinfo.c b/commands/devinfo.c
index 3c791e4464ac..cff4dbb92e31 100644
--- a/commands/devinfo.c
+++ b/commands/devinfo.c
@@ -88,7 +88,7 @@ static int do_devinfo(int argc, char *argv[])
 			printf("Parent: %s\n", dev_name(dev->parent));
 
 		first = true;
-		list_for_each_entry(param, &dev->parameters, list) {
+		dev_for_each_param(dev, param) {
 			if (first) {
 				printf("Parameters:\n");
 				first = false;
diff --git a/commands/varinfo.c b/commands/varinfo.c
index 5965c60159ca..eff7bf423cce 100644
--- a/commands/varinfo.c
+++ b/commands/varinfo.c
@@ -56,7 +56,7 @@ static int do_varinfo(int argc, char *argv[])
 	if (!dev)
 		return -ENODEV;
 
-	list_for_each_entry(param, &dev->parameters, list) {
+	dev_for_each_param(dev, param) {
 		if (prefix && !strstarts(param->name, prefix))
 			continue;
 
diff --git a/common/complete.c b/common/complete.c
index 5327944ca93b..a01ce9b47163 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -179,7 +179,7 @@ static int device_param_complete(struct device *dev, const char *devname,
 {
 	struct param_d *param;
 
-	list_for_each_entry(param, &dev->parameters, list) {
+	dev_for_each_param(dev, param) {
 		if (!strstarts_escaped(param->name, instr))
 			continue;
 
diff --git a/common/globalvar.c b/common/globalvar.c
index 1ef98f44bc67..cca1ac9b39f5 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -35,7 +35,7 @@ void globalvar_remove(const char *name)
 {
 	struct param_d *p, *tmp;
 
-	list_for_each_entry_safe(p, tmp, &global_device.parameters, list) {
+	dev_for_each_param_safe(&global_device, p, tmp) {
 		if (fnmatch(name, p->name, 0))
 			continue;
 
@@ -276,7 +276,7 @@ int nvvar_remove(const char *name)
 	if (!IS_ENABLED(CONFIG_NVVAR))
 		return -ENOSYS;
 
-	list_for_each_entry_safe(p, tmp, &nv_device.parameters, list) {
+	dev_for_each_param_safe(&nv_device, p, tmp) {
 		if (fnmatch(name, p->name, 0))
 			continue;
 
@@ -382,7 +382,7 @@ static void device_param_print(struct device *dev)
 {
 	struct param_d *param;
 
-	list_for_each_entry(param, &dev->parameters, list) {
+	dev_for_each_param(dev, param) {
 		const char *p = dev_get_param(dev, param->name);
 		const char *nv = NULL;
 
@@ -420,7 +420,7 @@ char *globalvar_get_match(const char *match, const char *separator)
 	char *val = NULL;
 	struct param_d *param;
 
-	list_for_each_entry(param, &global_device.parameters, list) {
+	dev_for_each_param(&global_device, param) {
 		if (!strncmp(match, param->name, strlen(match))) {
 			const char *p = dev_get_param(&global_device, param->name);
 			if (val) {
@@ -444,7 +444,7 @@ void globalvar_set_match(const char *match, const char *val)
 {
 	struct param_d *param;
 
-	list_for_each_entry(param, &global_device.parameters, list) {
+	dev_for_each_param(&global_device, param) {
 		if (!strncmp(match, param->name, strlen(match)))
 			dev_set_param(&global_device, param->name, val);
 	}
@@ -723,7 +723,7 @@ int nvvar_save(void)
 	envfs_load(env, TMPDIR, 0);
 	unlink_recursive(TMPDIR "/nv", NULL);
 
-	list_for_each_entry(param, &nv_device.parameters, list) {
+	dev_for_each_param(&nv_device, param) {
 		ret = __nv_save(TMPDIR "/nv", param->name,
 				dev_get_param(&nv_device, param->name));
 		if (ret) {
@@ -760,7 +760,7 @@ static int nv_global_param_complete(struct device *dev,
 
 	len = strlen(instr);
 
-	list_for_each_entry(param, &dev->parameters, list) {
+	dev_for_each_param(dev, param) {
 		if (strncmp(instr, param->name, len))
 			continue;
 
@@ -790,7 +790,7 @@ int nv_complete(struct string_list *sl, char *instr)
 		if (dev == &global_device || dev == &nv_device)
 			continue;
 
-		list_for_each_entry(param, &dev->parameters, list) {
+		dev_for_each_param(dev, param) {
 			str = basprintf("dev.%s.%s=", dev_name(dev), param->name);
 			if (strncmp(instr, str, len))
 				free(str);
diff --git a/include/device.h b/include/device.h
index 8b65693d9672..1158ec59b5e8 100644
--- a/include/device.h
+++ b/include/device.h
@@ -162,6 +162,11 @@ extern struct list_head class_list;
 
 #define class_for_each(class) list_for_each_entry((class), &class_list, list)
 
+#define dev_for_each_param(dev, param) \
+	list_for_each_entry((param), &(dev)->parameters, list)
+#define dev_for_each_param_safe(dev, param, tmp) \
+	list_for_each_entry_safe((param), (tmp), &(dev)->parameters, list)
+
 struct device_alias {
 	struct device *dev;
 	struct list_head list;
diff --git a/lib/parameter.c b/lib/parameter.c
index 584876bbc24b..c550de050db0 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -1026,7 +1026,7 @@ void dev_remove_parameters(struct device *dev)
 {
 	struct param_d *p, *n;
 
-	list_for_each_entry_safe(p, n, &dev->parameters, list)
+	dev_for_each_param_safe(dev, p, n)
 		param_remove(p);
 }
 
-- 
2.39.5




  parent reply	other threads:[~2025-08-11 12:29 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-11 12:27 [PATCH 00/44] commands: add bfetch/buds of command redirection Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 01/44] driver: move device name definition into device.h Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 02/44] driver: introduce common struct bobject Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 03/44] lib: param: rename dev_remove_param to param_remove Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 04/44] param: implement dev_remove_parameters using param_remove Ahmad Fatoum
2025-08-11 12:27 ` Ahmad Fatoum [this message]
2025-08-11 12:27 ` [PATCH 06/44] driver: initialize device parameters as part of bobject Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 07/44] param: operate on bobjects instead of full devices Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 08/44] commands: version: print value of CONFIG_NAME Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 09/44] treewide: populate CONFIG_NAME for all configs in-tree Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 10/44] test: py: change barebox_config from set to dict Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 11/44] test: add heuristic for guessing labgrid environment YAML Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 12/44] usb: drop dead iSerialNumber parameter addition Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 13/44] drivers: use dev_add_param_uint32_fixed for IDs Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 14/44] param: make bobject_add_param_fixed variadic Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 15/44] param: handle NULL gracefully in bobject_get_param Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 16/44] common: introduce structured I/O Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 17/44] ARM: cpuinfo: support structio output Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 18/44] commands: uptime: enable structured I/O Ahmad Fatoum
2025-08-11 12:27 ` [PATCH 19/44] string: implement strv_length helper Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 20/44] ARM: psci: client: add PSCI version/method parameters Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 21/44] net: move netmask_to_prefix into header Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 22/44] stringlist: implement string_list_empty Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 23/44] optee: add revision info to tee devinfo output Ahmad Fatoum
2025-08-12  9:35   ` Sascha Hauer
2025-08-12  9:44     ` Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 24/44] tee: enable structured I/O in devinfo handler Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 25/44] mtd: add devices to new mtd class Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 26/44] nvmem: add devices to new nvmem class Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 27/44] nvmem: export functions to query NVMEM size Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 28/44] video: add devices to new fb class Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 29/44] security: blobgen: add easy way to check for existent providers Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 30/44] pmdomain: add easy way to check for provider support Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 31/44] bbu: add easy way to check for existent providers Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 32/44] firmware: " Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 33/44] rtc: export rtc_class in header Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 34/44] driver: featctrl: export of_feature_controllers Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 35/44] net: dsa: export dsa_switch_list Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 36/44] usb: export usb_host_list Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 37/44] pstore: export pstore_is_ready Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 38/44] pinctrl: export pinctrl_list Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 39/44] clk: implement clk_have_nonfixed_providers Ahmad Fatoum
2025-08-13  5:38   ` Sascha Hauer
2025-08-11 12:28 ` [PATCH 40/44] driver: bus: export get_bus_by_name Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 41/44] fimware: arm_scmi: export scmi_list Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 42/44] block: define BLK_TYPE_COUNT as last enum blk_type value Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 43/44] commands: introduce bfetch command Ahmad Fatoum
2025-08-12 10:39   ` Sascha Hauer
2025-08-12 11:09     ` Ahmad Fatoum
2025-08-11 12:28 ` [PATCH 44/44] configs: enable bfetch in some popular defconfigs Ahmad Fatoum
2025-08-12 10:29 ` [PATCH 00/44] commands: add bfetch/buds of command redirection Sascha Hauer
2025-08-12 11:23   ` Ahmad Fatoum
2025-08-13  5:48 ` (subset) " 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=20250811122824.1667791-6-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --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