[v3,4/4] mtd: parsers: afs: Fix freeing the part name memory in failure

Message ID 20201119071308.9292-5-manivannan.sadhasivam@linaro.org
State Superseded
Headers show
  • [v3,1/4] dt-bindings: mtd: partitions: Add binding for Qcom SMEM parser
Related show

Commit Message

Manivannan Sadhasivam Nov. 19, 2020, 7:13 a.m.
In the case of failure while parsing the partitions, the iterator should
be pre decremented by one before starting to free the memory allocated
by kstrdup(). Because in the failure case, kstrdup() will not succeed
and thus no memory will be allocated for the current iteration.

Cc: Linus Walleij <linus.walleij@linaro.org>
Fixes: 1fca1f6abb38 ("mtd: afs: simplify partition parsing")
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

 drivers/mtd/parsers/afs.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)


Linux MTD discussion mailing list


diff --git a/drivers/mtd/parsers/afs.c b/drivers/mtd/parsers/afs.c
index 980e332bdac4..26116694c821 100644
--- a/drivers/mtd/parsers/afs.c
+++ b/drivers/mtd/parsers/afs.c
@@ -370,10 +370,8 @@  static int parse_afs_partitions(struct mtd_info *mtd,
 	return i;
-	while (i >= 0) {
+	while (--i >= 0)
-		i--;
-	}
 	*pparts = NULL;
 	return ret;