441-block2mtd_probe.patch 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #include <linux/module.h>
  6. +#include <linux/delay.h>
  7. #include <linux/fs.h>
  8. #include <linux/blkdev.h>
  9. #include <linux/bio.h>
  10. @@ -210,13 +211,16 @@ static void block2mtd_free_device(struct
  11. }
  12. -static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname)
  13. +static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout)
  14. {
  15. const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
  16. - struct block_device *bdev;
  17. + struct block_device *bdev = ERR_PTR(-ENODEV);
  18. struct block2mtd_dev *dev;
  19. struct mtd_partition *part;
  20. char *name;
  21. +#ifndef MODULE
  22. + int i;
  23. +#endif
  24. if (!devname)
  25. return NULL;
  26. @@ -227,15 +231,20 @@ static struct block2mtd_dev *add_device(
  27. /* Get a handle on the device */
  28. bdev = blkdev_get_by_path(devname, mode, dev);
  29. +
  30. #ifndef MODULE
  31. - if (IS_ERR(bdev)) {
  32. + for (i = 0; IS_ERR(bdev) && i <= timeout; i++) {
  33. + dev_t devt;
  34. - /* We might not have rootfs mounted at this point. Try
  35. - to resolve the device name by other means. */
  36. + if (i)
  37. + msleep(1000);
  38. + wait_for_device_probe();
  39. +
  40. + devt = name_to_dev_t(devname);
  41. + if (!devt)
  42. + continue;
  43. - dev_t devt = name_to_dev_t(devname);
  44. - if (devt)
  45. - bdev = blkdev_get_by_dev(devt, mode, dev);
  46. + bdev = blkdev_get_by_dev(devt, mode, dev);
  47. }
  48. #endif
  49. @@ -361,11 +370,12 @@ static char block2mtd_paramline[80 + 12]
  50. static int block2mtd_setup2(const char *val)
  51. {
  52. - char buf[80 + 12 + 80]; /* 80 for device, 12 for erase size, 80 for name */
  53. + char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */
  54. char *str = buf;
  55. - char *token[3];
  56. + char *token[4];
  57. char *name;
  58. size_t erase_size = PAGE_SIZE;
  59. + unsigned long timeout = 0;
  60. int i, ret;
  61. if (strnlen(val, sizeof(buf)) >= sizeof(buf)) {
  62. @@ -376,7 +386,7 @@ static int block2mtd_setup2(const char *
  63. strcpy(str, val);
  64. kill_final_newline(str);
  65. - for (i = 0; i < 3; i++)
  66. + for (i = 0; i < 4; i++)
  67. token[i] = strsep(&str, ",");
  68. if (str) {
  69. @@ -405,7 +415,10 @@ static int block2mtd_setup2(const char *
  70. if (token[2] && (strlen(token[2]) + 1 > 80))
  71. pr_err("mtd device name too long\n");
  72. - add_device(name, erase_size, token[2]);
  73. + if (token[3] && kstrtoul(token[3], 0, &timeout))
  74. + pr_err("invalid timeout\n");
  75. +
  76. + add_device(name, erase_size, token[2], timeout);
  77. return 0;
  78. }
  79. @@ -439,7 +452,7 @@ static int block2mtd_setup(const char *v
  80. module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
  81. -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>]]\"");
  82. +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>[,<timeout>]]]\"");
  83. static int __init block2mtd_init(void)
  84. {
  85. @@ -474,7 +487,7 @@ static void block2mtd_exit(void)
  86. }
  87. -module_init(block2mtd_init);
  88. +late_initcall(block2mtd_init);
  89. module_exit(block2mtd_exit);
  90. MODULE_LICENSE("GPL");