linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Rodrigo Freire <rfreire@redhat.com>
To: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org
Cc: "Herton Krzesinski" <hkrzesin@redhat.com>,
	"Jörn Engel" <joern@logfs.org>,
	"Brian Norris" <computersforpeace@gmail.com>,
	dwmw2@infradead.org, "Felix Fietkau" <nbd@openwrt.org>
Subject: [PATCH v3 2/3] mtd: block2mtd: Adds a mtd name and a block device timeout option
Date: Sun, 9 Nov 2014 07:22:27 -0500 (EST)	[thread overview]
Message-ID: <2138224172.7454780.1415535747241.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <2086372266.7454667.1415535533979.JavaMail.zimbra@redhat.com>

From: Felix Fietkau <nbd@openwrt.org>

mtd: block2mtd: Adds a mtd name and a block device timeout option

This patch adds support to a block2mtd MTD name and allows to specify
a block device timeout when adding a block2mtd MTD drive.
Usage: block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]
The devices will be identified the following way:
[root@server01 ~]# cat /proc/mtd
dev:    size   erasesize  name
mtd0: a0000000 00010000 "rootfs"
mtd1: 265080000 00010000 "anothername"
mtd2: acd00000 00010000 "/dev/mmcblk0p2"
Notice that the device mtd2 was added without specifying a name.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
Signed-off-by: Herton Krzesinski <herton@redhat.com>
---
V3: Separated on a single patch
--- a/drivers/mtd/devices/block2mtd.c	2014-11-07 17:16:11.711479312 -0200
+++ b/drivers/mtd/devices/block2mtd.c	2014-11-07 17:15:14.255464054 -0200
@@ -25,6 +25,7 @@
 #include <linux/list.h>
 #include <linux/init.h>
 #include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
 #include <linux/mutex.h>
 #include <linux/mount.h>
 #include <linux/slab.h>
@@ -218,7 +219,7 @@ static void block2mtd_free_device(struct
 
 
 static struct block2mtd_dev *add_device(char *devname, int erase_size,
-		int timeout)
+		const char *mtdname, int timeout)
 {
 #ifndef MODULE
 	int i;
@@ -226,6 +227,7 @@ static struct block2mtd_dev *add_device(
 	const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
 	struct block_device *bdev = ERR_PTR(-ENODEV);
 	struct block2mtd_dev *dev;
+	struct mtd_partition *part;
 	char *name;
 
 	if (!devname)
@@ -282,7 +284,9 @@ static struct block2mtd_dev *add_device(
 
 	/* Setup the MTD structure */
 	/* make the name contain the block device in */
-	name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
+	if (!mtdname)
+		mtdname = devname;
+	name = kstrdup(mtdname, GFP_KERNEL);
 	if (!name)
 		goto err_destroy_mutex;
 
@@ -301,7 +305,11 @@ static struct block2mtd_dev *add_device(
 	dev->mtd.priv = dev;
 	dev->mtd.owner = THIS_MODULE;
 
-	if (mtd_device_register(&dev->mtd, NULL, 0)) {
+	part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
+	part->name = name;
+	part->offset = 0;
+	part->size = dev->mtd.size;
+	if (mtd_device_register(&dev->mtd, part, 1)) {
 		/* Device didn't get added, so free the entry */
 		goto err_destroy_mutex;
 	}
@@ -309,8 +317,7 @@ static struct block2mtd_dev *add_device(
 	list_add(&dev->list, &blkmtd_device_list);
 	pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n",
 		dev->mtd.index,
-		dev->mtd.name + strlen("block2mtd: "),
-		dev->mtd.erasesize >> 10, dev->mtd.erasesize);
+		mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
 	return dev;
 
 err_destroy_mutex:
@@ -383,7 +390,7 @@ static int block2mtd_setup2(const char *
 	/* 80 for device, 12 for erase size, 80 for name, 8 for timeout */
 	char buf[80 + 12 + 80 + 8];
 	char *str = buf;
-	char *token[2];
+	char *token[4];
 	char *name;
 	size_t erase_size = PAGE_SIZE;
 	unsigned long timeout = MTD_DEFAULT_TIMEOUT;
@@ -397,7 +404,7 @@ static int block2mtd_setup2(const char *
 	strcpy(str, val);
 	kill_final_newline(str);
 
-	for (i = 0; i < 2; i++)
+	for (i = 0; i < 4; i++)
 		token[i] = strsep(&str, ",");
 
 	if (str) {
@@ -424,7 +431,13 @@ static int block2mtd_setup2(const char *
 		}
 	}
 
-	add_device(name, erase_size, timeout);
+	if (token[2] && (strlen(token[2]) + 1 > 80))
+		pr_err("mtd device name too long");
+
+
+	if (token[3] && kstrtoul(token[3], 0, &timeout))
+		pr_err("invalid timeout");
+	add_device(name, erase_size, token[2], timeout);
 
 	return 0;
 }
@@ -458,7 +471,7 @@ static int block2mtd_setup(const char *v
 
 
 module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
-MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
+MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\"");
 
 static int __init block2mtd_init(void)
 {
---
1.7.1

  parent reply	other threads:[~2014-11-09 12:22 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <371358190.34795877.1410204429882.JavaMail.zimbra@redhat.com>
2014-09-08 20:04 ` [PATCH] block2mtd: mtd: Present block2mtd timely on boot time Rodrigo Freire
2014-09-09 17:02   ` Jörn Engel
2014-09-17 20:18     ` Rodrigo Freire
2014-09-17 20:28     ` [PATCH V2] mtd: block2mtd: " Rodrigo Freire
2014-09-17 21:21       ` Ezequiel Garcia
2014-09-17 21:41         ` Rodrigo Freire
2014-10-09 15:07       ` [RESEND PATCH " Rodrigo Freire
2014-11-01 13:33         ` Rodrigo Freire
2014-11-07  9:44           ` Artem Bityutskiy
2014-11-07 20:05             ` Brian Norris
2014-11-05 20:01         ` Brian Norris
2014-11-05 20:23       ` [PATCH " Brian Norris
2014-11-07 14:59         ` Artem Bityutskiy
2014-11-07 15:20           ` Felix Fietkau
2014-11-07 15:30             ` Artem Bityutskiy
2014-11-09 12:18         ` Rodrigo Freire
2014-11-26  3:33           ` Brian Norris
2014-11-26 13:32             ` Rodrigo Freire
2015-02-11 15:09               ` Rodrigo Freire
2014-11-09 12:18         ` [PATCH v3 0/3] mtd: block2mtd: wait for device enumeration, add name support Rodrigo Freire
2014-11-09 12:21           ` [PATCH v3 1/3] mtd: block2mtd: Ensure that block2mtd is triggered after block devices are presented Rodrigo Freire
2015-02-24  7:45             ` Brian Norris
2014-11-09 12:22           ` Rodrigo Freire [this message]
2015-02-24  8:05             ` [PATCH v3 2/3] mtd: block2mtd: Adds a mtd name and a block device timeout option Brian Norris
2014-11-09 12:23           ` [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to partition size Rodrigo Freire
2014-11-26  7:21             ` Brian Norris
2014-11-26 13:19               ` Rodrigo Freire
2015-02-24  8:07                 ` Brian Norris
2015-02-24  8:20                   ` Felix Fietkau
2015-02-24  8:27                     ` Brian Norris
2015-02-24  8:30                       ` Felix Fietkau
2015-02-24  8:40                         ` Brian Norris

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=2138224172.7454780.1415535747241.JavaMail.zimbra@redhat.com \
    --to=rfreire@redhat.com \
    --cc=computersforpeace@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=hkrzesin@redhat.com \
    --cc=joern@logfs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=nbd@openwrt.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;
as well as URLs for NNTP newsgroup(s).