]> asedeno.scripts.mit.edu Git - linux.git/commit
ubi: Free the normal volumes in error paths of ubi_attach_mtd_dev()
authorHou Tao <houtao1@huawei.com>
Sat, 30 Nov 2019 09:48:25 +0000 (17:48 +0800)
committerRichard Weinberger <richard@nod.at>
Thu, 16 Jan 2020 22:35:59 +0000 (23:35 +0100)
commitfc55dacf7fea793e70c9c75a1acff47a4fb02017
tree322ea53989f168fdce2826455193d77364dadf43
parent9d6c4742f96cc0380a3f2854d62c667b87736d71
ubi: Free the normal volumes in error paths of ubi_attach_mtd_dev()

The allocated normal volumes saved in ubi->volumes are not freed
in the error paths in ubi_attach_mtd_dev() and its callees (e.g.
ubi_attach() and ubi_read_volume_table()).

These normal volumes should be freed through kill_volumes() and
vol_release(), but ubi_attach_mtd_dev() may fail before
calling uif_init(), and there will be memory leaks.

So adding a new helper ubi_free_all_volumes() to free the normal
and the internal volumes. And in order to prevent double-free
of volume, reset ubi->volumes[i] to NULL after freeing.

Signed-off-by: Hou Tao <houtao1@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
drivers/mtd/ubi/attach.c
drivers/mtd/ubi/build.c
drivers/mtd/ubi/ubi.h
drivers/mtd/ubi/vtbl.c