Commit 7b844cf4 authored by Manivannan Sadhasivam's avatar Manivannan Sadhasivam Committed by Miquel Raynal

mtd: parsers: afs: Fix freeing the part name memory in failure

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.

Fixes: 1fca1f6a ("mtd: afs: simplify partition parsing")
Signed-off-by: default avatarManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20210104041137.113075-5-manivannan.sadhasivam@linaro.org
parent 12ba8f8c
...@@ -370,10 +370,8 @@ static int parse_afs_partitions(struct mtd_info *mtd, ...@@ -370,10 +370,8 @@ static int parse_afs_partitions(struct mtd_info *mtd,
return i; return i;
out_free_parts: out_free_parts:
while (i >= 0) { while (--i >= 0)
kfree(parts[i].name); kfree(parts[i].name);
i--;
}
kfree(parts); kfree(parts);
*pparts = NULL; *pparts = NULL;
return ret; return ret;
......
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