brcm47xx: drop 3.14
[openwrt.git] / target / linux / generic / patches-3.14 / 441-block2mtd_probe.patch
1 --- a/drivers/mtd/devices/block2mtd.c
2 +++ b/drivers/mtd/devices/block2mtd.c
3 @@ -10,6 +10,7 @@
4  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
5  
6  #include <linux/module.h>
7 +#include <linux/delay.h>
8  #include <linux/fs.h>
9  #include <linux/blkdev.h>
10  #include <linux/bio.h>
11 @@ -211,13 +212,14 @@ static void block2mtd_free_device(struct
12  
13  
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)
17  {
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;
23         char *name;
24 +       int i;
25  
26         if (!devname)
27                 return NULL;
28 @@ -228,15 +230,20 @@ static struct block2mtd_dev *add_device(
29  
30         /* Get a handle on the device */
31         bdev = blkdev_get_by_path(devname, mode, dev);
32 +
33  #ifndef MODULE
34 -       if (IS_ERR(bdev)) {
35 +       for (i = 0; IS_ERR(bdev) && i <= timeout; i++) {
36 +               dev_t devt;
37  
38 -               /* We might not have rootfs mounted at this point. Try
39 -                  to resolve the device name by other means. */
40 +               if (i)
41 +                       msleep(1000);
42 +               wait_for_device_probe();
43 +
44 +               devt = name_to_dev_t(devname);
45 +               if (!devt)
46 +                       continue;
47  
48 -               dev_t devt = name_to_dev_t(devname);
49 -               if (devt)
50 -                       bdev = blkdev_get_by_dev(devt, mode, dev);
51 +               bdev = blkdev_get_by_dev(devt, mode, dev);
52         }
53  #endif
54  
55 @@ -355,11 +362,12 @@ static char block2mtd_paramline[80 + 12]
56  
57  static int block2mtd_setup2(const char *val)
58  {
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 */
61         char *str = buf;
62 -       char *token[3];
63 +       char *token[4];
64         char *name;
65         size_t erase_size = PAGE_SIZE;
66 +       unsigned long timeout = 0;
67         int i, ret;
68  
69         if (strnlen(val, sizeof(buf)) >= sizeof(buf)) {
70 @@ -370,7 +378,7 @@ static int block2mtd_setup2(const char *
71         strcpy(str, val);
72         kill_final_newline(str);
73  
74 -       for (i = 0; i < 3; i++)
75 +       for (i = 0; i < 4; i++)
76                 token[i] = strsep(&str, ",");
77  
78         if (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");
82  
83 -       add_device(name, erase_size, token[2]);
84 +       if (token[3] && kstrtoul(token[3], 0, &timeout))
85 +               pr_err("invalid timeout\n");
86 +
87 +       add_device(name, erase_size, token[2], timeout);
88  
89         return 0;
90  }
91 @@ -433,7 +444,7 @@ static int block2mtd_setup(const char *v
92  
93  
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>]]]\"");
97  
98  static int __init block2mtd_init(void)
99  {
100 @@ -467,7 +478,7 @@ static void block2mtd_exit(void)
101  }
102  
103  
104 -module_init(block2mtd_init);
105 +late_initcall(block2mtd_init);
106  module_exit(block2mtd_exit);
107  
108  MODULE_LICENSE("GPL");