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 @@ -210,13 +211,16 @@ static void block2mtd_free_device(struct
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;
30 @@ -227,15 +231,20 @@ static struct block2mtd_dev *add_device(
32 /* Get a handle on the device */
33 bdev = blkdev_get_by_path(devname, mode, dev);
37 + for (i = 0; IS_ERR(bdev) && i <= timeout; i++) {
40 - /* We might not have rootfs mounted at this point. Try
41 - to resolve the device name by other means. */
44 + wait_for_device_probe();
46 + devt = name_to_dev_t(devname);
50 - dev_t devt = name_to_dev_t(devname);
52 - bdev = blkdev_get_by_dev(devt, mode, dev);
53 + bdev = blkdev_get_by_dev(devt, mode, dev);
57 @@ -361,11 +370,12 @@ static char block2mtd_paramline[80 + 12]
59 static int block2mtd_setup2(const char *val)
61 - char buf[80 + 12 + 80]; /* 80 for device, 12 for erase size, 80 for name */
62 + char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */
67 size_t erase_size = PAGE_SIZE;
68 + unsigned long timeout = 0;
71 if (strnlen(val, sizeof(buf)) >= sizeof(buf)) {
72 @@ -376,7 +386,7 @@ static int block2mtd_setup2(const char *
74 kill_final_newline(str);
76 - for (i = 0; i < 3; i++)
77 + for (i = 0; i < 4; i++)
78 token[i] = strsep(&str, ",");
81 @@ -405,7 +415,10 @@ static int block2mtd_setup2(const char *
82 if (token[2] && (strlen(token[2]) + 1 > 80))
83 pr_err("mtd device name too long\n");
85 - add_device(name, erase_size, token[2]);
86 + if (token[3] && kstrtoul(token[3], 0, &timeout))
87 + pr_err("invalid timeout\n");
89 + add_device(name, erase_size, token[2], timeout);
93 @@ -439,7 +452,7 @@ static int block2mtd_setup(const char *v
96 module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
97 -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>]]\"");
98 +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\"");
100 static int __init block2mtd_init(void)
102 @@ -474,7 +487,7 @@ static void block2mtd_exit(void)
106 -module_init(block2mtd_init);
107 +late_initcall(block2mtd_init);
108 module_exit(block2mtd_exit);
110 MODULE_LICENSE("GPL");