aboutsummaryrefslogtreecommitdiff
path: root/hw/ppc/ppc405_uc.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2022-03-15 15:41:56 +0100
committerMarkus Armbruster <armbru@redhat.com>2022-03-21 15:44:44 +0100
commitb21e2380376c470900fcadf47507f4d5ade75e85 (patch)
tree7fd41d348f85d6ef66d6f10ca4df241ba0e74f83 /hw/ppc/ppc405_uc.c
parent1366244ab6d0c83bf0f90270e5bb608651a3cc8f (diff)
Use g_new() & friends where that makes obvious sense
g_new(T, n) is neater than g_malloc(sizeof(T) * n). It's also safer, for two reasons. One, it catches multiplication overflowing size_t. Two, it returns T * rather than void *, which lets the compiler catch more type errors. This commit only touches allocations with size arguments of the form sizeof(T). Patch created mechanically with: $ spatch --in-place --sp-file scripts/coccinelle/use-g_new-etc.cocci \ --macro-file scripts/cocci-macro-file.h FILES... Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Cédric Le Goater <clg@kaod.org> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Message-Id: <20220315144156.1595462-4-armbru@redhat.com> Reviewed-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
Diffstat (limited to 'hw/ppc/ppc405_uc.c')
-rw-r--r--hw/ppc/ppc405_uc.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/hw/ppc/ppc405_uc.c b/hw/ppc/ppc405_uc.c
index 8aacd275a6..36c8ba6f3c 100644
--- a/hw/ppc/ppc405_uc.c
+++ b/hw/ppc/ppc405_uc.c
@@ -215,7 +215,7 @@ void ppc4xx_plb_init(CPUPPCState *env)
{
ppc4xx_plb_t *plb;
- plb = g_malloc0(sizeof(ppc4xx_plb_t));
+ plb = g_new0(ppc4xx_plb_t, 1);
ppc_dcr_register(env, PLB3A0_ACR, plb, &dcr_read_plb, &dcr_write_plb);
ppc_dcr_register(env, PLB4A0_ACR, plb, &dcr_read_plb, &dcr_write_plb);
ppc_dcr_register(env, PLB0_ACR, plb, &dcr_read_plb, &dcr_write_plb);
@@ -300,7 +300,7 @@ static void ppc4xx_pob_init(CPUPPCState *env)
{
ppc4xx_pob_t *pob;
- pob = g_malloc0(sizeof(ppc4xx_pob_t));
+ pob = g_new0(ppc4xx_pob_t, 1);
ppc_dcr_register(env, POB0_BEAR, pob, &dcr_read_pob, &dcr_write_pob);
ppc_dcr_register(env, POB0_BESR0, pob, &dcr_read_pob, &dcr_write_pob);
ppc_dcr_register(env, POB0_BESR1, pob, &dcr_read_pob, &dcr_write_pob);
@@ -380,7 +380,7 @@ static void ppc4xx_opba_init(hwaddr base)
trace_opba_init(base);
- opba = g_malloc0(sizeof(ppc4xx_opba_t));
+ opba = g_new0(ppc4xx_opba_t, 1);
memory_region_init_io(&opba->io, NULL, &opba_ops, opba, "opba", 0x002);
memory_region_add_subregion(get_system_memory(), base, &opba->io);
qemu_register_reset(ppc4xx_opba_reset, opba);
@@ -575,7 +575,7 @@ void ppc405_ebc_init(CPUPPCState *env)
{
ppc4xx_ebc_t *ebc;
- ebc = g_malloc0(sizeof(ppc4xx_ebc_t));
+ ebc = g_new0(ppc4xx_ebc_t, 1);
qemu_register_reset(&ebc_reset, ebc);
ppc_dcr_register(env, EBC0_CFGADDR,
ebc, &dcr_read_ebc, &dcr_write_ebc);
@@ -658,7 +658,7 @@ static void ppc405_dma_init(CPUPPCState *env, qemu_irq irqs[4])
{
ppc405_dma_t *dma;
- dma = g_malloc0(sizeof(ppc405_dma_t));
+ dma = g_new0(ppc405_dma_t, 1);
memcpy(dma->irqs, irqs, 4 * sizeof(qemu_irq));
qemu_register_reset(&ppc405_dma_reset, dma);
ppc_dcr_register(env, DMA0_CR0,
@@ -757,7 +757,7 @@ static void ppc405_gpio_init(hwaddr base)
trace_ppc405_gpio_init(base);
- gpio = g_malloc0(sizeof(ppc405_gpio_t));
+ gpio = g_new0(ppc405_gpio_t, 1);
memory_region_init_io(&gpio->io, NULL, &ppc405_gpio_ops, gpio, "pgio", 0x038);
memory_region_add_subregion(get_system_memory(), base, &gpio->io);
qemu_register_reset(&ppc405_gpio_reset, gpio);
@@ -906,7 +906,7 @@ static void ppc405_ocm_init(CPUPPCState *env)
{
ppc405_ocm_t *ocm;
- ocm = g_malloc0(sizeof(ppc405_ocm_t));
+ ocm = g_new0(ppc405_ocm_t, 1);
/* XXX: Size is 4096 or 0x04000000 */
memory_region_init_ram(&ocm->isarc_ram, NULL, "ppc405.ocm", 4 * KiB,
&error_fatal);
@@ -1148,7 +1148,7 @@ static void ppc4xx_gpt_init(hwaddr base, qemu_irq irqs[5])
trace_ppc4xx_gpt_init(base);
- gpt = g_malloc0(sizeof(ppc4xx_gpt_t));
+ gpt = g_new0(ppc4xx_gpt_t, 1);
for (i = 0; i < 5; i++) {
gpt->irqs[i] = irqs[i];
}
@@ -1399,7 +1399,7 @@ static void ppc405ep_cpc_init (CPUPPCState *env, clk_setup_t clk_setup[8],
{
ppc405ep_cpc_t *cpc;
- cpc = g_malloc0(sizeof(ppc405ep_cpc_t));
+ cpc = g_new0(ppc405ep_cpc_t, 1);
memcpy(cpc->clk_setup, clk_setup,
PPC405EP_CLK_NB * sizeof(clk_setup_t));
cpc->jtagid = 0x20267049;