diff options
author | Markus Armbruster <armbru@redhat.com> | 2022-09-23 10:42:54 +0200 |
---|---|---|
committer | Laurent Vivier <laurent@vivier.eu> | 2022-10-04 00:10:11 +0200 |
commit | c5e8d51824fe725d0693cd9f50171d34297c5cc0 (patch) | |
tree | ed7b4ecb99371f483a2694493450be78623d91b9 /hw | |
parent | 76eb88b12baf2bd9a1729ded33bd58b7da5d7ec3 (diff) | |
download | qemu-c5e8d51824fe725d0693cd9f50171d34297c5cc0.zip qemu-c5e8d51824fe725d0693cd9f50171d34297c5cc0.tar.gz qemu-c5e8d51824fe725d0693cd9f50171d34297c5cc0.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...
The previous iteration was commit a95942b50c.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <20220923084254.4173111-1-armbru@redhat.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Diffstat (limited to 'hw')
-rw-r--r-- | hw/remote/iommu.c | 2 | ||||
-rw-r--r-- | hw/virtio/virtio-crypto.c | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/hw/remote/iommu.c b/hw/remote/iommu.c index fd723d9..1391dd7 100644 --- a/hw/remote/iommu.c +++ b/hw/remote/iommu.c @@ -47,7 +47,7 @@ static AddressSpace *remote_iommu_find_add_as(PCIBus *pci_bus, elem = g_hash_table_lookup(iommu->elem_by_devfn, INT2VOIDP(devfn)); if (!elem) { - elem = g_malloc0(sizeof(RemoteIommuElem)); + elem = g_new0(RemoteIommuElem, 1); g_hash_table_insert(iommu->elem_by_devfn, INT2VOIDP(devfn), elem); } diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index c1243c3..df4bde2 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -710,7 +710,7 @@ virtio_crypto_handle_asym_req(VirtIOCrypto *vcrypto, uint8_t *src = NULL; uint8_t *dst = NULL; - asym_op_info = g_malloc0(sizeof(CryptoDevBackendAsymOpInfo)); + asym_op_info = g_new0(CryptoDevBackendAsymOpInfo, 1); src_len = ldl_le_p(&req->para.src_data_len); dst_len = ldl_le_p(&req->para.dst_data_len); |