[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1496418222-23483-5-git-send-email-pali.rohar@gmail.com>
Date: Fri, 2 Jun 2017 17:43:41 +0200
From: Pali Rohár <pali.rohar@...il.com>
To: Joern Engel <joern@...ybastard.org>,
David Woodhouse <dwmw2@...radead.org>,
Brian Norris <computersforpeace@...il.com>,
Boris Brezillon <boris.brezillon@...e-electrons.com>,
Marek Vasut <marek.vasut@...il.com>,
Richard Weinberger <richard@....at>,
Cyrille Pitchen <cyrille.pitchen@...el.com>,
Artem Bityutskiy <dedekind1@...il.com>
Cc: linux-mtd@...ts.infradead.org, linux-kernel@...r.kernel.org,
Pali Rohár <pali.rohar@...il.com>
Subject: [PATCH 4/5] mtd: block2mtd: Add support for deleting block2mtd mapping
This patch allows user to delete block2mtd mapping via parameters file
/sys/module/block2mtd/parameters/block2mtd
Syntax is "del=device", e.g.:
$ echo -n del=/dev/loop0 > /sys/module/block2mtd/parameters/block2mtd
Signed-off-by: Pali Rohár <pali.rohar@...il.com>
---
drivers/mtd/devices/block2mtd.c | 35 +++++++++++++++++++++++++++--------
1 file changed, 27 insertions(+), 8 deletions(-)
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index ad96937..9b6f7b5 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -355,6 +355,19 @@ static struct block2mtd_dev *add_device(char *devname, uint32_t erase_size,
return NULL;
}
+static void del_device(struct block2mtd_dev *dev)
+{
+ if (!dev->ro_mode)
+ block2mtd_sync(&dev->mtd);
+ mtd_device_unregister(&dev->mtd);
+ mutex_destroy(&dev->write_mutex);
+ pr_info("mtd%d: [%s] removed\n",
+ dev->mtd.index,
+ dev->mtd.name + strlen("block2mtd: "));
+ list_del(&dev->list);
+ block2mtd_free_device(dev);
+}
+
/* This function works similar to reguler strtoul. In addition, it
* allows some suffixes for a more human-readable number format:
@@ -477,6 +490,19 @@ static int block2mtd_setup2(const char *val)
}
}
+ if (strncmp(name, "del=", strlen("del=")) == 0) {
+ struct list_head *pos, *next;
+ list_for_each_safe(pos, next, &blkmtd_device_list) {
+ struct block2mtd_dev *dev =
+ list_entry(pos, typeof(*dev), list);
+ if (strcmp(dev->mtd.name + strlen("block2mtd: "),
+ name + strlen("del=")) != 0)
+ continue;
+ del_device(dev);
+ return 0;
+ }
+ }
+
add_device(name, erase_size, write_size, subpage_sft, timeout);
return 0;
@@ -536,14 +562,7 @@ static void block2mtd_exit(void)
/* Remove the MTD devices */
list_for_each_safe(pos, next, &blkmtd_device_list) {
struct block2mtd_dev *dev = list_entry(pos, typeof(*dev), list);
- block2mtd_sync(&dev->mtd);
- mtd_device_unregister(&dev->mtd);
- mutex_destroy(&dev->write_mutex);
- pr_info("mtd%d: [%s] removed\n",
- dev->mtd.index,
- dev->mtd.name + strlen("block2mtd: "));
- list_del(&dev->list);
- block2mtd_free_device(dev);
+ del_device(dev);
}
}
--
1.7.9.5
Powered by blists - more mailing lists