aboutsummaryrefslogtreecommitdiff
path: root/hw/misc
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/misc
parent1366244ab6d0c83bf0f90270e5bb608651a3cc8f (diff)
downloadqemu-b21e2380376c470900fcadf47507f4d5ade75e85.zip
qemu-b21e2380376c470900fcadf47507f4d5ade75e85.tar.gz
qemu-b21e2380376c470900fcadf47507f4d5ade75e85.tar.bz2
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/misc')
-rw-r--r--hw/misc/applesmc.c2
-rw-r--r--hw/misc/imx6_src.c2
-rw-r--r--hw/misc/ivshmem.c4
3 files changed, 4 insertions, 4 deletions
diff --git a/hw/misc/applesmc.c b/hw/misc/applesmc.c
index 1b9acaf..81cd6b6 100644
--- a/hw/misc/applesmc.c
+++ b/hw/misc/applesmc.c
@@ -253,7 +253,7 @@ static void applesmc_add_key(AppleSMCState *s, const char *key,
{
struct AppleSMCData *def;
- def = g_malloc0(sizeof(struct AppleSMCData));
+ def = g_new0(struct AppleSMCData, 1);
def->key = key;
def->len = len;
def->data = data;
diff --git a/hw/misc/imx6_src.c b/hw/misc/imx6_src.c
index 79f4375..7b0e9688 100644
--- a/hw/misc/imx6_src.c
+++ b/hw/misc/imx6_src.c
@@ -151,7 +151,7 @@ static void imx6_defer_clear_reset_bit(int cpuid,
return;
}
- ri = g_malloc(sizeof(struct SRCSCRResetInfo));
+ ri = g_new(struct SRCSCRResetInfo, 1);
ri->s = s;
ri->reset_bit = reset_shift;
diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index 2307f4a..e7c0099 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -411,7 +411,7 @@ static void resize_peers(IVShmemState *s, int nb_peers)
assert(nb_peers > old_nb_peers);
IVSHMEM_DPRINTF("bumping storage to %d peers\n", nb_peers);
- s->peers = g_realloc(s->peers, nb_peers * sizeof(Peer));
+ s->peers = g_renew(Peer, s->peers, nb_peers);
s->nb_peers = nb_peers;
for (i = old_nb_peers; i < nb_peers; i++) {
@@ -731,7 +731,7 @@ static void ivshmem_reset(DeviceState *d)
static int ivshmem_setup_interrupts(IVShmemState *s, Error **errp)
{
/* allocate QEMU callback data for receiving interrupts */
- s->msi_vectors = g_malloc0(s->vectors * sizeof(MSIVector));
+ s->msi_vectors = g_new0(MSIVector, s->vectors);
if (ivshmem_has_feature(s, IVSHMEM_MSI)) {
if (msix_init_exclusive_bar(PCI_DEVICE(s), s->vectors, 1, errp)) {