161-mtd-part-add-generic-parsing-of-linux-part-probe.patch 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. From: Hauke Mehrtens <[email protected]>
  2. Subject: mtd: part: add generic parsing of linux,part-probe
  3. This moves the linux,part-probe device tree parsing code from
  4. physmap_of.c to mtdpart.c. Now all drivers can use this feature by just
  5. providing a reference to their device tree node in struct
  6. mtd_part_parser_data.
  7. Signed-off-by: Hauke Mehrtens <[email protected]>
  8. ---
  9. Documentation/devicetree/bindings/mtd/nand.txt | 16 +++++++++
  10. drivers/mtd/maps/physmap_of.c | 46 +-------------------------
  11. drivers/mtd/mtdpart.c | 45 +++++++++++++++++++++++++
  12. 3 files changed, 62 insertions(+), 45 deletions(-)
  13. --- a/Documentation/devicetree/bindings/mtd/nand.txt
  14. +++ b/Documentation/devicetree/bindings/mtd/nand.txt
  15. @@ -44,6 +44,22 @@ Optional NAND chip properties:
  16. used by the upper layers, and you want to make your NAND
  17. as reliable as possible.
  18. +- linux,part-probe: list of name as strings of the partition parser
  19. + which should be used to parse the partition table.
  20. + They will be tried in the specified ordering and
  21. + the next one will be used if the previous one
  22. + failed.
  23. +
  24. + Example: linux,part-probe = "cmdlinepart", "ofpart";
  25. +
  26. + This is also the default value, which will be used
  27. + if this attribute is not specified. It could be
  28. + that the flash driver in use overwrote the default
  29. + value and uses some other default.
  30. +
  31. + Possible values are: bcm47xxpart, afs, ar7part,
  32. + ofoldpart, ofpart, bcm63xxpart, RedBoot, cmdlinepart
  33. +
  34. The ECC strength and ECC step size properties define the correction capability
  35. of a controller. Together, they say a controller can correct "{strength} bit
  36. errors per {size} bytes".
  37. --- a/drivers/mtd/maps/physmap_of_core.c
  38. +++ b/drivers/mtd/maps/physmap_of_core.c
  39. @@ -114,37 +114,9 @@ static struct mtd_info *obsolete_probe(s
  40. static const char * const part_probe_types_def[] = {
  41. "cmdlinepart", "RedBoot", "ofpart", "ofoldpart", NULL };
  42. -static const char * const *of_get_probes(struct device_node *dp)
  43. -{
  44. - const char **res;
  45. - int count;
  46. -
  47. - count = of_property_count_strings(dp, "linux,part-probe");
  48. - if (count < 0)
  49. - return part_probe_types_def;
  50. -
  51. - res = kzalloc((count + 1) * sizeof(*res), GFP_KERNEL);
  52. - if (!res)
  53. - return NULL;
  54. -
  55. - count = of_property_read_string_array(dp, "linux,part-probe", res,
  56. - count);
  57. - if (count < 0)
  58. - return NULL;
  59. -
  60. - return res;
  61. -}
  62. -
  63. -static void of_free_probes(const char * const *probes)
  64. -{
  65. - if (probes != part_probe_types_def)
  66. - kfree(probes);
  67. -}
  68. -
  69. static const struct of_device_id of_flash_match[];
  70. static int of_flash_probe(struct platform_device *dev)
  71. {
  72. - const char * const *part_probe_types;
  73. const struct of_device_id *match;
  74. struct device_node *dp = dev->dev.of_node;
  75. struct resource res;
  76. @@ -310,14 +282,8 @@ static int of_flash_probe(struct platfor
  77. info->cmtd->dev.parent = &dev->dev;
  78. mtd_set_of_node(info->cmtd, dp);
  79. - part_probe_types = of_get_probes(dp);
  80. - if (!part_probe_types) {
  81. - err = -ENOMEM;
  82. - goto err_out;
  83. - }
  84. - mtd_device_parse_register(info->cmtd, part_probe_types, NULL,
  85. + mtd_device_parse_register(info->cmtd, part_probe_types_def, NULL,
  86. NULL, 0);
  87. - of_free_probes(part_probe_types);
  88. kfree(mtd_list);
  89. --- a/drivers/mtd/mtdpart.c
  90. +++ b/drivers/mtd/mtdpart.c
  91. @@ -29,6 +29,7 @@
  92. #include <linux/kmod.h>
  93. #include <linux/mtd/mtd.h>
  94. #include <linux/mtd/partitions.h>
  95. +#include <linux/of.h>
  96. #include <linux/err.h>
  97. #include <linux/of.h>
  98. @@ -835,6 +836,32 @@ void deregister_mtd_parser(struct mtd_pa
  99. EXPORT_SYMBOL_GPL(deregister_mtd_parser);
  100. /*
  101. + * Parses the linux,part-probe device tree property.
  102. + * When a non null value is returned it has to be freed with kfree() by
  103. + * the caller.
  104. + */
  105. +static const char * const *of_get_probes(struct device_node *dp)
  106. +{
  107. + const char **res;
  108. + int count;
  109. +
  110. + count = of_property_count_strings(dp, "linux,part-probe");
  111. + if (count < 0)
  112. + return NULL;
  113. +
  114. + res = kzalloc((count + 1) * sizeof(*res), GFP_KERNEL);
  115. + if (!res)
  116. + return NULL;
  117. +
  118. + count = of_property_read_string_array(dp, "linux,part-probe", res,
  119. + count);
  120. + if (count < 0)
  121. + return NULL;
  122. +
  123. + return res;
  124. +}
  125. +
  126. +/*
  127. * Do not forget to update 'parse_mtd_partitions()' kerneldoc comment if you
  128. * are changing this array!
  129. */
  130. @@ -983,6 +1010,13 @@ int parse_mtd_partitions(struct mtd_info
  131. struct mtd_partitions pparts = { };
  132. struct mtd_part_parser *parser;
  133. int ret, err = 0;
  134. + const char *const *types_of = NULL;
  135. +
  136. + if (mtd_get_of_node(master)) {
  137. + types_of = of_get_probes(mtd_get_of_node(master));
  138. + if (types_of != NULL)
  139. + types = types_of;
  140. + }
  141. if (!types)
  142. types = mtd_is_partition(master) ? default_subpartition_types :
  143. @@ -1024,6 +1058,7 @@ int parse_mtd_partitions(struct mtd_info
  144. if (ret < 0 && !err)
  145. err = ret;
  146. }
  147. + kfree(types_of);
  148. return err;
  149. }