Commit c3168d26 authored by Brian Norris's avatar Brian Norris

mtd: ofpart: assign return argument exactly once

It's easier to refactor these parsers if the return value gets assigned
only once, just like every other MTD partition parser.

This prepares for making the second arg to the parse_fn() const. This is
OK if we construct the partitions completely first, and assign them to
the return pointer only after we're done modifying them.
Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
Reviewed-by: default avatarBoris Brezillon <boris.brezillon@free-electrons.com>
parent 2027cba6
...@@ -29,6 +29,7 @@ static int parse_ofpart_partitions(struct mtd_info *master, ...@@ -29,6 +29,7 @@ static int parse_ofpart_partitions(struct mtd_info *master,
struct mtd_partition **pparts, struct mtd_partition **pparts,
struct mtd_part_parser_data *data) struct mtd_part_parser_data *data)
{ {
struct mtd_partition *parts;
struct device_node *mtd_node; struct device_node *mtd_node;
struct device_node *ofpart_node; struct device_node *ofpart_node;
const char *partname; const char *partname;
...@@ -70,8 +71,8 @@ static int parse_ofpart_partitions(struct mtd_info *master, ...@@ -70,8 +71,8 @@ static int parse_ofpart_partitions(struct mtd_info *master,
if (nr_parts == 0) if (nr_parts == 0)
return 0; return 0;
*pparts = kzalloc(nr_parts * sizeof(**pparts), GFP_KERNEL); parts = kzalloc(nr_parts * sizeof(*parts), GFP_KERNEL);
if (!*pparts) if (!parts)
return -ENOMEM; return -ENOMEM;
i = 0; i = 0;
...@@ -105,19 +106,19 @@ static int parse_ofpart_partitions(struct mtd_info *master, ...@@ -105,19 +106,19 @@ static int parse_ofpart_partitions(struct mtd_info *master,
goto ofpart_fail; goto ofpart_fail;
} }
(*pparts)[i].offset = of_read_number(reg, a_cells); parts[i].offset = of_read_number(reg, a_cells);
(*pparts)[i].size = of_read_number(reg + a_cells, s_cells); parts[i].size = of_read_number(reg + a_cells, s_cells);
partname = of_get_property(pp, "label", &len); partname = of_get_property(pp, "label", &len);
if (!partname) if (!partname)
partname = of_get_property(pp, "name", &len); partname = of_get_property(pp, "name", &len);
(*pparts)[i].name = partname; parts[i].name = partname;
if (of_get_property(pp, "read-only", &len)) 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)) if (of_get_property(pp, "lock", &len))
(*pparts)[i].mask_flags |= MTD_POWERUP_LOCK; parts[i].mask_flags |= MTD_POWERUP_LOCK;
i++; i++;
} }
...@@ -125,6 +126,7 @@ static int parse_ofpart_partitions(struct mtd_info *master, ...@@ -125,6 +126,7 @@ static int parse_ofpart_partitions(struct mtd_info *master,
if (!nr_parts) if (!nr_parts)
goto ofpart_none; goto ofpart_none;
*pparts = parts;
return nr_parts; return nr_parts;
ofpart_fail: ofpart_fail:
...@@ -133,8 +135,7 @@ static int parse_ofpart_partitions(struct mtd_info *master, ...@@ -133,8 +135,7 @@ static int parse_ofpart_partitions(struct mtd_info *master,
ret = -EINVAL; ret = -EINVAL;
ofpart_none: ofpart_none:
of_node_put(pp); of_node_put(pp);
kfree(*pparts); kfree(parts);
*pparts = NULL;
return ret; return ret;
} }
...@@ -147,6 +148,7 @@ static int parse_ofoldpart_partitions(struct mtd_info *master, ...@@ -147,6 +148,7 @@ static int parse_ofoldpart_partitions(struct mtd_info *master,
struct mtd_partition **pparts, struct mtd_partition **pparts,
struct mtd_part_parser_data *data) struct mtd_part_parser_data *data)
{ {
struct mtd_partition *parts;
struct device_node *dp; struct device_node *dp;
int i, plen, nr_parts; int i, plen, nr_parts;
const struct { const struct {
...@@ -168,32 +170,33 @@ static int parse_ofoldpart_partitions(struct mtd_info *master, ...@@ -168,32 +170,33 @@ static int parse_ofoldpart_partitions(struct mtd_info *master,
nr_parts = plen / sizeof(part[0]); nr_parts = plen / sizeof(part[0]);
*pparts = kzalloc(nr_parts * sizeof(*(*pparts)), GFP_KERNEL); parts = kzalloc(nr_parts * sizeof(*parts), GFP_KERNEL);
if (!*pparts) if (!parts)
return -ENOMEM; return -ENOMEM;
names = of_get_property(dp, "partition-names", &plen); names = of_get_property(dp, "partition-names", &plen);
for (i = 0; i < nr_parts; i++) { for (i = 0; i < nr_parts; i++) {
(*pparts)[i].offset = be32_to_cpu(part->offset); parts[i].offset = be32_to_cpu(part->offset);
(*pparts)[i].size = be32_to_cpu(part->len) & ~1; parts[i].size = be32_to_cpu(part->len) & ~1;
/* bit 0 set signifies read only partition */ /* bit 0 set signifies read only partition */
if (be32_to_cpu(part->len) & 1) if (be32_to_cpu(part->len) & 1)
(*pparts)[i].mask_flags = MTD_WRITEABLE; parts[i].mask_flags = MTD_WRITEABLE;
if (names && (plen > 0)) { if (names && (plen > 0)) {
int len = strlen(names) + 1; int len = strlen(names) + 1;
(*pparts)[i].name = names; parts[i].name = names;
plen -= len; plen -= len;
names += len; names += len;
} else { } else {
(*pparts)[i].name = "unnamed"; parts[i].name = "unnamed";
} }
part++; part++;
} }
*pparts = parts;
return nr_parts; return nr_parts;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment