2
0

440-block2mtd_init.patch 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. --- a/drivers/mtd/devices/block2mtd.c
  2. +++ b/drivers/mtd/devices/block2mtd.c
  3. @@ -17,6 +17,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. @@ -209,11 +210,12 @@ static void block2mtd_free_device(struct
  12. }
  13. -static struct block2mtd_dev *add_device(char *devname, int erase_size)
  14. +static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname)
  15. {
  16. const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL;
  17. struct block_device *bdev;
  18. struct block2mtd_dev *dev;
  19. + struct mtd_partition *part;
  20. char *name;
  21. if (!devname)
  22. @@ -257,13 +259,16 @@ static struct block2mtd_dev *add_device(
  23. /* Setup the MTD structure */
  24. /* make the name contain the block device in */
  25. - name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
  26. + if (!mtdname)
  27. + mtdname = devname;
  28. + name = kmalloc(strlen(mtdname) + 1, GFP_KERNEL);
  29. if (!name)
  30. goto err_destroy_mutex;
  31. + strcpy(name, mtdname);
  32. dev->mtd.name = name;
  33. - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
  34. + dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK & ~(erase_size - 1);
  35. dev->mtd.erasesize = erase_size;
  36. dev->mtd.writesize = 1;
  37. dev->mtd.writebufsize = PAGE_SIZE;
  38. @@ -276,15 +281,18 @@ static struct block2mtd_dev *add_device(
  39. dev->mtd.priv = dev;
  40. dev->mtd.owner = THIS_MODULE;
  41. - if (mtd_device_register(&dev->mtd, NULL, 0)) {
  42. + part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL);
  43. + part->name = name;
  44. + part->offset = 0;
  45. + part->size = dev->mtd.size;
  46. + if (mtd_device_register(&dev->mtd, part, 1)) {
  47. /* Device didn't get added, so free the entry */
  48. goto err_destroy_mutex;
  49. }
  50. list_add(&dev->list, &blkmtd_device_list);
  51. pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n",
  52. dev->mtd.index,
  53. - dev->mtd.name + strlen("block2mtd: "),
  54. - dev->mtd.erasesize >> 10, dev->mtd.erasesize);
  55. + mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize);
  56. return dev;
  57. err_destroy_mutex:
  58. @@ -353,9 +361,9 @@ static char block2mtd_paramline[80 + 12]
  59. static int block2mtd_setup2(const char *val)
  60. {
  61. - char buf[80 + 12]; /* 80 for device, 12 for erase size */
  62. + char buf[80 + 12 + 80]; /* 80 for device, 12 for erase size, 80 for name */
  63. char *str = buf;
  64. - char *token[2];
  65. + char *token[3];
  66. char *name;
  67. size_t erase_size = PAGE_SIZE;
  68. int i, ret;
  69. @@ -368,7 +376,7 @@ static int block2mtd_setup2(const char *
  70. strcpy(str, val);
  71. kill_final_newline(str);
  72. - for (i = 0; i < 2; i++)
  73. + for (i = 0; i < 3; i++)
  74. token[i] = strsep(&str, ",");
  75. if (str) {
  76. @@ -394,8 +402,10 @@ static int block2mtd_setup2(const char *
  77. return 0;
  78. }
  79. }
  80. + if (token[2] && (strlen(token[2]) + 1 > 80))
  81. + pr_err("mtd device name too long\n");
  82. - add_device(name, erase_size);
  83. + add_device(name, erase_size, token[2]);
  84. return 0;
  85. }
  86. @@ -429,7 +439,7 @@ static int block2mtd_setup(const char *v
  87. module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
  88. -MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
  89. +MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>[,<name>]]\"");
  90. static int __init block2mtd_init(void)
  91. {