1
0

040-v4.17-0001-mtd-move-code-adding-master-MTD-out-of-mtd_add_devic.patch 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. From 2c77c57d22adb05b21cdb333a0c42bdfa0e19835 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:41 +0100
  4. Subject: [PATCH] mtd: move code adding master MTD out of
  5. mtd_add_device_partitions()
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. This change is a small cleanup of mtd_device_parse_register(). When
  10. using MTD_PARTITIONED_MASTER it makes sure a master MTD is registered
  11. before dealing with partitions. The advantage of this is not mixing
  12. code handling master MTD with code handling partitions.
  13. This commit doesn't change any behavior except from a slightly different
  14. failure code path. The new code may need to call del_mtd_device when
  15. something goes wrong.
  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 | 25 +++++++++++++------------
  20. 1 file changed, 13 insertions(+), 12 deletions(-)
  21. --- a/drivers/mtd/mtdcore.c
  22. +++ b/drivers/mtd/mtdcore.c
  23. @@ -641,20 +641,12 @@ static int mtd_add_device_partitions(str
  24. {
  25. const struct mtd_partition *real_parts = parts->parts;
  26. int nbparts = parts->nr_parts;
  27. - int ret;
  28. - if (nbparts == 0 || IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)) {
  29. - ret = add_mtd_device(mtd);
  30. - if (ret)
  31. - return ret;
  32. - }
  33. + if (!nbparts && !device_is_registered(&mtd->dev))
  34. + return add_mtd_device(mtd);
  35. - if (nbparts > 0) {
  36. - ret = add_mtd_partitions(mtd, real_parts, nbparts);
  37. - if (ret && IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER))
  38. - del_mtd_device(mtd);
  39. - return ret;
  40. - }
  41. + if (nbparts > 0)
  42. + return add_mtd_partitions(mtd, real_parts, nbparts);
  43. return 0;
  44. }
  45. @@ -714,6 +706,12 @@ int mtd_device_parse_register(struct mtd
  46. mtd_set_dev_defaults(mtd);
  47. + if (IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)) {
  48. + ret = add_mtd_device(mtd);
  49. + if (ret)
  50. + return ret;
  51. + }
  52. +
  53. memset(&parsed, 0, sizeof(parsed));
  54. ret = parse_mtd_partitions(mtd, types, &parsed, parser_data);
  55. @@ -753,6 +751,9 @@ int mtd_device_parse_register(struct mtd
  56. out:
  57. /* Cleanup any parsed partitions */
  58. mtd_part_parser_cleanup(&parsed);
  59. + if (ret && device_is_registered(&mtd->dev))
  60. + del_mtd_device(mtd);
  61. +
  62. return ret;
  63. }
  64. EXPORT_SYMBOL_GPL(mtd_device_parse_register);