提交 4ad05fc4 编写于 作者: M Manivannan Sadhasivam 提交者: Zheng Zengkai

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

stable inclusion
from stable-5.10.20
commit 0edd035143ddd318faafeff5e608cd5983c47cf0
bugzilla: 50608

--------------------------------

[ Upstream commit 7b844cf4 ]

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: NManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Reviewed-by: NLinus Walleij <linus.walleij@linaro.org>
Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: NMiquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20210104041137.113075-5-manivannan.sadhasivam@linaro.orgSigned-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 6988001b
...@@ -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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册