mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 07:43:54 -06:00
arm: 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). Coccinelle semantic patch: @@ type T; @@ -g_malloc(sizeof(T)) +g_new(T, 1) @@ type T; @@ -g_try_malloc(sizeof(T)) +g_try_new(T, 1) @@ type T; @@ -g_malloc0(sizeof(T)) +g_new0(T, 1) @@ type T; @@ -g_try_malloc0(sizeof(T)) +g_try_new0(T, 1) @@ type T; expression n; @@ -g_malloc(sizeof(T) * (n)) +g_new(T, n) @@ type T; expression n; @@ -g_try_malloc(sizeof(T) * (n)) +g_try_new(T, n) @@ type T; expression n; @@ -g_malloc0(sizeof(T) * (n)) +g_new0(T, n) @@ type T; expression n; @@ -g_try_malloc0(sizeof(T) * (n)) +g_try_new0(T, n) @@ type T; expression p, n; @@ -g_realloc(p, sizeof(T) * (n)) +g_renew(T, p, n) @@ type T; expression p, n; @@ -g_try_realloc(p, sizeof(T) * (n)) +g_try_renew(T, p, n) @@ type T; expression n; @@ -(T *)g_new(T, n) +g_new(T, n) @@ type T; expression n; @@ -(T *)g_new0(T, n) +g_new0(T, n) @@ type T; expression p, n; @@ -(T *)g_renew(T, p, n) +g_renew(T, p, n) Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 1440524394-15640-1-git-send-email-armbru@redhat.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
parent
b597aa037d
commit
b45c03f585
17 changed files with 38 additions and 65 deletions
|
@ -1626,8 +1626,7 @@ struct soc_dma_s *omap_dma_init(hwaddr base, qemu_irq *irqs,
|
|||
enum omap_dma_model model)
|
||||
{
|
||||
int num_irqs, memsize, i;
|
||||
struct omap_dma_s *s = (struct omap_dma_s *)
|
||||
g_malloc0(sizeof(struct omap_dma_s));
|
||||
struct omap_dma_s *s = g_new0(struct omap_dma_s, 1);
|
||||
|
||||
if (model <= omap_dma_3_1) {
|
||||
num_irqs = 6;
|
||||
|
@ -2061,8 +2060,7 @@ struct soc_dma_s *omap_dma4_init(hwaddr base, qemu_irq *irqs,
|
|||
int chans, omap_clk iclk, omap_clk fclk)
|
||||
{
|
||||
int i;
|
||||
struct omap_dma_s *s = (struct omap_dma_s *)
|
||||
g_malloc0(sizeof(struct omap_dma_s));
|
||||
struct omap_dma_s *s = g_new0(struct omap_dma_s, 1);
|
||||
|
||||
s->model = omap_dma_4;
|
||||
s->chans = chans;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue