Skip to content

Commit 49c64df

Browse files
tasksetmiquelraynal
authored andcommitted
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 free issues. This problem is avoided by adding a goto label to release the memory uniformly. And this change also makes the code a bit more cleaner. Fixes: 4f678a5 ("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]> Cc: [email protected] Cc: [email protected] Signed-off-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent 4da0ea7 commit 49c64df

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

drivers/mtd/devices/phram.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,22 +243,25 @@ static int phram_setup(const char *val)
243243

244244
ret = parse_num64(&start, token[1]);
245245
if (ret) {
246-
kfree(name);
247246
parse_err("illegal start address\n");
247+
goto error;
248248
}
249249

250250
ret = parse_num64(&len, token[2]);
251251
if (ret) {
252-
kfree(name);
253252
parse_err("illegal device length\n");
253+
goto error;
254254
}
255255

256256
ret = register_device(name, start, len);
257-
if (!ret)
258-
pr_info("%s device: %#llx at %#llx\n", name, len, start);
259-
else
260-
kfree(name);
257+
if (ret)
258+
goto error;
259+
260+
pr_info("%s device: %#llx at %#llx\n", name, len, start);
261+
return 0;
261262

263+
error:
264+
kfree(name);
262265
return ret;
263266
}
264267

0 commit comments

Comments
 (0)