Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>

+19 -16
+19 -16
drivers/mtd/ofpart.c
··· 29 29 struct mtd_partition **pparts, 30 30 struct mtd_part_parser_data *data) 31 31 { 32 + struct mtd_partition *parts; 32 33 struct device_node *mtd_node; 33 34 struct device_node *ofpart_node; 34 35 const char *partname; ··· 71 70 if (nr_parts == 0) 72 71 return 0; 73 72 74 - *pparts = kzalloc(nr_parts * sizeof(**pparts), GFP_KERNEL); 75 - if (!*pparts) 73 + parts = kzalloc(nr_parts * sizeof(*parts), GFP_KERNEL); 74 + if (!parts) 76 75 return -ENOMEM; 77 76 78 77 i = 0; ··· 106 105 goto ofpart_fail; 107 106 } 108 107 109 - (*pparts)[i].offset = of_read_number(reg, a_cells); 110 - (*pparts)[i].size = of_read_number(reg + a_cells, s_cells); 108 + parts[i].offset = of_read_number(reg, a_cells); 109 + parts[i].size = of_read_number(reg + a_cells, s_cells); 111 110 112 111 partname = of_get_property(pp, "label", &len); 113 112 if (!partname) 114 113 partname = of_get_property(pp, "name", &len); 115 - (*pparts)[i].name = partname; 114 + parts[i].name = partname; 116 115 117 116 if (of_get_property(pp, "read-only", &len)) 118 - (*pparts)[i].mask_flags |= MTD_WRITEABLE; 117 + parts[i].mask_flags |= MTD_WRITEABLE; 119 118 120 119 if (of_get_property(pp, "lock", &len)) 121 - (*pparts)[i].mask_flags |= MTD_POWERUP_LOCK; 120 + parts[i].mask_flags |= MTD_POWERUP_LOCK; 122 121 123 122 i++; 124 123 } ··· 126 125 if (!nr_parts) 127 126 goto ofpart_none; 128 127 128 + *pparts = parts; 129 129 return nr_parts; 130 130 131 131 ofpart_fail: ··· 135 133 ret = -EINVAL; 136 134 ofpart_none: 137 135 of_node_put(pp); 138 - kfree(*pparts); 139 - *pparts = NULL; 136 + kfree(parts); 140 137 return ret; 141 138 } 142 139 ··· 148 147 struct mtd_partition **pparts, 149 148 struct mtd_part_parser_data *data) 150 149 { 150 + struct mtd_partition *parts; 151 151 struct device_node *dp; 152 152 int i, plen, nr_parts; 153 153 const struct { ··· 170 168 171 169 nr_parts = plen / sizeof(part[0]); 172 170 173 - *pparts = kzalloc(nr_parts * sizeof(*(*pparts)), GFP_KERNEL); 174 - if (!*pparts) 171 + parts = kzalloc(nr_parts * sizeof(*parts), GFP_KERNEL); 172 + if (!parts) 175 173 return -ENOMEM; 176 174 177 175 names = of_get_property(dp, "partition-names", &plen); 178 176 179 177 for (i = 0; i < nr_parts; i++) { 180 - (*pparts)[i].offset = be32_to_cpu(part->offset); 181 - (*pparts)[i].size = be32_to_cpu(part->len) & ~1; 178 + parts[i].offset = be32_to_cpu(part->offset); 179 + parts[i].size = be32_to_cpu(part->len) & ~1; 182 180 /* bit 0 set signifies read only partition */ 183 181 if (be32_to_cpu(part->len) & 1) 184 - (*pparts)[i].mask_flags = MTD_WRITEABLE; 182 + parts[i].mask_flags = MTD_WRITEABLE; 185 183 186 184 if (names && (plen > 0)) { 187 185 int len = strlen(names) + 1; 188 186 189 - (*pparts)[i].name = names; 187 + parts[i].name = names; 190 188 plen -= len; 191 189 names += len; 192 190 } else { 193 - (*pparts)[i].name = "unnamed"; 191 + parts[i].name = "unnamed"; 194 192 } 195 193 196 194 part++; 197 195 } 198 196 197 + *pparts = parts; 199 198 return nr_parts; 200 199 } 201 200