1 --- a/drivers/mtd/devices/block2mtd.c
2 +++ b/drivers/mtd/devices/block2mtd.c
4 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
6 #include <linux/module.h>
7 +#include <linux/delay.h>
9 #include <linux/blkdev.h>
10 #include <linux/bio.h>
11 @@ -211,13 +212,14 @@ static void block2mtd_free_device(struct
14 /* FIXME: ensure that mtd->size % erase_size == 0 */
15 -static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname)
16 +static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout)
18 const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
19 - struct block_device *bdev;
20 + struct block_device *bdev = ERR_PTR(-ENODEV);
21 struct block2mtd_dev *dev;
22 struct mtd_partition *part;
28 @@ -228,15 +230,20 @@ static struct block2mtd_dev *add_device(
30 /* Get a handle on the device */
31 bdev = blkdev_get_by_path(devname, mode, dev);
35 + for (i = 0; IS_ERR(bdev) && i <= timeout; i++) {
38 - /* We might not have rootfs mounted at this point. Try
39 - to resolve the device name by other means. */
42 + wait_for_device_probe();
44 + devt = name_to_dev_t(devname);
48 - dev_t devt = name_to_dev_t(devname);
50 - bdev = blkdev_get_by_dev(devt, mode, dev);
51 + bdev = blkdev_get_by_dev(devt, mode, dev);
55 @@ -355,11 +362,12 @@ static char block2mtd_paramline[80 + 12]
57 static int block2mtd_setup2(const char *val)
59 - char buf[80 + 12 + 80]; /* 80 for device, 12 for erase size, 80 for name */
60 + char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */
65 size_t erase_size = PAGE_SIZE;
66 + unsigned long timeout = 0;
69 if (strnlen(val, sizeof(buf)) >= sizeof(buf)) {
70 @@ -370,7 +378,7 @@ static int block2mtd_setup2(const char *
72 kill_final_newline(str);
74 - for (i = 0; i < 3; i++)
75 + for (i = 0; i < 4; i++)
76 token[i] = strsep(&str, ",");
79 @@ -399,7 +407,10 @@ static int block2mtd_setup2(const char *
80 if (token[2] && (strlen(token[2]) + 1 > 80))
81 pr_err("mtd device name too long\n");
83 - add_device(name, erase_size, token[2]);
84 + if (token[3] && kstrtoul(token[3], 0, &timeout))
85 + pr_err("invalid timeout\n");
87 + add_device(name, erase_size, token[2], timeout);
91 @@ -433,7 +444,7 @@ static int block2mtd_setup(const char *v
94 module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
95 -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>]]\"");
96 +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\"");
98 static int __init block2mtd_init(void)
100 @@ -467,7 +478,7 @@ static void block2mtd_exit(void)
104 -module_init(block2mtd_init);
105 +late_initcall(block2mtd_init);
106 module_exit(block2mtd_exit);
108 MODULE_LICENSE("GPL");