mtd: parsers: afs: Fix freeing the part name memory in failure
authorManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Mon, 4 Jan 2021 04:11:37 +0000 (09:41 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 4 Mar 2021 10:37:45 +0000 (11:37 +0100)
commit0edd035143ddd318faafeff5e608cd5983c47cf0
tree3dcc9f51bcfaacd554505fe5070402aa0bacecf4
parente350b5bea8e83136ce677f1b5dbab87d126ec1b0
mtd: parsers: afs: Fix freeing the part name memory in failure

[ Upstream commit 7b844cf445f0a7daa68be0ce71eb2c88d68b0c5d ]

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: 1fca1f6abb38 ("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>
drivers/mtd/parsers/afs.c