ubi: Fix an error pointer dereference in error handling code
authorDan Carpenter <dan.carpenter@oracle.com>
Mon, 13 Jan 2020 13:23:46 +0000 (16:23 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 14 Feb 2020 21:32:18 +0000 (16:32 -0500)
commitc91730d38fd7f8151eb6f9d4a4f39d06170d3d40
treed23c4a5a8ccab7cdd068738d98ea960dc16139b5
parent9ab31c4b1d7be0acea4fc14f7687e5d90d1321de
ubi: Fix an error pointer dereference in error handling code

commit 5d3805af279c93ef49a64701f35254676d709622 upstream.

If "seen_pebs = init_seen(ubi);" fails then "seen_pebs" is an error pointer
and we try to kfree() it which results in an Oops.

This patch re-arranges the error handling so now it only frees things
which have been allocated successfully.

Fixes: daef3dd1f0ae ("UBI: Fastmap: Add self check to detect absent PEBs")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/mtd/ubi/fastmap.c