mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 1/4] driver: allow register device with specific id
Date: Sun, 12 Sep 2010 13:27:37 +0200	[thread overview]
Message-ID: <1284290860-32033-1-git-send-email-plagnioj@jcrosoft.com> (raw)

if you specify id = 0 the next available id will be taken
otherwise fail if already registered

before if you specify one it will have use the next free id anyway

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 lib/driver.c |   26 ++++++++++++++++++++++----
 1 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/lib/driver.c b/lib/driver.c
index b600745..00aca9c 100644
--- a/lib/driver.c
+++ b/lib/driver.c
@@ -56,14 +56,24 @@ struct device_d *get_device_by_name(const char *name)
 	return NULL;
 }
 
+struct device_d *get_device_by_name_id(const char *name, int id)
+{
+	struct device_d *dev;
+
+	for_each_device(dev) {
+		if(!strcmp(dev->name, name) && id == dev->id)
+			return dev;
+	}
+
+	return NULL;
+}
+
 int get_free_deviceid(const char *name_template)
 {
 	int i = 0;
-	char name[MAX_DRIVER_NAME + 3];
 
 	while (1) {
-		sprintf(name, "%s%d", name_template, i);
-		if (!get_device_by_name(name))
+		if (!get_device_by_name_id(name_template, i))
 			return i;
 		i++;
 	};
@@ -95,7 +105,15 @@ int register_device(struct device_d *new_device)
 {
 	struct driver_d *drv;
 
-	new_device->id = get_free_deviceid(new_device->name);
+	if (new_device->id == 0) {
+		new_device->id = get_free_deviceid(new_device->name);
+	} else {
+		if (get_device_by_name_id(new_device->name, new_device->id)) {
+			eprintf("register_device: already registered %s\n",
+				dev_name(new_device));
+			return -EINVAL;
+		}
+	}
 
 	debug ("register_device: %s\n",new_device->name);
 
-- 
1.7.1


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

             reply	other threads:[~2010-09-12 11:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-12 11:27 Jean-Christophe PLAGNIOL-VILLARD [this message]
2010-09-12 11:27 ` [PATCH 2/4] device: fix dev_name Jean-Christophe PLAGNIOL-VILLARD
2010-09-12 11:27 ` [PATCH 3/4] amba-pl011: probe fail if we can get the clock Jean-Christophe PLAGNIOL-VILLARD
2010-09-12 11:38   ` Jean-Christophe PLAGNIOL-VILLARD
2010-09-17 13:52     ` Sascha Hauer
2010-09-17 13:51   ` Sascha Hauer
2010-09-17 13:54     ` Jean-Christophe PLAGNIOL-VILLARD
2010-09-12 11:27 ` [PATCH 4/4] stm8815: fix the uart device clock match Jean-Christophe PLAGNIOL-VILLARD
2010-09-17 13:45 ` [PATCH 1/4] driver: allow register device with specific id Sascha Hauer
2010-09-17 13:50   ` Jean-Christophe PLAGNIOL-VILLARD
2010-09-17 13:54     ` Sascha Hauer
2010-09-17 13:55       ` Jean-Christophe PLAGNIOL-VILLARD

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=1284290860-32033-1-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --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