065-v4.13-0003-mtd-partitions-add-helper-for-deleting-partition.patch 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. From 08263a9ae664b24fa777d20b365601534842b236 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
  3. Date: Wed, 21 Jun 2017 08:26:42 +0200
  4. Subject: [PATCH] mtd: partitions: add helper for deleting partition
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. There are two similar functions handling deletion. One handles single
  9. partition and another the whole MTD flash device. They share (duplicate)
  10. some code so it makes sense to add a small helper for that part.
  11. Function del_mtd_partitions has been moved a bit to keep all deleting
  12. stuff together.
  13. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
  14. Signed-off-by: Brian Norris <computersforpeace@gmail.com>
  15. ---
  16. drivers/mtd/mtdpart.c | 75 +++++++++++++++++++++++++++++----------------------
  17. 1 file changed, 43 insertions(+), 32 deletions(-)
  18. --- a/drivers/mtd/mtdpart.c
  19. +++ b/drivers/mtd/mtdpart.c
  20. @@ -363,32 +363,6 @@ static inline void free_partition(struct
  21. kfree(p);
  22. }
  23. -/*
  24. - * This function unregisters and destroy all slave MTD objects which are
  25. - * attached to the given master MTD object.
  26. - */
  27. -
  28. -int del_mtd_partitions(struct mtd_info *master)
  29. -{
  30. - struct mtd_part *slave, *next;
  31. - int ret, err = 0;
  32. -
  33. - mutex_lock(&mtd_partitions_mutex);
  34. - list_for_each_entry_safe(slave, next, &mtd_partitions, list)
  35. - if (slave->master == master) {
  36. - ret = del_mtd_device(&slave->mtd);
  37. - if (ret < 0) {
  38. - err = ret;
  39. - continue;
  40. - }
  41. - list_del(&slave->list);
  42. - free_partition(slave);
  43. - }
  44. - mutex_unlock(&mtd_partitions_mutex);
  45. -
  46. - return err;
  47. -}
  48. -
  49. static struct mtd_part *allocate_partition(struct mtd_info *master,
  50. const struct mtd_partition *part, int partno,
  51. uint64_t cur_offset)
  52. @@ -675,6 +649,48 @@ int mtd_add_partition(struct mtd_info *m
  53. }
  54. EXPORT_SYMBOL_GPL(mtd_add_partition);
  55. +/**
  56. + * __mtd_del_partition - delete MTD partition
  57. + *
  58. + * @priv: internal MTD struct for partition to be deleted
  59. + *
  60. + * This function must be called with the partitions mutex locked.
  61. + */
  62. +static int __mtd_del_partition(struct mtd_part *priv)
  63. +{
  64. + int err;
  65. +
  66. + err = del_mtd_device(&priv->mtd);
  67. + if (err)
  68. + return err;
  69. +
  70. + list_del(&priv->list);
  71. + free_partition(priv);
  72. +
  73. + return 0;
  74. +}
  75. +
  76. +/*
  77. + * This function unregisters and destroy all slave MTD objects which are
  78. + * attached to the given master MTD object.
  79. + */
  80. +int del_mtd_partitions(struct mtd_info *master)
  81. +{
  82. + struct mtd_part *slave, *next;
  83. + int ret, err = 0;
  84. +
  85. + mutex_lock(&mtd_partitions_mutex);
  86. + list_for_each_entry_safe(slave, next, &mtd_partitions, list)
  87. + if (slave->master == master) {
  88. + ret = __mtd_del_partition(slave);
  89. + if (ret < 0)
  90. + err = ret;
  91. + }
  92. + mutex_unlock(&mtd_partitions_mutex);
  93. +
  94. + return err;
  95. +}
  96. +
  97. int mtd_del_partition(struct mtd_info *master, int partno)
  98. {
  99. struct mtd_part *slave, *next;
  100. @@ -686,12 +702,7 @@ int mtd_del_partition(struct mtd_info *m
  101. (slave->mtd.index == partno)) {
  102. sysfs_remove_files(&slave->mtd.dev.kobj,
  103. mtd_partition_attrs);
  104. - ret = del_mtd_device(&slave->mtd);
  105. - if (ret < 0)
  106. - break;
  107. -
  108. - list_del(&slave->list);
  109. - free_partition(slave);
  110. + ret = __mtd_del_partition(slave);
  111. break;
  112. }
  113. mutex_unlock(&mtd_partitions_mutex);