[PATCH 2/3] mtd: untangle error codes and number of partitions

Brian Norris computersforpeace at gmail.com
Thu Nov 19 22:26:36 EST 2015


We're going to need to know how many partitions were registered, so
let's disentangle the 'ret' and 'nr_parts' variables, so that nr_parts
always represents the number of partitions we're registering.

Signed-off-by: Brian Norris <computersforpeace at gmail.com>
---
 drivers/mtd/mtdcore.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 62f83b050978..c8d54948bbc1 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -592,23 +592,25 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
 	struct mtd_partition *real_parts = NULL;
 
 	ret = parse_mtd_partitions(mtd, types, &real_parts, parser_data);
-	if (ret <= 0 && nr_parts && parts) {
+	if (ret > 0) {
+		nr_parts = ret;
+	} else if (ret <= 0 && nr_parts && parts) {
 		real_parts = kmemdup(parts, sizeof(*parts) * nr_parts,
 				     GFP_KERNEL);
 		if (!real_parts)
 			ret = -ENOMEM;
 		else
-			ret = nr_parts;
+			ret = 0;
 	}
 	/* Didn't come up with either parsed OR fallback partitions */
 	if (ret < 0) {
 		pr_info("mtd: failed to find partitions; one or more parsers reports errors (%d)\n",
 			ret);
 		/* Don't abort on errors; we can still use unpartitioned MTD */
-		ret = 0;
+		nr_parts = 0;
 	}
 
-	ret = mtd_add_device_partitions(mtd, real_parts, ret);
+	ret = mtd_add_device_partitions(mtd, real_parts, nr_parts);
 	if (ret)
 		goto out;
 
-- 
2.6.0.rc2.230.g3dd15c0




More information about the linux-mtd mailing list