mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 12/12] devices: unregister children when unregistering a device
Date: Wed, 15 Feb 2012 09:22:45 +0100	[thread overview]
Message-ID: <1329294165-12089-13-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1329294165-12089-1-git-send-email-s.hauer@pengutronix.de>

We currently do not allow to unregister a device when it
has children. However, the return value is seldomly checked.
Also this breaks for hot pluggable devices like USB which we have
to unregister when they disappear. The best way to fix this is to
unregister our children and also the partitions on the unregistered
device.
We unregister the device first and then afterwards the children.
We do this because for example network devices have a miidev as
child which they unregister themselves. So we only have to
unregister the children which are not cleaned up by the drivers,
namely fs devices.
Also, unregister all partitions on a disappearing device.

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

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 0132e7d..3777f82 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -137,16 +137,26 @@ EXPORT_SYMBOL(register_device);
 
 int unregister_device(struct device_d *old_dev)
 {
-	debug("unregister_device: %s\n", dev_name(old_dev));
+	struct cdev *cdev, *ct;
+	struct device_d *child, *dt;
 
-	if (!list_empty(&old_dev->children)) {
-		errno = -EBUSY;
-		return errno;
-	}
+	dev_dbg(old_dev, "unregister\n");
 
 	if (old_dev->driver)
 		old_dev->bus->remove(old_dev);
 
+	list_for_each_entry_safe(child, dt, &old_dev->children, sibling) {
+		dev_dbg(old_dev, "unregister child %s\n", dev_name(child));
+		unregister_device(child);
+	}
+
+	list_for_each_entry_safe(cdev, ct, &old_dev->cdevs, devices_list) {
+		if (cdev->flags & DEVFS_IS_PARTITION) {
+			dev_dbg(old_dev, "unregister part %s\n", cdev->name);
+			devfs_del_partition(cdev->name);
+		}
+	}
+
 	list_del(&old_dev->list);
 	list_del(&old_dev->active);
 
-- 
1.7.9


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

      parent reply	other threads:[~2012-02-15  8:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-15  8:22 cleanup filesystem core Sascha Hauer
2012-02-15  8:22 ` [PATCH 01/12] add list_is_singular Sascha Hauer
2012-02-15  8:22 ` [PATCH 02/12] dos partitions: Do not register as fixed partitions Sascha Hauer
2012-02-15  8:22 ` [PATCH 03/12] fs: Store mtab entries in list Sascha Hauer
2012-02-15  8:22 ` [PATCH 04/12] fs: make locally used function get_mtab_entry_by_path static Sascha Hauer
2012-02-15  8:22 ` [PATCH 05/12] fs: Store mtab path in allocated string Sascha Hauer
2012-02-15  8:22 ` [PATCH 06/12] fs: remove unused function fsdev_get_mountpoint Sascha Hauer
2012-02-15  8:22 ` [PATCH 07/12] fs: simplify get_mtab_entry_by_path Sascha Hauer
2012-02-15  8:22 ` [PATCH 08/12] fs: remove only once used variable Sascha Hauer
2012-02-15  8:22 ` [PATCH 09/12] fs: remove fs devices list Sascha Hauer
2012-02-15  8:22 ` [PATCH 10/12] fs: put fs devices on its own bus Sascha Hauer
2012-02-15  8:22 ` [PATCH 11/12] fs: allow to mount on subdirectories Sascha Hauer
2012-02-15  8:22 ` Sascha Hauer [this message]

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=1329294165-12089-13-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