[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 05/18] g_malloc(0) and g_malloc0(0) return NULL; sim
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PATCH 05/18] g_malloc(0) and g_malloc0(0) return NULL; simplify |
Date: |
Wed, 30 Jan 2013 11:24:17 +0100 |
From: Markus Armbruster <address@hidden>
Once upon a time, it was decided that qemu_malloc(0) should abort.
Switching to glib retired that bright idea. Some code that was added
to cope with it (e.g. in commits 702ef63, b76b6e9) is still around.
Bury it.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
block/qcow2-refcount.c | 6 +-----
block/vdi.c | 4 +---
hw/9pfs/virtio-9p.c | 6 +-----
hw/vhost.c | 7 ++-----
4 files changed, 5 insertions(+), 18 deletions(-)
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 6a95aa6..bc1784c 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -737,11 +737,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
* l1_table_offset when it is the current s->l1_table_offset! Be careful
* when changing this! */
if (l1_table_offset != s->l1_table_offset) {
- if (l1_size2 != 0) {
- l1_table = g_malloc0(align_offset(l1_size2, 512));
- } else {
- l1_table = NULL;
- }
+ l1_table = g_malloc0(align_offset(l1_size2, 512));
l1_allocated = 1;
if (bdrv_pread(bs->file, l1_table_offset,
l1_table, l1_size2) != l1_size2)
diff --git a/block/vdi.c b/block/vdi.c
index 257a592..87c691b 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -443,9 +443,7 @@ static int vdi_open(BlockDriverState *bs, int flags)
bmap_size = header.blocks_in_image * sizeof(uint32_t);
bmap_size = (bmap_size + SECTOR_SIZE - 1) / SECTOR_SIZE;
- if (bmap_size > 0) {
- s->bmap = g_malloc(bmap_size * SECTOR_SIZE);
- }
+ s->bmap = g_malloc(bmap_size * SECTOR_SIZE);
ret = bdrv_read(bs->file, s->bmap_sector, (uint8_t *)s->bmap, bmap_size);
if (ret < 0) {
goto fail_free_bmap;
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 0aaf0d2..b795839 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3101,11 +3101,7 @@ static void v9fs_xattrcreate(void *opaque)
xattr_fidp->fs.xattr.flags = flags;
v9fs_string_init(&xattr_fidp->fs.xattr.name);
v9fs_string_copy(&xattr_fidp->fs.xattr.name, &name);
- if (size) {
- xattr_fidp->fs.xattr.value = g_malloc(size);
- } else {
- xattr_fidp->fs.xattr.value = NULL;
- }
+ xattr_fidp->fs.xattr.value = g_malloc(size);
err = offset;
put_fid(pdu, file_fidp);
out_nofid:
diff --git a/hw/vhost.c b/hw/vhost.c
index cee8aad..0dd2a9a 100644
--- a/hw/vhost.c
+++ b/hw/vhost.c
@@ -269,11 +269,8 @@ static inline void vhost_dev_log_resize(struct vhost_dev*
dev, uint64_t size)
vhost_log_chunk_t *log;
uint64_t log_base;
int r, i;
- if (size) {
- log = g_malloc0(size * sizeof *log);
- } else {
- log = NULL;
- }
+
+ log = g_malloc0(size * sizeof *log);
log_base = (uint64_t)(unsigned long)log;
r = ioctl(dev->control, VHOST_SET_LOG_BASE, &log_base);
assert(r >= 0);
--
1.8.1
- [Qemu-devel] [PULL 00/18] Trivial patches for 22 to 30 January 2013, Stefan Hajnoczi, 2013/01/30
- [Qemu-devel] [PATCH 1/4] hw: Spelling fix in log message, Stefan Hajnoczi, 2013/01/30
- [Qemu-devel] [PATCH 01/18] vnc: Clean up vncws_send_handshake_response(), Stefan Hajnoczi, 2013/01/30
- [Qemu-devel] [PATCH 2/4] acpitable: open the data file in binary mode, Stefan Hajnoczi, 2013/01/30
- [Qemu-devel] [PATCH 03/18] cadence_gem: Debug mode compile fixes, Stefan Hajnoczi, 2013/01/30
- [Qemu-devel] [PATCH 02/18] cadence_ttc: Debug mode compile fixes, Stefan Hajnoczi, 2013/01/30
- [Qemu-devel] [PATCH 4/4] hw/tpci200: Fix compiler warning (redefined symbol with MinGW), Stefan Hajnoczi, 2013/01/30
- [Qemu-devel] [PATCH 3/4] configure: silence pkg-config's check for curses, Stefan Hajnoczi, 2013/01/30
- [Qemu-devel] [PATCH 04/18] xilinx_axidma: Fix debug mode compile messages, Stefan Hajnoczi, 2013/01/30
- [Qemu-devel] [PATCH 05/18] g_malloc(0) and g_malloc0(0) return NULL; simplify,
Stefan Hajnoczi <=
- [Qemu-devel] [PATCH 10/18] virtfs-proxy-helper: Fix unchecked strdup() by conv. to g_strdup(), Stefan Hajnoczi, 2013/01/30
- [Qemu-devel] [PATCH 09/18] spice: Fix unchecked strdup() by converting to g_strdup(), Stefan Hajnoczi, 2013/01/30
- [Qemu-devel] [PATCH 15/18] qemu-ga: Fix unchecked strdup() by converting to g_strdup(), Stefan Hajnoczi, 2013/01/30
- [Qemu-devel] [PATCH 13/18] libcacard: Fix unchecked strdup() by converting to g_strdup(), Stefan Hajnoczi, 2013/01/30
- [Qemu-devel] [PATCH 14/18] qapi: Fix unchecked strdup() by converting to g_strdup(), Stefan Hajnoczi, 2013/01/30
- [Qemu-devel] [PATCH 16/18] qemu-pixman.h: Avoid mutual inclusion loop with console.h, Stefan Hajnoczi, 2013/01/30
- [Qemu-devel] [PATCH 18/18] qmp-commands.hx: s/tray-open/tray_open/ to match qapi schema, Stefan Hajnoczi, 2013/01/30
- [Qemu-devel] [PATCH 06/18] g_strdup(NULL) returns NULL; simplify, Stefan Hajnoczi, 2013/01/30
- [Qemu-devel] [PATCH 08/18] readline: Fix unchecked strdup() by converting to g_strdup(), Stefan Hajnoczi, 2013/01/30
- [Qemu-devel] [PATCH 17/18] tests: Fix {rtc, m48t59}-test build on illumos, Stefan Hajnoczi, 2013/01/30