440-block2mtd_init.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. --- a/drivers/mtd/devices/block2mtd.c
  2. +++ b/drivers/mtd/devices/block2mtd.c
  3. @@ -25,6 +25,7 @@
  4. #include <linux/list.h>
  5. #include <linux/init.h>
  6. #include <linux/mtd/mtd.h>
  7. +#include <linux/mtd/partitions.h>
  8. #include <linux/mutex.h>
  9. #include <linux/mount.h>
  10. #include <linux/slab.h>
  11. @@ -218,7 +219,7 @@ static void block2mtd_free_device(struct
  12. static struct block2mtd_dev *add_device(char *devname, int erase_size,
  13. - int timeout)
  14. + const char *mtdname, int timeout)
  15. {
  16. #ifndef MODULE
  17. int i;
  18. @@ -226,6 +227,7 @@ static struct block2mtd_dev *add_device(
  19. const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
  20. struct block_device *bdev = ERR_PTR(-ENODEV);
  21. struct block2mtd_dev *dev;
  22. + struct mtd_partition *part;
  23. char *name;
  24. if (!devname)
  25. @@ -282,13 +284,16 @@ static struct block2mtd_dev *add_device(
  26. /* Setup the MTD structure */
  27. /* make the name contain the block device in */
  28. - name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
  29. + if (!mtdname)
  30. + mtdname = devname;
  31. + name = kmalloc(strlen(mtdname) + 1, GFP_KERNEL);
  32. if (!name)
  33. goto err_destroy_mutex;
  34. + strcpy(name, mtdname);
  35. dev->mtd.name = name;
  36. - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
  37. + dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK & ~(erase_size - 1);
  38. dev->mtd.erasesize = erase_size;
  39. dev->mtd.writesize = 1;
  40. dev->mtd.writebufsize = PAGE_SIZE;
  41. @@ -301,7 +306,11 @@ static struct block2mtd_dev *add_device(
  42. dev->mtd.priv = dev;
  43. dev->mtd.owner = THIS_MODULE;
  44. - if (mtd_device_register(&dev->mtd, NULL, 0)) {
  45. + part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
  46. + part->name = name;
  47. + part->offset = 0;
  48. + part->size = dev->mtd.size;
  49. + if (mtd_device_register(&dev->mtd, part, 1)) {
  50. /* Device didn't get added, so free the entry */
  51. goto err_destroy_mutex;
  52. }
  53. @@ -309,8 +318,7 @@ static struct block2mtd_dev *add_device(
  54. list_add(&dev->list, &blkmtd_device_list);
  55. pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n",
  56. dev->mtd.index,
  57. - dev->mtd.name + strlen("block2mtd: "),
  58. - dev->mtd.erasesize >> 10, dev->mtd.erasesize);
  59. + mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
  60. return dev;
  61. err_destroy_mutex:
  62. @@ -383,7 +391,7 @@ static int block2mtd_setup2(const char *
  63. /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */
  64. char buf[80 + 12 + 80 + 8];
  65. char *str = buf;
  66. - char *token[2];
  67. + char *token[3];
  68. char *name;
  69. size_t erase_size = PAGE_SIZE;
  70. unsigned long timeout = MTD_DEFAULT_TIMEOUT;
  71. @@ -397,7 +405,7 @@ static int block2mtd_setup2(const char *
  72. strcpy(str, val);
  73. kill_final_newline(str);
  74. - for (i = 0; i < 2; i++)
  75. + for (i = 0; i < 3; i++)
  76. token[i] = strsep(&str, ",");
  77. if (str) {
  78. @@ -423,8 +431,10 @@ static int block2mtd_setup2(const char *
  79. return 0;
  80. }
  81. }
  82. + if (token[2] && (strlen(token[2]) + 1 > 80))
  83. + pr_err("mtd device name too long\n");
  84. - add_device(name, erase_size, timeout);
  85. + add_device(name, erase_size, token[2], timeout);
  86. return 0;
  87. }
  88. @@ -458,7 +468,7 @@ static int block2mtd_setup(const char *v
  89. module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
  90. -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
  91. +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>]]\"");
  92. static int __init block2mtd_init(void)
  93. {