mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] device parameters: sort alphabetically
@ 2015-06-18  6:59 Sascha Hauer
  0 siblings, 0 replies; only message in thread
From: Sascha Hauer @ 2015-06-18  6:59 UTC (permalink / raw)
  To: Barebox List

With many parameters on the global device it becomes increasingly
annoying to find a parameter in the list. Sort it alphabetically
to make this easier.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 lib/parameter.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/lib/parameter.c b/lib/parameter.c
index 865ad9f..4c261b1 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -122,6 +122,14 @@ static const char *param_get_generic(struct device_d *dev, struct param_d *p)
 	return p->value ? p->value : "";
 }
 
+static int compare(struct list_head *a, struct list_head *b)
+{
+	char *na = (char*)list_entry(a, struct param_d, list)->name;
+	char *nb = (char*)list_entry(b, struct param_d, list)->name;
+
+	return strcmp(na, nb);
+}
+
 static int __dev_add_param(struct param_d *param, struct device_d *dev, const char *name,
 		int (*set)(struct device_d *dev, struct param_d *p, const char *val),
 		const char *(*get)(struct device_d *dev, struct param_d *p),
@@ -145,7 +153,7 @@ static int __dev_add_param(struct param_d *param, struct device_d *dev, const ch
 
 	param->flags = flags;
 	param->dev = dev;
-	list_add_tail(&param->list, &dev->parameters);
+	list_add_sort(&param->list, &dev->parameters, compare);
 
 	return 0;
 }
-- 
2.1.4


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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-06-18  7:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-18  6:59 [PATCH] device parameters: sort alphabetically Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox