From bc5008a832f95aae86efce844382e64d54da2146 Mon Sep 17 00:00:00 2001 From: zhanghailiang Date: Mon, 18 Aug 2014 15:49:22 +0800 Subject: [PATCH 01/11] util/path: Use the GLib memory allocation routines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this file, we don't check the return value of malloc/strdup/realloc which may fail. Instead of using these routines, we use the GLib memory APIs g_malloc/g_strdup/g_realloc. They will exit on allocation failure, so there is no need to test for failure, which would be fine for setup. Signed-off-by: zhanghailiang Reviewed-by: Alex Bennée Signed-off-by: Michael Tokarev --- util/path.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/util/path.c b/util/path.c index 5c59d9f1d3..4e4877e821 100644 --- a/util/path.c +++ b/util/path.c @@ -45,8 +45,8 @@ static struct pathelem *new_entry(const char *root, struct pathelem *parent, const char *name) { - struct pathelem *new = malloc(sizeof(*new)); - new->name = strdup(name); + struct pathelem *new = g_malloc(sizeof(*new)); + new->name = g_strdup(name); new->pathname = g_strdup_printf("%s/%s", root, name); new->num_entries = 0; return new; @@ -88,7 +88,7 @@ static struct pathelem *add_entry(struct pathelem *root, const char *name, root->num_entries++; - root = realloc(root, sizeof(*root) + root = g_realloc(root, sizeof(*root) + sizeof(root->entries[0])*root->num_entries); e = &root->entries[root->num_entries-1]; @@ -161,8 +161,8 @@ void init_paths(const char *prefix) base = add_dir_maybe(base); if (base->num_entries == 0) { g_free(base->pathname); - free(base->name); - free(base); + g_free(base->name); + g_free(base); base = NULL; } else { set_parents(base, base); From d70724cec84ff99ffc7f70dd567466acf228b389 Mon Sep 17 00:00:00 2001 From: zhanghailiang Date: Mon, 18 Aug 2014 15:58:08 +0800 Subject: [PATCH 02/11] tcg: dump op count into qemu log fopen() may fail and it does not check its return vaule here, it is better to dump op count to the normal log file. Signed-off-by: Li Liu Signed-off-by: zhanghailiang Signed-off-by: Michael Tokarev --- tcg/tcg.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index c068990fd5..7a84b871fc 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -2404,12 +2404,10 @@ static int64_t tcg_table_op_count[NB_OPS]; static void dump_op_count(void) { int i; - FILE *f; - f = fopen("/tmp/op.log", "w"); + for(i = INDEX_op_end; i < NB_OPS; i++) { - fprintf(f, "%s %" PRId64 "\n", tcg_op_defs[i].name, tcg_table_op_count[i]); + qemu_log("%s %" PRId64 "\n", tcg_op_defs[i].name, tcg_table_op_count[i]); } - fclose(f); } #endif From c39a28a43d95a3dcb339bdc2865e953a79f01378 Mon Sep 17 00:00:00 2001 From: zhanghailiang Date: Mon, 18 Aug 2014 15:54:33 +0800 Subject: [PATCH 03/11] tests/bios-tables-test: check the value returned by fopen() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function fopen() may fail, so check its return value. Signed-off-by: zhanghailiang Signed-off-by: Li Liu Reviewed-by: Alex Bennée Signed-off-by: Michael Tokarev --- tests/bios-tables-test.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index 045eb27577..602932b888 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -790,6 +790,11 @@ int main(int argc, char *argv[]) const char *arch = qtest_get_arch(); FILE *f = fopen(disk, "w"); int ret; + + if (!f) { + fprintf(stderr, "Couldn't open \"%s\": %s", disk, strerror(errno)); + return 1; + } fwrite(boot_sector, 1, sizeof boot_sector, f); fclose(f); From f55f8852675f1ece8739b5f89aeda8418c483367 Mon Sep 17 00:00:00 2001 From: Peter Crosthwaite Date: Sun, 17 Aug 2014 17:52:38 -0700 Subject: [PATCH 04/11] microblaze: ml605: Get rid of ddr_base variable It's a constant based on a macro. Just use the macro in place. Signed-off-by: Peter Crosthwaite Signed-off-by: Michael Tokarev --- hw/microblaze/petalogix_ml605_mmu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hw/microblaze/petalogix_ml605_mmu.c b/hw/microblaze/petalogix_ml605_mmu.c index aea9c5b49f..6843abf547 100644 --- a/hw/microblaze/petalogix_ml605_mmu.c +++ b/hw/microblaze/petalogix_ml605_mmu.c @@ -89,7 +89,6 @@ petalogix_ml605_init(MachineState *machine) SysBusDevice *busdev; DriveInfo *dinfo; int i; - hwaddr ddr_base = MEMORY_BASEADDR; MemoryRegion *phys_lmb_bram = g_new(MemoryRegion, 1); MemoryRegion *phys_ram = g_new(MemoryRegion, 1); qemu_irq irq[32]; @@ -106,7 +105,7 @@ petalogix_ml605_init(MachineState *machine) memory_region_init_ram(phys_ram, NULL, "petalogix_ml605.ram", ram_size); vmstate_register_ram_global(phys_ram); - memory_region_add_subregion(address_space_mem, ddr_base, phys_ram); + memory_region_add_subregion(address_space_mem, MEMORY_BASEADDR, phys_ram); dinfo = drive_get(IF_PFLASH, 0, 0); /* 5th parameter 2 means bank-width @@ -201,7 +200,7 @@ petalogix_ml605_init(MachineState *machine) } } - microblaze_load_kernel(cpu, ddr_base, ram_size, + microblaze_load_kernel(cpu, MEMORY_BASEADDR, ram_size, machine->initrd_filename, BINARY_DEVICE_TREE_FILE, machine_cpu_reset); From 6a07a695b0a8bf8638d28d06909a100c854cfc73 Mon Sep 17 00:00:00 2001 From: Peter Crosthwaite Date: Sun, 17 Aug 2014 17:53:12 -0700 Subject: [PATCH 05/11] dma: axidma: Variablise repeated s->streams[i] sub-expr This have 6 inline usages. Make it a bit more readable by using a local variable. Signed-off-by: Peter Crosthwaite Signed-off-by: Michael Tokarev --- hw/dma/xilinx_axidma.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hw/dma/xilinx_axidma.c b/hw/dma/xilinx_axidma.c index ee60d3ff39..d06002dde8 100644 --- a/hw/dma/xilinx_axidma.c +++ b/hw/dma/xilinx_axidma.c @@ -553,10 +553,12 @@ static void xilinx_axidma_realize(DeviceState *dev, Error **errp) int i; for (i = 0; i < 2; i++) { - s->streams[i].nr = i; - s->streams[i].bh = qemu_bh_new(timer_hit, &s->streams[i]); - s->streams[i].ptimer = ptimer_init(s->streams[i].bh); - ptimer_set_freq(s->streams[i].ptimer, s->freqhz); + struct Stream *st = &s->streams[i]; + + st->nr = i; + st->bh = qemu_bh_new(timer_hit, st); + st->ptimer = ptimer_init(st->bh); + ptimer_set_freq(st->ptimer, s->freqhz); } return; From 58ab9e680731ffd1793a7957ab8523f1dca18d05 Mon Sep 17 00:00:00 2001 From: Liming Wang Date: Tue, 19 Aug 2014 10:24:05 +0800 Subject: [PATCH 06/11] configure: no need to mkdir QMP commit 7537fe04 QMP: QMP/ -> docs/qmp/ Above commit has moved last QMP files to docs/qmp and it's not necessary to create QMP directory. So remove it from configure. Signed-off-by: Liming Wang Signed-off-by: Michael Tokarev --- configure | 4 ---- 1 file changed, 4 deletions(-) diff --git a/configure b/configure index c4e47e1ea1..2063cf6a3c 100755 --- a/configure +++ b/configure @@ -5372,10 +5372,6 @@ for rom in seabios vgabios ; do echo "LD=$ld" >> $config_mak done -if test "$docs" = "yes" ; then - mkdir -p QMP -fi - # set up qemu-iotests in this build directory iotests_common_env="tests/qemu-iotests/common.env" iotests_check="tests/qemu-iotests/check" From 2fd5d864099dd38b43b595e9e3375dad2f76049b Mon Sep 17 00:00:00 2001 From: zhanghailiang Date: Tue, 19 Aug 2014 16:30:17 +0800 Subject: [PATCH 07/11] slirp/misc: Use the GLib memory allocation APIs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Here we don't check the return value of malloc() which may fail. Use the g_new() instead, which will abort the program when there is not enough memory. Also, use g_strdup instead of strdup and remove the unnecessary strdup function. Signed-off-by: zhanghailiang Reviewed-by: Alex Bennée Reviewed-by: Benoît Canet Signed-off-by: Michael Tokarev --- slirp/misc.c | 20 +++----------------- slirp/misc.h | 4 ---- slirp/slirp_config.h | 3 --- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/slirp/misc.c b/slirp/misc.c index b8eb74cab0..6543dc7772 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -54,11 +54,11 @@ int add_exec(struct ex_list **ex_ptr, int do_pty, char *exec, } tmp_ptr = *ex_ptr; - *ex_ptr = (struct ex_list *)malloc(sizeof(struct ex_list)); + *ex_ptr = g_new(struct ex_list, 1); (*ex_ptr)->ex_fport = port; (*ex_ptr)->ex_addr = addr; (*ex_ptr)->ex_pty = do_pty; - (*ex_ptr)->ex_exec = (do_pty == 3) ? exec : strdup(exec); + (*ex_ptr)->ex_exec = (do_pty == 3) ? exec : g_strdup(exec); (*ex_ptr)->ex_next = tmp_ptr; return 0; } @@ -187,7 +187,7 @@ fork_exec(struct socket *so, const char *ex, int do_pty) bptr++; c = *bptr; *bptr++ = (char)0; - argv[i++] = strdup(curarg); + argv[i++] = g_strdup(curarg); } while (c); argv[i] = NULL; @@ -228,20 +228,6 @@ fork_exec(struct socket *so, const char *ex, int do_pty) } #endif -#ifndef HAVE_STRDUP -char * -strdup(str) - const char *str; -{ - char *bptr; - - bptr = (char *)malloc(strlen(str)+1); - strcpy(bptr, str); - - return bptr; -} -#endif - void slirp_connection_info(Slirp *slirp, Monitor *mon) { const char * const tcpstates[] = { diff --git a/slirp/misc.h b/slirp/misc.h index ba8beb1b17..41a32583da 100644 --- a/slirp/misc.h +++ b/slirp/misc.h @@ -16,10 +16,6 @@ struct ex_list { struct ex_list *ex_next; }; -#ifndef HAVE_STRDUP -char *strdup(const char *); -#endif - #define EMU_NONE 0x0 /* TCP emulations */ diff --git a/slirp/slirp_config.h b/slirp/slirp_config.h index 18db45c8e4..896d8022eb 100644 --- a/slirp/slirp_config.h +++ b/slirp/slirp_config.h @@ -72,9 +72,6 @@ /* Define if you have strerror */ #define HAVE_STRERROR -/* Define if you have strdup() */ -#define HAVE_STRDUP - /* Define according to how time.h should be included */ #define TIME_WITH_SYS_TIME 0 #undef HAVE_SYS_TIME_H From bcc55f327c571295193880110c048b463bce6677 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Fri, 18 Jul 2014 16:52:29 +0200 Subject: [PATCH 08/11] po: Fix Makefile rules for in-tree builds without configuration Adding 'update' to the phony targets fixes this error: $ LANG=C make -C po update make: Entering directory `/qemu/po' LINK update /qemu/po/de_DE.po: file not recognized: File format not recognized collect2: error: ld returned 1 exit status make: *** [update] Error 1 make: Leaving directory `/qemu/po' Some other phony targets (build, install) were also added, and the existing .PHONY statement was moved to a more prominent position at the beginning of the Makefile. The patch also fixes a 2nd bug. The default target should be 'all', but instead 'modules' (from rules.mak) was the default. Fix this by adding 'all' as a target before any include statement. Signed-off-by: Stefan Weil Signed-off-by: Michael Tokarev --- po/Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/po/Makefile b/po/Makefile index 669f8654a6..1ab241a5b7 100644 --- a/po/Makefile +++ b/po/Makefile @@ -4,6 +4,11 @@ # Set SRC_PATH for in-tree builds without configuration. SRC_PATH=.. +# The default target must come before any include statements. +all: + +.PHONY: all build clean install update + -include ../config-host.mak include $(SRC_PATH)/rules.mak @@ -45,5 +50,3 @@ $(PO_PATH)/messages.po: $(SRC_PATH)/ui/gtk.c $(PO_PATH)/%.po: $(PO_PATH)/messages.po $(call quiet-command, msgmerge -q $@ $< > $@.bak && mv $@.bak $@, " GEN $@") - -.PHONY: clean all From 680dfde91981516942ec557ef1c27753db24cbe8 Mon Sep 17 00:00:00 2001 From: zhanghailiang Date: Fri, 22 Aug 2014 16:23:51 +0800 Subject: [PATCH 09/11] linux-user: fix file descriptor leaks Handle variable "fd_orig" going out of scope leaks the handle. Signed-off-by: zhanghailiang Reviewed-by: Gonglei Signed-off-by: Michael Tokarev --- linux-user/syscall.c | 1 + 1 file changed, 1 insertion(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 7ff7c21255..8fe9df7b87 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5167,6 +5167,7 @@ static int open_self_cmdline(void *cpu_env, int fd) if (word_skipped) { if (write(fd, cp_buf, nb_read) != nb_read) { + close(fd_orig); return -1; } } From d072cdf3baeab6a190aa9f2f64a8702744f83d29 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Wed, 20 Aug 2014 11:02:10 +0200 Subject: [PATCH 10/11] libdecnumber: Fix warnings from smatch (missing static, boolean operations) Signed-off-by: Stefan Weil Signed-off-by: Michael Tokarev --- libdecnumber/decNumber.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/libdecnumber/decNumber.c b/libdecnumber/decNumber.c index a30632f94e..58211e7afd 100644 --- a/libdecnumber/decNumber.c +++ b/libdecnumber/decNumber.c @@ -5275,8 +5275,8 @@ static decNumber * decMultiplyOp(decNumber *res, const decNumber *lhs, /* 4. The working precisions for the static buffers are twice the */ /* obvious size to allow for calls from decNumberPower. */ /* ------------------------------------------------------------------ */ -decNumber * decExpOp(decNumber *res, const decNumber *rhs, - decContext *set, uInt *status) { +static decNumber *decExpOp(decNumber *res, const decNumber *rhs, + decContext *set, uInt *status) { uInt ignore=0; /* working status */ Int h; /* adjusted exponent for 0.xxxx */ Int p; /* working precision */ @@ -5563,7 +5563,8 @@ decNumber * decExpOp(decNumber *res, const decNumber *rhs, /* where x is truncated (NB) into the range 10 through 99, */ /* and then c = k>>2 and e = k&3. */ /* ------------------------------------------------------------------ */ -const uShort LNnn[90]={9016, 8652, 8316, 8008, 7724, 7456, 7208, +static const uShort LNnn[90] = { + 9016, 8652, 8316, 8008, 7724, 7456, 7208, 6972, 6748, 6540, 6340, 6148, 5968, 5792, 5628, 5464, 5312, 5164, 5020, 4884, 4748, 4620, 4496, 4376, 4256, 4144, 4032, 39233, 38181, 37157, 36157, 35181, 34229, 33297, 32389, 31501, 30629, @@ -5635,8 +5636,8 @@ const uShort LNnn[90]={9016, 8652, 8316, 8008, 7724, 7456, 7208, /* 5. The static buffers are larger than might be expected to allow */ /* for calls from decNumberPower. */ /* ------------------------------------------------------------------ */ -decNumber * decLnOp(decNumber *res, const decNumber *rhs, - decContext *set, uInt *status) { +static decNumber *decLnOp(decNumber *res, const decNumber *rhs, + decContext *set, uInt *status) { uInt ignore=0; /* working status accumulator */ uInt needbytes; /* for space calculations */ Int residue; /* rounding residue */ @@ -6052,9 +6053,9 @@ static decNumber * decQuantizeOp(decNumber *res, const decNumber *lhs, /* The emphasis here is on speed for common cases, and avoiding */ /* coefficient comparison if possible. */ /* ------------------------------------------------------------------ */ -decNumber * decCompareOp(decNumber *res, const decNumber *lhs, - const decNumber *rhs, decContext *set, - Flag op, uInt *status) { +static decNumber *decCompareOp(decNumber *res, const decNumber *lhs, + const decNumber *rhs, decContext *set, + Flag op, uInt *status) { #if DECSUBSET decNumber *alloclhs=NULL; /* non-NULL if rounded lhs allocated */ decNumber *allocrhs=NULL; /* .., rhs */ @@ -6086,11 +6087,11 @@ decNumber * decCompareOp(decNumber *res, const decNumber *lhs, /* If total ordering then handle differing signs 'up front' */ if (op==COMPTOTAL) { /* total ordering */ - if (decNumberIsNegative(lhs) & !decNumberIsNegative(rhs)) { + if (decNumberIsNegative(lhs) && !decNumberIsNegative(rhs)) { result=-1; break; } - if (!decNumberIsNegative(lhs) & decNumberIsNegative(rhs)) { + if (!decNumberIsNegative(lhs) && decNumberIsNegative(rhs)) { result=+1; break; } From 40a87c6c9b11ef9c14e0301f76abf0eb2582f08e Mon Sep 17 00:00:00 2001 From: Ben Draper Date: Wed, 20 Aug 2014 13:27:14 +0100 Subject: [PATCH 11/11] vmxnet3: Pad short frames to minimum size (60 bytes) When running VMware ESXi under qemu-kvm the guest discards frames that are too short. Short ARP Requests will be dropped, this prevents guests on the same bridge as VMware ESXi from communicating. This patch simply adds the padding on the network device itself. Signed-off-by: Ben Draper Reviewed-by: Dmitry Fleytman Cc: qemu-stable@nongnu.org Signed-off-by: Michael Tokarev --- hw/net/vmxnet3.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c index 791321fa49..f246fa1c45 100644 --- a/hw/net/vmxnet3.c +++ b/hw/net/vmxnet3.c @@ -34,6 +34,7 @@ #define PCI_DEVICE_ID_VMWARE_VMXNET3_REVISION 0x1 #define VMXNET3_MSIX_BAR_SIZE 0x2000 +#define MIN_BUF_SIZE 60 #define VMXNET3_BAR0_IDX (0) #define VMXNET3_BAR1_IDX (1) @@ -1871,12 +1872,21 @@ vmxnet3_receive(NetClientState *nc, const uint8_t *buf, size_t size) { VMXNET3State *s = qemu_get_nic_opaque(nc); size_t bytes_indicated; + uint8_t min_buf[MIN_BUF_SIZE]; if (!vmxnet3_can_receive(nc)) { VMW_PKPRN("Cannot receive now"); return -1; } + /* Pad to minimum Ethernet frame length */ + if (size < sizeof(min_buf)) { + memcpy(min_buf, buf, size); + memset(&min_buf[size], 0, sizeof(min_buf) - size); + buf = min_buf; + size = sizeof(min_buf); + } + if (s->peer_has_vhdr) { vmxnet_rx_pkt_set_vhdr(s->rx_pkt, (struct virtio_net_hdr *)buf); buf += sizeof(struct virtio_net_hdr);