hw/arm/exynos4210: Zero memory allocated for Exynos4210State
PATCH 1/1 hw/arm/exynos4210: Zero memory allocated for Exynos4210State
In exynos4210_init() we allocate memory for an Exynos4210State struct. Generally devices can assume that the memory allocated for their state struct is zero-initialized; we broke that assumption here by using g_new(). Use g_new0() instead. (In particular, some code assumes that the various irq arrays in the Exynos4210Irq sub-struct are zero-initialized.)
In the longer term, this code should be QOMified, and then the struct memory will be allocated elsewhere and by functions which always zero-initalize it; but for 3.1 this is a simple fix.
---
I suggested this fix the other day:
https://lists.gnu.org/archive/html/qemu-devel/2018-11/msg00135.html
so here it is as an actual patch.
Probably we should go through other uses of g_new() in board/device code at some point.
hw/arm/exynos4210.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/arm/exynos4210.c +1 -1
@@ -162,7 +162,7 @@ static uint64_t exynos4210_calc_affinity(int cpu)Exynos4210State *exynos4210_init (MemoryRegion *system_mem) { -Exynos4210State *s =g_new (Exynos4210State,1 ); +Exynos4210State *s =g_new0 (Exynos4210State,1 );qemu_irq gate_irq[EXYNOS4210_NCPUS ][EXYNOS4210_IRQ_GATE_NINPUTS ];SysBusDevice *busdev;DeviceState *dev;
Signature · 1 line
2.19.1
Hi Peter,
Quoted 12 lines · Peter Maydell
In
exynos4210_init()we allocate memory for an Exynos4210State struct. Generally devices can assume that the memory allocated for their state struct is zero-initialized; we broke that assumption here by usingg_new(). Useg_new0()instead. (In particular, some code assumes that the various irq arrays in the Exynos4210Irq sub-struct are zero-initialized.)In the longer term, this code should be QOMified, and then the struct memory will be allocated elsewhere and by functions which always zero-initalize it; but for 3.1 this is a simple fix.
Quoted 5 lines
Signed-off-by Peter Maydell <[email protected]>---
I suggested this fix the other day:
https://lists.gnu.org/archive/html/qemu-devel/2018-11/msg00135.html
so here it is as an actual patch.
I did the same patch as you suggested but continued more soft-freeze testing and planed to send it today, sorry.
Quoted 21 lines
Probably we should go through other uses of
g_new()in board/device code at some point.hw/arm/exynos4210.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/arm/exynos4210.c +1
-1@@ -162,7 +162,7 @@ static uint64_t exynos4210_calc_affinity(int cpu)Exynos4210State *exynos4210_init (MemoryRegion *system_mem) { -Exynos4210State *s =g_new (Exynos4210State,1 ); +Exynos4210State *s =g_new0 (Exynos4210State,1 );qemu_irq gate_irq[EXYNOS4210_NCPUS ][EXYNOS4210_IRQ_GATE_NINPUTS ];SysBusDevice *busdev;DeviceState *dev;