040-v4.17-0002-mtd-get-rid-of-the-mtd_add_device_partitions.patch 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. From 0dbe4ea78d69756efeb0bba0764f6bd4a9ee9567 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
  3. Date: Tue, 16 Jan 2018 16:45:42 +0100
  4. Subject: [PATCH] mtd: get rid of the mtd_add_device_partitions()
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. This simplifies code a bit by:
  9. 1) Avoiding an extra (tiny) function
  10. 2) Checking for amount of parsed (found) partitions just once
  11. 3) Avoiding clearing/filling struct mtd_partitions manually
  12. With this commit proper functions are called directly from the
  13. mtd_device_parse_register(). It doesn't need to use minor tricks like
  14. memsetting struct to 0 to trigger an expected
  15. mtd_add_device_partitions() behavior.
  16. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
  17. Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
  18. ---
  19. drivers/mtd/mtdcore.c | 43 ++++++++++++-------------------------------
  20. 1 file changed, 12 insertions(+), 31 deletions(-)
  21. --- a/drivers/mtd/mtdcore.c
  22. +++ b/drivers/mtd/mtdcore.c
  23. @@ -638,21 +638,6 @@ out_error:
  24. return ret;
  25. }
  26. -static int mtd_add_device_partitions(struct mtd_info *mtd,
  27. - struct mtd_partitions *parts)
  28. -{
  29. - const struct mtd_partition *real_parts = parts->parts;
  30. - int nbparts = parts->nr_parts;
  31. -
  32. - if (!nbparts && !device_is_registered(&mtd->dev))
  33. - return add_mtd_device(mtd);
  34. -
  35. - if (nbparts > 0)
  36. - return add_mtd_partitions(mtd, real_parts, nbparts);
  37. -
  38. - return 0;
  39. -}
  40. -
  41. /*
  42. * Set a few defaults based on the parent devices, if not provided by the
  43. * driver
  44. @@ -703,7 +688,7 @@ int mtd_device_parse_register(struct mtd
  45. const struct mtd_partition *parts,
  46. int nr_parts)
  47. {
  48. - struct mtd_partitions parsed;
  49. + struct mtd_partitions parsed = { };
  50. int ret;
  51. mtd_set_dev_defaults(mtd);
  52. @@ -714,24 +699,20 @@ int mtd_device_parse_register(struct mtd
  53. return ret;
  54. }
  55. - memset(&parsed, 0, sizeof(parsed));
  56. -
  57. + /* Prefer parsed partitions over driver-provided fallback */
  58. ret = parse_mtd_partitions(mtd, types, &parsed, parser_data);
  59. - if ((ret < 0 || parsed.nr_parts == 0) && parts && nr_parts) {
  60. - /* Fall back to driver-provided partitions */
  61. - parsed = (struct mtd_partitions){
  62. - .parts = parts,
  63. - .nr_parts = nr_parts,
  64. - };
  65. - } else if (ret < 0) {
  66. - /* Didn't come up with parsed OR fallback partitions */
  67. - pr_info("mtd: failed to find partitions; one or more parsers reports errors (%d)\n",
  68. - ret);
  69. - /* Don't abort on errors; we can still use unpartitioned MTD */
  70. - memset(&parsed, 0, sizeof(parsed));
  71. + if (!ret && parsed.nr_parts) {
  72. + parts = parsed.parts;
  73. + nr_parts = parsed.nr_parts;
  74. }
  75. - ret = mtd_add_device_partitions(mtd, &parsed);
  76. + if (nr_parts)
  77. + ret = add_mtd_partitions(mtd, parts, nr_parts);
  78. + else if (!device_is_registered(&mtd->dev))
  79. + ret = add_mtd_device(mtd);
  80. + else
  81. + ret = 0;
  82. +
  83. if (ret)
  84. goto out;