[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 3/3] scsi: Use g_new() & friends where that makes ob
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH 3/3] scsi: Use g_new() & friends where that makes obvious sense |
Date: |
Thu, 4 Dec 2014 14:12:45 +0100 |
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).
Signed-off-by: Markus Armbruster <address@hidden>
---
hw/scsi/lsi53c895a.c | 2 +-
hw/scsi/virtio-scsi.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c
index d9b4c7e..ec92048 100644
--- a/hw/scsi/lsi53c895a.c
+++ b/hw/scsi/lsi53c895a.c
@@ -781,7 +781,7 @@ static void lsi_do_command(LSIState *s)
}
assert(s->current == NULL);
- s->current = g_malloc0(sizeof(lsi_request));
+ s->current = g_new0(lsi_request, 1);
s->current->tag = s->select_tag;
s->current->req = scsi_req_new(dev, s->current->tag, s->current_lun, buf,
s->current);
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index ef48550..b06dd39 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -829,7 +829,7 @@ void virtio_scsi_common_realize(DeviceState *dev, Error
**errp,
virtio_cleanup(vdev);
return;
}
- s->cmd_vqs = g_malloc0(s->conf.num_queues * sizeof(VirtQueue *));
+ s->cmd_vqs = g_new0(VirtQueue *, s->conf.num_queues);
s->sense_size = VIRTIO_SCSI_SENSE_SIZE;
s->cdb_size = VIRTIO_SCSI_CDB_SIZE;
--
1.9.3
- [Qemu-devel] [PATCH 0/3] scsi: Trivial cleanups around g_malloc(), Markus Armbruster, 2014/12/04
- [Qemu-devel] [PATCH 2/3] scsi: Fuse g_malloc(); memset() into g_malloc0(), Markus Armbruster, 2014/12/04
- [Qemu-devel] [PATCH 3/3] scsi: Use g_new() & friends where that makes obvious sense,
Markus Armbruster <=
- [Qemu-devel] [PATCH 1/3] scsi: Drop superfluous conditionals around g_free(), Markus Armbruster, 2014/12/04
- Re: [Qemu-devel] [PATCH 0/3] scsi: Trivial cleanups around g_malloc(), Eric Blake, 2014/12/04
- Re: [Qemu-devel] [PATCH 0/3] scsi: Trivial cleanups around g_malloc(), Fam Zheng, 2014/12/05
- Re: [Qemu-devel] [PATCH 0/3] scsi: Trivial cleanups around g_malloc(), Paolo Bonzini, 2014/12/05