065-v4.13-0006-mtd-partitions-add-support-for-subpartitions.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. From 97519dc52b44af054d7654776e78eaa211cf1842 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <[email protected]>
  3. Date: Wed, 21 Jun 2017 08:26:45 +0200
  4. Subject: [PATCH] mtd: partitions: add support for subpartitions
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Some flash device partitions can be containers with extra subpartitions
  9. (volumes). All callbacks are already capable of this additional level of
  10. indirection.
  11. This patch makes sure we always display subpartitions using a tree
  12. structure and takes care of deleting subpartitions when parent gets
  13. removed.
  14. Signed-off-by: Rafał Miłecki <[email protected]>
  15. Signed-off-by: Brian Norris <[email protected]>
  16. ---
  17. drivers/mtd/mtdpart.c | 23 ++++++++++++++++-------
  18. 1 file changed, 16 insertions(+), 7 deletions(-)
  19. --- a/drivers/mtd/mtdpart.c
  20. +++ b/drivers/mtd/mtdpart.c
  21. @@ -413,7 +413,7 @@ static struct mtd_part *allocate_partiti
  22. * parent conditional on that option. Note, this is a way to
  23. * distinguish between the master and the partition in sysfs.
  24. */
  25. - slave->mtd.dev.parent = IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) ?
  26. + slave->mtd.dev.parent = IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) || mtd_is_partition(parent) ?
  27. &parent->dev :
  28. parent->dev.parent;
  29. slave->mtd.dev.of_node = part->of_node;
  30. @@ -664,8 +664,17 @@ EXPORT_SYMBOL_GPL(mtd_add_partition);
  31. */
  32. static int __mtd_del_partition(struct mtd_part *priv)
  33. {
  34. + struct mtd_part *child, *next;
  35. int err;
  36. + list_for_each_entry_safe(child, next, &mtd_partitions, list) {
  37. + if (child->parent == &priv->mtd) {
  38. + err = __mtd_del_partition(child);
  39. + if (err)
  40. + return err;
  41. + }
  42. + }
  43. +
  44. sysfs_remove_files(&priv->mtd.dev.kobj, mtd_partition_attrs);
  45. err = del_mtd_device(&priv->mtd);
  46. @@ -680,16 +689,16 @@ static int __mtd_del_partition(struct mt
  47. /*
  48. * This function unregisters and destroy all slave MTD objects which are
  49. - * attached to the given master MTD object.
  50. + * attached to the given MTD object.
  51. */
  52. -int del_mtd_partitions(struct mtd_info *master)
  53. +int del_mtd_partitions(struct mtd_info *mtd)
  54. {
  55. struct mtd_part *slave, *next;
  56. int ret, err = 0;
  57. mutex_lock(&mtd_partitions_mutex);
  58. list_for_each_entry_safe(slave, next, &mtd_partitions, list)
  59. - if (slave->parent == master) {
  60. + if (slave->parent == mtd) {
  61. ret = __mtd_del_partition(slave);
  62. if (ret < 0)
  63. err = ret;
  64. @@ -699,14 +708,14 @@ int del_mtd_partitions(struct mtd_info *
  65. return err;
  66. }
  67. -int mtd_del_partition(struct mtd_info *master, int partno)
  68. +int mtd_del_partition(struct mtd_info *mtd, int partno)
  69. {
  70. struct mtd_part *slave, *next;
  71. int ret = -EINVAL;
  72. mutex_lock(&mtd_partitions_mutex);
  73. list_for_each_entry_safe(slave, next, &mtd_partitions, list)
  74. - if ((slave->parent == master) &&
  75. + if ((slave->parent == mtd) &&
  76. (slave->mtd.index == partno)) {
  77. ret = __mtd_del_partition(slave);
  78. break;
  79. @@ -939,6 +948,6 @@ uint64_t mtd_get_device_size(const struc
  80. if (!mtd_is_partition(mtd))
  81. return mtd->size;
  82. - return mtd_to_part(mtd)->parent->size;
  83. + return mtd_get_device_size(mtd_to_part(mtd)->parent);
  84. }
  85. EXPORT_SYMBOL_GPL(mtd_get_device_size);