From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] device parameters: sort alphabetically
Date: Thu, 18 Jun 2015 08:59:39 +0200 [thread overview]
Message-ID: <1434610779-21839-1-git-send-email-s.hauer@pengutronix.de> (raw)
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(¶m->list, &dev->parameters);
+ list_add_sort(¶m->list, &dev->parameters, compare);
return 0;
}
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
reply other threads:[~2015-06-18 7:00 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1434610779-21839-1-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@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