1
0
Fork 0

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

[ Upstream commit 7b844cf445 ]

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: 1fca1f6abb ("mtd: afs: simplify partition parsing")
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20210104041137.113075-5-manivannan.sadhasivam@linaro.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
pull/272/head^2
Manivannan Sadhasivam 2021-01-04 09:41:37 +05:30 committed by Greg Kroah-Hartman
parent e350b5bea8
commit 0edd035143
1 changed files with 1 additions and 3 deletions

View File

@ -370,10 +370,8 @@ static int parse_afs_partitions(struct mtd_info *mtd,
return i;
out_free_parts:
while (i >= 0) {
while (--i >= 0)
kfree(parts[i].name);
i--;
}
kfree(parts);
*pparts = NULL;
return ret;