diff options
Diffstat (limited to 'drivers/mtd/ofpart.c')
-rw-r--r-- | drivers/mtd/ofpart.c | 65 |
1 files changed, 35 insertions, 30 deletions
diff --git a/drivers/mtd/ofpart.c b/drivers/mtd/ofpart.c index 669c3452f278..ede407d6e106 100644 --- a/drivers/mtd/ofpart.c +++ b/drivers/mtd/ofpart.c @@ -26,9 +26,10 @@ static bool node_has_compatible(struct device_node *pp) } static int parse_ofpart_partitions(struct mtd_info *master, - struct mtd_partition **pparts, + const struct mtd_partition **pparts, struct mtd_part_parser_data *data) { + struct mtd_partition *parts; struct device_node *mtd_node; struct device_node *ofpart_node; const char *partname; @@ -37,19 +38,25 @@ static int parse_ofpart_partitions(struct mtd_info *master, bool dedicated = true; - if (!data) - return 0; - - mtd_node = data->of_node; + /* Pull of_node from the master device node */ + mtd_node = mtd_get_of_node(master); if (!mtd_node) return 0; ofpart_node = of_get_child_by_name(mtd_node, "partitions"); if (!ofpart_node) { - pr_warn("%s: 'partitions' subnode not found on %s. Trying to parse direct subnodes as partitions.\n", - master->name, mtd_node->full_name); + /* + * We might get here even when ofpart isn't used at all (e.g., + * when using another parser), so don't be louder than + * KERN_DEBUG + */ + pr_debug("%s: 'partitions' subnode not found on %s. Trying to parse direct subnodes as partitions.\n", + master->name, mtd_node->full_name); ofpart_node = mtd_node; dedicated = false; + } else if (!of_device_is_compatible(ofpart_node, "fixed-partitions")) { + /* The 'partitions' subnode might be used by another parser */ + return 0; } /* First count the subnodes */ @@ -64,8 +71,8 @@ static int parse_ofpart_partitions(struct mtd_info *master, if (nr_parts == 0) return 0; - *pparts = kzalloc(nr_parts * sizeof(**pparts), GFP_KERNEL); - if (!*pparts) + parts = kzalloc(nr_parts * sizeof(*parts), GFP_KERNEL); + if (!parts) return -ENOMEM; i = 0; @@ -99,19 +106,19 @@ static int parse_ofpart_partitions(struct mtd_info *master, goto ofpart_fail; } - (*pparts)[i].offset = of_read_number(reg, a_cells); - (*pparts)[i].size = of_read_number(reg + a_cells, s_cells); + parts[i].offset = of_read_number(reg, a_cells); + parts[i].size = of_read_number(reg + a_cells, s_cells); partname = of_get_property(pp, "label", &len); if (!partname) partname = of_get_property(pp, "name", &len); - (*pparts)[i].name = partname; + parts[i].name = partname; if (of_get_property(pp, "read-only", &len)) - (*pparts)[i].mask_flags |= MTD_WRITEABLE; + parts[i].mask_flags |= MTD_WRITEABLE; if (of_get_property(pp, "lock", &len)) - (*pparts)[i].mask_flags |= MTD_POWERUP_LOCK; + parts[i].mask_flags |= MTD_POWERUP_LOCK; i++; } @@ -119,6 +126,7 @@ static int parse_ofpart_partitions(struct mtd_info *master, if (!nr_parts) goto ofpart_none; + *pparts = parts; return nr_parts; ofpart_fail: @@ -127,21 +135,20 @@ ofpart_fail: ret = -EINVAL; ofpart_none: of_node_put(pp); - kfree(*pparts); - *pparts = NULL; + kfree(parts); return ret; } static struct mtd_part_parser ofpart_parser = { - .owner = THIS_MODULE, .parse_fn = parse_ofpart_partitions, .name = "ofpart", }; static int parse_ofoldpart_partitions(struct mtd_info *master, - struct mtd_partition **pparts, + const struct mtd_partition **pparts, struct mtd_part_parser_data *data) { + struct mtd_partition *parts; struct device_node *dp; int i, plen, nr_parts; const struct { @@ -149,10 +156,8 @@ static int parse_ofoldpart_partitions(struct mtd_info *master, } *part; const char *names; - if (!data) - return 0; - - dp = data->of_node; + /* Pull of_node from the master device node */ + dp = mtd_get_of_node(master); if (!dp) return 0; @@ -165,37 +170,37 @@ static int parse_ofoldpart_partitions(struct mtd_info *master, nr_parts = plen / sizeof(part[0]); - *pparts = kzalloc(nr_parts * sizeof(*(*pparts)), GFP_KERNEL); - if (!*pparts) + parts = kzalloc(nr_parts * sizeof(*parts), GFP_KERNEL); + if (!parts) return -ENOMEM; names = of_get_property(dp, "partition-names", &plen); for (i = 0; i < nr_parts; i++) { - (*pparts)[i].offset = be32_to_cpu(part->offset); - (*pparts)[i].size = be32_to_cpu(part->len) & ~1; + parts[i].offset = be32_to_cpu(part->offset); + parts[i].size = be32_to_cpu(part->len) & ~1; /* bit 0 set signifies read only partition */ if (be32_to_cpu(part->len) & 1) - (*pparts)[i].mask_flags = MTD_WRITEABLE; + parts[i].mask_flags = MTD_WRITEABLE; if (names && (plen > 0)) { int len = strlen(names) + 1; - (*pparts)[i].name = names; + parts[i].name = names; plen -= len; names += len; } else { - (*pparts)[i].name = "unnamed"; + parts[i].name = "unnamed"; } part++; } + *pparts = parts; return nr_parts; } static struct mtd_part_parser ofoldpart_parser = { - .owner = THIS_MODULE, .parse_fn = parse_ofoldpart_partitions, .name = "ofoldpart", }; |