mtd: phram: fix a double free issue in error path
Subsystems (2)
PATCH 1/1 mtd: phram: fix a double free issue in error path
The variable 'name' is released multiple times in the error path, which may cause double.
This problem is avoided by adding a goto label to release memory uniformly. This change also makes the code a bit more cleaner.
Fixes 4f678a58d335 ("mtd: fix memory leaks in phram_setup")
Signed-off-by Wen Yang <[email protected]>
Cc Joern Engel <[email protected]>
Cc Miquel Raynal <[email protected]>
Cc Richard Weinberger <[email protected]>
Cc Vignesh Raghavendra <[email protected]>
--- drivers/mtd/devices/phram.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/mtd/devices/phram.c +9 -6
@@ -243,22 +243,25 @@ static int phram_setup(const char *val) ret =parse_num64 (&start, token[1 ]);if (ret) { -kfree (name);parse_err ("illegal start address\n" ); + goto error; } ret =parse_num64 (&len, token[2 ]);if (ret) { -kfree (name);parse_err ("illegal device length\n" ); + goto error; } ret =register_device (name, start, len); -if (!ret) -pr_info ("%s device: %#llx at %#llx\n" , name, len, start); -else -kfree (name); +if (ret) + goto error; + +pr_info ("%s device: %#llx at %#llx\n" , name, len, start); +return 0 ; +error: +kfree (name);return ret; }
Signature · 6 lines
2.23.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/