Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 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

authored by

Manivannan Sadhasivam and committed by
Miquel Raynal
7b844cf4 12ba8f8c

+1 -3
+1 -3
drivers/mtd/parsers/afs.c
··· 370 370 return i; 371 371 372 372 out_free_parts: 373 - while (i >= 0) { 373 + while (--i >= 0) 374 374 kfree(parts[i].name); 375 - i--; 376 - } 377 375 kfree(parts); 378 376 *pparts = NULL; 379 377 return ret;