[PATCH 5/8] mtd: ubi: umount mounted volumes before detaching a ubi device

Sascha Hauer s.hauer at pengutronix.de
Tue Mar 15 04:22:29 PDT 2016


Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mtd/ubi/barebox.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/mtd/ubi/barebox.c b/drivers/mtd/ubi/barebox.c
index 1643f7c..f81705e 100644
--- a/drivers/mtd/ubi/barebox.c
+++ b/drivers/mtd/ubi/barebox.c
@@ -261,10 +261,25 @@ void ubi_cdev_remove(struct ubi_device *ubi)
 	kfree(cdev->name);
 }
 
+static void ubi_umount_volumes(struct ubi_device *ubi)
+{
+	int i;
+
+	for (i = 0; i < ubi->vtbl_slots; i++) {
+		struct ubi_volume *vol = ubi->volumes[i];
+		if (!vol)
+			continue;
+		umount_by_cdev(&vol->cdev);
+	}
+}
+
 /**
  * ubi_detach - detach an UBI device
  * @ubi_num: The UBI device number
  *
+ * UBI volumes used by UBIFS will be unmounted before detaching the
+ * UBI device.
+ *
  * @return: 0 for success, negative error code otherwise
  */
 int ubi_detach(int ubi_num)
@@ -278,5 +293,7 @@ int ubi_detach(int ubi_num)
 	if (!ubi)
 		return -ENOENT;
 
+	ubi_umount_volumes(ubi);
+
 	return ubi_detach_mtd_dev(ubi_num, 1);
 }
-- 
2.7.0




More information about the barebox mailing list