kernel: move diff adding run_parsers_by_type() between mtd patches
[openwrt/staging/wigyori.git] / target / linux / generic / pending-4.14 / 401-mtd-add-support-for-different-partition-parser-types.patch
index 77ee85a8c87f8a7996777afb099f3ac6fc1b8932..a48ae87ea24996561114de43901550d7b0aed22d 100644 (file)
@@ -9,7 +9,55 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 
 --- a/drivers/mtd/mtdpart.c
 +++ b/drivers/mtd/mtdpart.c
-@@ -1034,6 +1034,62 @@ void mtd_part_parser_cleanup(struct mtd_
+@@ -56,6 +56,10 @@ struct mtd_part {
+ };
+ static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part);
++static int parse_mtd_partitions_by_type(struct mtd_info *master,
++                                      enum mtd_parser_type type,
++                                      const struct mtd_partition **pparts,
++                                      struct mtd_part_parser_data *data);
+ /*
+  * Given a pointer to the MTD object in the mtd_part structure, we can retrieve
+@@ -741,6 +745,36 @@ int mtd_del_partition(struct mtd_info *m
+ }
+ EXPORT_SYMBOL_GPL(mtd_del_partition);
++static int
++run_parsers_by_type(struct mtd_part *slave, enum mtd_parser_type type)
++{
++      struct mtd_partition *parts;
++      int nr_parts;
++      int i;
++
++      nr_parts = parse_mtd_partitions_by_type(&slave->mtd, type, (const struct mtd_partition **)&parts,
++                                              NULL);
++      if (nr_parts <= 0)
++              return nr_parts;
++
++      if (WARN_ON(!parts))
++              return 0;
++
++      for (i = 0; i < nr_parts; i++) {
++              /* adjust partition offsets */
++              parts[i].offset += slave->offset;
++
++              mtd_add_partition(slave->parent,
++                                parts[i].name,
++                                parts[i].offset,
++                                parts[i].size);
++      }
++
++      kfree(parts);
++
++      return nr_parts;
++}
++
+ #ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
+ #define SPLIT_FIRMWARE_NAME   CONFIG_MTD_SPLIT_FIRMWARE_NAME
+ #else
+@@ -1118,6 +1152,61 @@ void mtd_part_parser_cleanup(struct mtd_
        }
  }
  
@@ -37,10 +85,10 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 +      return ret;
 +}
 +
-+int parse_mtd_partitions_by_type(struct mtd_info *master,
-+                               enum mtd_parser_type type,
-+                               const struct mtd_partition **pparts,
-+                               struct mtd_part_parser_data *data)
++static int parse_mtd_partitions_by_type(struct mtd_info *master,
++                                      enum mtd_parser_type type,
++                                      const struct mtd_partition **pparts,
++                                      struct mtd_part_parser_data *data)
 +{
 +      struct mtd_part_parser *prev = NULL;
 +      int ret = 0;
@@ -67,19 +115,13 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
 +
 +      return ret;
 +}
-+EXPORT_SYMBOL_GPL(parse_mtd_partitions_by_type);
 +
  int mtd_is_partition(const struct mtd_info *mtd)
  {
        struct mtd_part *part;
 --- a/include/linux/mtd/partitions.h
 +++ b/include/linux/mtd/partitions.h
-@@ -68,11 +68,14 @@ struct mtd_part_parser_data {
-       unsigned long origin;
- };
--
- /*
+@@ -73,6 +73,10 @@ struct mtd_part_parser_data {
   * Functions dealing with the various ways of partitioning the space
   */
  
@@ -90,7 +132,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  struct mtd_part_parser {
        struct list_head list;
        struct module *owner;
-@@ -80,6 +83,7 @@ struct mtd_part_parser {
+@@ -81,6 +85,7 @@ struct mtd_part_parser {
        int (*parse_fn)(struct mtd_info *, const struct mtd_partition **,
                        struct mtd_part_parser_data *);
        void (*cleanup)(const struct mtd_partition *pparts, int nr_parts);
@@ -98,13 +140,3 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  };
  
  /* Container for passing around a set of parsed partitions */
-@@ -112,4 +116,9 @@ uint64_t mtd_get_device_size(const struc
- extern void __weak arch_split_mtd_part(struct mtd_info *master,
-                                      const char *name, int offset, int size);
-+int parse_mtd_partitions_by_type(struct mtd_info *master,
-+                               enum mtd_parser_type type,
-+                               const struct mtd_partition **pparts,
-+                               struct mtd_part_parser_data *data);
-+
- #endif