linux/drivers/soc/fsl/qe
Rasmus Villemoes ec2058ac8f soc: fsl: qe: refactor cpm_muram_alloc_common to prevent BUG on error path
If the kmalloc() fails, we try to undo the gen_pool allocation we've
just done. Unfortunately, start has already been modified to subtract
the GENPOOL_OFFSET bias, so we're freeing something that very likely
doesn't exist in the gen_pool, meaning we hit the

 kernel BUG at lib/genalloc.c:399!
 Internal error: Oops - BUG: 0 [#1] PREEMPT SMP ARM
 ...
 [<803fd0e8>] (gen_pool_free) from [<80426bc8>] (cpm_muram_alloc_common+0xb0/0xc8)
 [<80426bc8>] (cpm_muram_alloc_common) from [<80426c28>] (cpm_muram_alloc+0x48/0x80)
 [<80426c28>] (cpm_muram_alloc) from [<80428214>] (ucc_slow_init+0x110/0x4f0)
 [<80428214>] (ucc_slow_init) from [<8044a718>] (qe_uart_request_port+0x3c/0x1d8)

(this was tested by just injecting a random failure by adding
"|| (get_random_int()&7) == 0" to the "if (!entry)" condition).

Refactor the code so we do the kmalloc() first, meaning that's the
thing that needs undoing in case gen_pool_alloc_algo() then
fails. This allows a later cleanup to move the locking from the
callers into the _common function, keeping the kmalloc() out of the
critical region and then, hopefully (if all the muram_alloc callers
allow) change it to a GFP_KERNEL allocation.

Reviewed-by: Timur Tabi <timur@kernel.org>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Li Yang <leoyang.li@nxp.com>
2019-12-09 13:54:36 -06:00
..
gpio.c soc: fsl: qe: avoid ppc-specific io accessors 2019-12-09 13:54:29 -06:00
Kconfig treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
qe_common.c soc: fsl: qe: refactor cpm_muram_alloc_common to prevent BUG on error path 2019-12-09 13:54:36 -06:00
qe_ic.c soc: fsl: qe: merge qe_ic.h headers into qe_ic.c 2019-12-09 13:54:33 -06:00
qe_io.c soc: fsl: qe: qe_io.c: use of_property_read_u32() in par_io_init() 2019-12-09 13:54:33 -06:00
qe_tdm.c soc: fsl: qe: avoid ppc-specific io accessors 2019-12-09 13:54:29 -06:00
qe.c soc: fsl: qe: qe.c: use of_property_read_* helpers 2019-12-09 13:54:33 -06:00
ucc_fast.c soc: fsl: qe: avoid ppc-specific io accessors 2019-12-09 13:54:29 -06:00
ucc_slow.c soc: fsl: qe: avoid ppc-specific io accessors 2019-12-09 13:54:29 -06:00
ucc.c soc: fsl: qe: avoid ppc-specific io accessors 2019-12-09 13:54:29 -06:00
usb.c soc: fsl: qe: avoid ppc-specific io accessors 2019-12-09 13:54:29 -06:00