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>
Subject: [PATCH 2/8] driver: detect: detect parent devices aswell
Date: Fri, 26 Jun 2015 09:31:01 +0200	[thread overview]
Message-ID: <1435303867-12889-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1435303867-12889-1-git-send-email-s.hauer@pengutronix.de>

Let device_detect_by_name detect parent devices aswell. We
separate the devname strings by colons and call device_detect()
for each component. This makes it possible for example to

detect nand0.root.ubi.root

With the above detect will be called for nand0, nand0.root, nand0.root.ubi
and nand0.root.ubi.root. The nand0.root detection step will detect the
UBI volume and attach it.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/base/driver.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 24cb5bc..338bea1 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -113,14 +113,29 @@ int device_detect(struct device_d *dev)
 	return dev->detect(dev);
 }
 
-int device_detect_by_name(const char *devname)
+int device_detect_by_name(const char *__devname)
 {
-	struct device_d *dev = get_device_by_name(devname);
+	char *devname = xstrdup(__devname);
+	char *str = devname;
+	struct device_d *dev;
+	int ret = -ENODEV;
+
+	while (1) {
+		strsep(&str, ".");
+
+		dev = get_device_by_name(devname);
+		if (dev)
+			ret = device_detect(dev);
 
-	if (!dev)
-		return -ENODEV;
+		if (!str)
+			break;
+		else
+			*(str - 1) = '.';
+	}
 
-	return device_detect(dev);
+	free(devname);
+
+	return ret;
 }
 
 static int match(struct driver_d *drv, struct device_d *dev)
-- 
2.1.4


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

  parent reply	other threads:[~2015-06-26  7:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-26  7:30 ubi: Make attaching UBI more convenient Sascha Hauer
2015-06-26  7:31 ` [PATCH 1/8] commands: detect: use device_detect_by_name Sascha Hauer
2015-06-26  7:31 ` Sascha Hauer [this message]
2015-06-26  7:31 ` [PATCH 3/8] blspec: Use device_detect_by_name Sascha Hauer
2015-06-26  7:31 ` [PATCH 4/8] ubi: Use preditable device names Sascha Hauer
2015-06-26  7:31 ` [PATCH 5/8] mtd: detect ubi devices automatically Sascha Hauer
2015-06-26  7:31 ` [PATCH 6/8] ubi: Lower 'already attached' message to debug level Sascha Hauer
2015-06-26  7:31 ` [PATCH 7/8] commands: mount: detect the device to be mounted Sascha Hauer
2015-06-26  7:31 ` [PATCH 8/8] ubi: Update documentation 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=1435303867-12889-3-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