Misc trivial code cleanups
Subsystems (4)
PATCH 1/7 maint: remove double semicolons in many files
In reply to Daniel P. BerrangeA number of source files have statements accidentally terminated by a double semicolon - eg 'foo = bar;;'. This is harmless but a mistake none the less.
The tcg/ia64/tcg-target.c file is whitelisted because it has valid use of ';;' in a comment containing assembly code.
--- block/vhdx.c | 2 +- hw/arm/vexpress.c | 4 ++-- hw/intc/arm_gic.c | 2 +- numa.c | 2 +- qga/commands-win32.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-)
block/vhdx.c +1 -1
@@ -1454,7 +1454,7 @@ static int vhdx_create_new_metadata(BlockDriverState *bs,uint32_t offset =0 ;void *buffer =NULL ;void *entry_buffer; -VHDXMetadataTableHeader *md_table;; +VHDXMetadataTableHeader *md_table;VHDXMetadataTableEntry *md_table_entry;/* Metadata entries */
hw/arm/vexpress.c +2 -2
@@ -541,7 +541,7 @@ static void vexpress_common_init(MachineState *machine) {VexpressMachineState *vms =VEXPRESS_MACHINE (machine);VexpressMachineClass *vmc =VEXPRESS_MACHINE_GET_CLASS (machine); -VEDBoardInfo *daughterboard = vmc->daughterboard;; +VEDBoardInfo *daughterboard = vmc->daughterboard;DeviceState *dev, *sysctl, *pl041;qemu_irq pic[64 ];uint32_t sys_id;
@@ -762,7 +762,7 @@ static void vexpress_a9_class_init(ObjectClass *oc, void *data) mc->name =TYPE_VEXPRESS_A9_MACHINE ; mc->desc ="ARM Versatile Express for Cortex-A9" ; - vmc->daughterboard = &a9_daughterboard;; + vmc->daughterboard = &a9_daughterboard; }static void vexpress_a15_class_init (ObjectClass *oc,void *data)
hw/intc/arm_gic.c +1 -1
@@ -239,7 +239,7 @@ uint32_t gic_acknowledge_irq(GICState *s, int cpu, MemTxAttrs attrs)* for the case where this GIC supports grouping and the pending interrupt * is in the wrong group. */ - irq =gic_get_current_pending_irq (s, cpu, attrs);; + irq =gic_get_current_pending_irq (s, cpu, attrs);if (irq >=GIC_MAXIRQ ) {DPRINTF ("ACK, no pending interrupt or it is hidden: %d\n" , irq);
numa.c +1 -1
@@ -280,7 +280,7 @@ static void validate_numa_cpus(void)bitmap_and (seen_cpus, seen_cpus, numa_info[i].node_cpu,MAX_CPUMASK_BITS );error_report ("CPU(s) present in multiple NUMA nodes: %s" , -enumerate_cpus (seen_cpus, max_cpus));; +enumerate_cpus (seen_cpus, max_cpus));exit (EXIT_FAILURE ); } bitmap_or(seen_cpus, seen_cpus,
qga/commands-win32.c +1 -1
@@ -657,7 +657,7 @@ static GuestFilesystemInfo *build_guest_fsinfo(char *guid, Error **errp) fs->mountpoint =g_strndup (mnt_point, len); } fs->type =g_strdup (fs_name); - fs->disk =build_guest_disk_info (guid, errp);; + fs->disk =build_guest_disk_info (guid, errp); free:g_free (mnt_point);return fs;
Signature · 1 line
2.4.3
PATCH 3/7 maint: remove unused include for assert.h
In reply to Daniel P. BerrangeA number of files were including assert.h but not using any of the functions it provides
--- disas/ia64.c | 1 - hw/i386/xen/xen_platform.c | 2 -- linux-user/signal.c | 1 - target-microblaze/op_helper.c | 1 - target-moxie/helper.c | 1 - target-moxie/translate.c | 1 - target-sh4/op_helper.c | 1 - tests/test-xbzrle.c | 1 - 8 files changed, 9 deletions(-)
disas/ia64.c +0 -1
@@ -18,7 +18,6 @@ along with this file; see the file COPYING. If not, see <http://www.gnu.org/licenses/>. */ -#include <assert.h> #include <string.h> #include "disas/bfd.h"
hw/i386/xen/xen_platform.c +0 -2
@@ -23,8 +23,6 @@* THE SOFTWARE. */ -#include <assert.h> -#include "hw/hw.h" #include "hw/i386/pc.h" #include "hw/ide.h"
linux-user/signal.c +0 -1
@@ -22,7 +22,6 @@#include <stdarg.h> #include <unistd.h> #include <errno.h> -#include <assert.h> #include <sys/ucontext.h> #include <sys/resource.h>
target-microblaze/op_helper.c +0 -1
@@ -18,7 +18,6 @@* License along with this library; if not, see <http://www.gnu.org/licenses/>. */ -#include <assert.h> #include "cpu.h" #include "exec/helper-proto.h" #include "qemu/host-utils.h"
target-moxie/helper.c +0 -1
@@ -19,7 +19,6 @@#include <stdio.h> #include <string.h> -#include <assert.h> #include "config.h" #include "cpu.h"
target-moxie/translate.c +0 -1
@@ -26,7 +26,6 @@#include <stdio.h> #include <string.h> #include <inttypes.h> -#include <assert.h> #include "cpu.h" #include "exec/exec-all.h"
target-sh4/op_helper.c +0 -1
@@ -16,7 +16,6 @@* You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see <http://www.gnu.org/licenses/>. */ -#include <assert.h> #include <stdlib.h> #include "cpu.h" #include "exec/helper-proto.h"
tests/test-xbzrle.c +0 -1
@@ -16,7 +16,6 @@#include <strings.h> #include <string.h> #include <sys/time.h> -#include <assert.h> #include "qemu-common.h" #include "include/migration/migration.h"
Signature · 1 line
2.4.3
PATCH 4/7 maint: remove unused include for dirent.h
In reply to Daniel P. BerrangeA number of files were including dirent.h but not using any of the functions it provides
--- fsdev/virtio-9p-marshal.c | 1 - hw/tpm/tpm_passthrough.c | 2 -- hw/usb/redirect.c | 1 - hw/vfio/pci.c | 1 - qemu-char.c | 1 - 5 files changed, 6 deletions(-)
fsdev/virtio-9p-marshal.c +0 -1
@@ -14,7 +14,6 @@#include <glib.h> #include <glib/gprintf.h> #include <sys/types.h> -#include <dirent.h> #include <sys/time.h> #include <utime.h> #include <sys/uio.h>
hw/tpm/tpm_passthrough.c +0 -2
@@ -22,8 +22,6 @@* License along with this library; if not, see <http://www.gnu.org/licenses/> */ -#include <dirent.h> -#include "qemu-common.h" #include "qapi/error.h" #include "qemu/error-report.h"
hw/usb/redirect.c +0 -1
@@ -33,7 +33,6 @@#include "qemu/iov.h" #include "sysemu/char.h" -#include <dirent.h> #include <sys/ioctl.h> #include <signal.h> #include <usbredirparser.h>
hw/vfio/pci.c +0 -1
@@ -18,7 +18,6 @@* Copyright (C) 2008, IBM, Muli Ben-Yehuda ([email protected]) */ -#include <dirent.h> #include <linux/vfio.h> #include <sys/ioctl.h> #include <sys/mman.h>
qemu-char.c +0 -1
@@ -51,7 +51,6 @@#include <netinet/in.h> #include <net/if.h> #include <arpa/inet.h> -#include <dirent.h> #include <netdb.h> #include <sys/select.h> #ifdef CONFIG_BSD
Signature · 1 line
2.4.3
cover Misc trivial code cleanups
This is a series of misc trivial code cleanups that I originally used to illustrate the use of GNULIB's syntax-check facility:
http://lists.nongnu.org/archive/html/qemu-devel/2015-07/msg06268.html
Since it appears the license of the GNULIB syntax-check is problematic, this series has separated the fixes out from the GNULIB additions, to allow for possibility of merging them as-is.
Daniel P. Berrange (7):
maint: remove double semicolons in many files
maint: remove / fix many doubled words
maint: remove unused include for assert.h
maint: remove unused include for dirent.h
maint: remove unused include for signal.h
maint: remove unused include for strings.h
maint: avoid useless "if (foo) free(foo)" pattern
backends/hostmem-file.c | 4 +--- block/qcow2-cluster.c | 4 ++-- block/qcow2-refcount.c | 2 +- block/vhdx.c | 2 +- bsd-user/elfload.c | 4 +--- bsd-user/signal.c | 1 - disas/ia64.c | 1 - disas/microblaze.c | 1 - disas/sparc.c | 3 +-- docs/libcacard.txt | 4 ++-- docs/multiseat.txt | 2 +- docs/specs/qcow2.txt | 2 +- docs/specs/rocker.txt | 2 +- fsdev/virtio-9p-marshal.c | 1 - hw/arm/vexpress.c | 4 ++-- hw/block/xen_disk.c | 1 - hw/bt/hci.c | 9 +++------ hw/core/loader.c | 3 +-- hw/core/qdev-properties.c | 4 +--- hw/display/exynos4210_fimd.c | 4 +--- hw/i386/xen/xen_platform.c | 2 -- hw/intc/arm_gic.c | 2 +- hw/mips/mips_r4k.c | 4 +--- hw/net/fsl_etsec/rings.c | 4 +--- hw/net/rocker/rocker.c | 4 +--- hw/net/rocker/rocker_desc.c | 8 ++------ hw/net/rtl8139.c | 2 +- hw/net/xen_nic.c | 1 - hw/nvram/fw_cfg.c | 4 +--- hw/pci-host/prep.c | 4 +--- hw/pci/shpc.c | 1 - hw/sd/sd.c | 3 +-- hw/tpm/tpm_passthrough.c | 2 -- hw/usb/hcd-xhci.c | 4 +--- hw/usb/host-libusb.c | 2 +- hw/usb/redirect.c | 2 -- hw/vfio/common.c | 2 +- hw/vfio/pci.c | 1 - hw/xen/xen_pt_config_init.c | 4 +--- include/block/block.h | 2 +- include/exec/memory.h | 2 +- linux-user/elfload.c | 2 +- linux-user/signal.c | 1 - migration/rdma.c | 2 +- migration/savevm.c | 8 ++------ numa.c | 2 +- os-win32.c | 1 - page_cache.c | 1 - qemu-char.c | 5 +---- qemu-doc.texi | 2 +- qemu-img.texi | 2 +- qemu-options.hx | 2 +- qga/commands-win32.c | 2 +- target-arm/cpu.h | 4 ++-- target-arm/helper.c | 2 +- target-arm/translate.c | 2 +- target-i386/translate.c | 1 - target-lm32/helper.c | 2 +- target-microblaze/op_helper.c | 1 - target-microblaze/translate.c | 2 +- target-mips/helper.c | 1 - target-moxie/helper.c | 3 +-- target-moxie/translate.c | 1 - target-sh4/helper.c | 1 - target-sh4/op_helper.c | 1 - target-tricore/helper.c | 1 - tests/bios-tables-test.c | 36 +++++++++++++----------------------- tests/tcg/testthread.c | 1 - tests/test-xbzrle.c | 2 -- ui/spice-display.c | 14 ++++---------- util/bitmap.c | 2 +- 71 files changed, 71 insertions(+), 154 deletions(-)
Signature · 1 line
2.4.3
PATCH 5/7 maint: remove unused include for signal.h
A number of files were including signal.h but not using any of the functions it provides
--- bsd-user/signal.c | 1 - hw/block/xen_disk.c | 1 - hw/net/xen_nic.c | 1 - hw/usb/redirect.c | 1 - os-win32.c | 1 - target-i386/translate.c | 1 - target-mips/helper.c | 1 - target-sh4/helper.c | 1 - target-tricore/helper.c | 1 - tests/tcg/testthread.c | 1 - 10 files changed, 10 deletions(-)
bsd-user/signal.c +0 -1
@@ -21,7 +21,6 @@#include <string.h> #include <stdarg.h> #include <unistd.h> -#include <signal.h> #include <errno.h> #include "qemu.h"
hw/block/xen_disk.c +0 -1
@@ -24,7 +24,6 @@#include <stdarg.h> #include <string.h> #include <unistd.h> -#include <signal.h> #include <inttypes.h> #include <time.h> #include <fcntl.h>
hw/net/xen_nic.c +0 -1
@@ -24,7 +24,6 @@#include <stdarg.h> #include <string.h> #include <unistd.h> -#include <signal.h> #include <inttypes.h> #include <fcntl.h> #include <errno.h>
hw/usb/redirect.c +0 -1
@@ -34,7 +34,6 @@#include "sysemu/char.h" #include <sys/ioctl.h> -#include <signal.h> #include <usbredirparser.h> #include <usbredirfilter.h>
os-win32.c +0 -1
@@ -26,7 +26,6 @@#include <mmsystem.h> #include <unistd.h> #include <fcntl.h> -#include <signal.h> #include <time.h> #include <errno.h> #include <sys/time.h>
target-i386/translate.c +0 -1
@@ -21,7 +21,6 @@#include <stdio.h> #include <string.h> #include <inttypes.h> -#include <signal.h> #include "qemu/host-utils.h" #include "cpu.h"
target-mips/helper.c +0 -1
@@ -21,7 +21,6 @@#include <stdio.h> #include <string.h> #include <inttypes.h> -#include <signal.h> #include "cpu.h" #include "sysemu/kvm.h"
target-sh4/helper.c +0 -1
@@ -21,7 +21,6 @@#include <stdio.h> #include <string.h> #include <inttypes.h> -#include <signal.h> #include "cpu.h"
target-tricore/helper.c +0 -1
@@ -20,7 +20,6 @@#include <stdio.h> #include <string.h> #include <inttypes.h> -#include <signal.h> #include "cpu.h"
tests/tcg/testthread.c +0 -1
@@ -2,7 +2,6 @@#include <stdlib.h> #include <stdio.h> #include <string.h> -#include <signal.h> #include <unistd.h> #include <inttypes.h> #include <pthread.h>
Signature · 1 line
2.4.3
PATCH 6/7 maint: remove unused include for strings.h
In reply to Daniel P. BerrangeA number of files were including strings.h but not using any of the functions it provides
--- disas/microblaze.c | 1 - hw/pci/shpc.c | 1 - page_cache.c | 1 - tests/test-xbzrle.c | 1 - 4 files changed, 4 deletions(-)
disas/microblaze.c +0 -1
@@ -582,7 +582,6 @@ static const char pvr_register_prefix[] = "rpvr";#endif /* MICROBLAZE_OPC */ #include "disas/bfd.h" -#include <strings.h> #define get_field_rd (instr) get_field(instr, RD_MASK, RD_LOW)#define get_field_r1 (instr) get_field(instr, RA_MASK, RA_LOW)
hw/pci/shpc.c +0 -1
@@ -1,5 +1,4 @@#include "qemu-common.h" -#include <strings.h> #include <stdint.h> #include "qemu/range.h" #include "qemu/error-report.h"
page_cache.c +0 -1
@@ -15,7 +15,6 @@#include <stdint.h> #include <stdio.h> #include <stdlib.h> -#include <strings.h> #include <string.h> #include <sys/time.h> #include <sys/types.h>
tests/test-xbzrle.c +0 -1
@@ -13,7 +13,6 @@#include <stdint.h> #include <stdio.h> #include <stdlib.h> -#include <strings.h> #include <string.h> #include <sys/time.h> #include "qemu-common.h"
Signature · 1 line
2.4.3
PATCH 2/7 maint: remove / fix many doubled words
In reply to Daniel P. BerrangeMany source files have doubled words (eg "the the", "to to", and so on). Most of these can simply be removed, but a couple were actual mis-spellings (eg "to to" instead of "to do"). There was even one triple word score "to to to" :-)
--- block/qcow2-cluster.c | 4 ++-- block/qcow2-refcount.c | 2 +- docs/libcacard.txt | 4 ++-- docs/multiseat.txt | 2 +- docs/specs/qcow2.txt | 2 +- docs/specs/rocker.txt | 2 +- hw/net/rtl8139.c | 2 +- hw/usb/host-libusb.c | 2 +- hw/vfio/common.c | 2 +- include/block/block.h | 2 +- include/exec/memory.h | 2 +- linux-user/elfload.c | 2 +- migration/rdma.c | 2 +- qemu-doc.texi | 2 +- qemu-img.texi | 2 +- qemu-options.hx | 2 +- target-arm/cpu.h | 4 ++-- target-arm/helper.c | 2 +- target-arm/translate.c | 2 +- target-lm32/helper.c | 2 +- target-microblaze/translate.c | 2 +- target-moxie/helper.c | 2 +- util/bitmap.c | 2 +- 23 files changed, 26 insertions(+), 26 deletions(-)
block/qcow2-cluster.c +2 -2
@@ -498,7 +498,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset, *cluster_offset =0 ; -/* seek the the l2 offset in the l1 table */ +/* seek to the l2 offset in the l1 table */ l1_index = offset >> l1_bits;if (l1_index >= s->l1_size) {
@@ -612,7 +612,7 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t offset,uint64_t *l2_table =NULL ;int ret; -/* seek the the l2 offset in the l1 table */ +/* seek to the l2 offset in the l1 table */ l1_index = offset >> (s->l2_bits + s->cluster_bits);if (l1_index >= s->l1_size) {
block/qcow2-refcount.c +1 -1
@@ -1294,7 +1294,7 @@ static int realloc_refcount_array(BDRVQcowState *s, void **array,/* * Increases the refcount for a range of clusters in a given refcount table. * This is used to construct a temporary refcount table out of L1 and L2 tables -* which can be compared the the refcount table saved in the image. +* which can be compared to the refcount table saved in the image. * * Modifies the number of errors in res. */
docs/libcacard.txt +2 -2
@@ -327,7 +327,7 @@ and applet. int vcard_emul_get_login_count(VCard *card); - This function returns the the number of remaining login attempts for this + This function returns the number of remaining login attempts for this card. If the card emulator does not know, or the card does not have a way of giving this information, this function returns -1.
@@ -421,7 +421,7 @@ functions: The vcard is the value returned from vcard_new. The type is the card type emulator that this card should presented to the guest as. The flags are card type emulator specific options. The certs, - cert_len, and keys are all arrays of length cert_count. These are the + cert_len, and keys are all arrays of length cert_count. These are the same of the parameters xxxx_card_init() accepts. Finally the card is associated with its reader by the call:
docs/multiseat.txt +1 -1
@@ -135,7 +135,7 @@ configuration: TAG+="seat", ENV{ID_AUTOSEAT}="1" Patch with this rule has been submitted to upstream udev/systemd, was -accepted and and should be included in the next systemd release (222). +accepted and should be included in the next systemd release (222). So, if your guest has this or a newer version, multiseat will work just fine without any manual guest configuration.
docs/specs/qcow2.txt +1 -1
@@ -257,7 +257,7 @@ L2 table entry: 63: 0 for a cluster that is unused or requires COW, 1 if its refcount is exactly one. This information is only accurate - in L2 tables that are reachable from the the active L1 + in L2 tables that are reachable from the active L1 table. Standard Cluster Descriptor:
docs/specs/rocker.txt +1 -1
@@ -297,7 +297,7 @@ but not fired. If only partial credits are returned, the interrupt remains masked but the device generates an interrupt, signaling the driver that more outstanding work is available. -(* this masking is unrelated to to the MSI-X interrupt mask register) +(* this masking is unrelated to the MSI-X interrupt mask register) Endianness ----------
hw/net/rtl8139.c +1 -1
@@ -43,7 +43,7 @@* Added rx/tx buffer reset when enabling rx/tx operation * * 2010-Feb-04 Frediano Ziglio: Rewrote timer support using QEMU timer only -* when strictly needed (required for for +* when strictly needed (required for * Darwin) * 2011-Mar-22 Benjamin Poirier: Implemented VLAN offloading */
hw/usb/host-libusb.c +1 -1
@@ -1429,7 +1429,7 @@ static void usb_host_free_streams(USBDevice *udev, USBEndpoint **eps,* still present in the first place. Attemping to contine where we * left off is impossible. * -* What we are going to to to here is emulate a surprise removal of +* What we are going to do here is emulate a surprise removal of * the usb device passed through, then kick host scan so the device * will get re-attached (and re-initialized by the guest) in case it * is still present.
hw/vfio/common.c +1 -1
@@ -226,7 +226,7 @@ static int vfio_dma_map(VFIOContainer *container, hwaddr iova,/* * Try the mapping, if it fails with EBUSY, unmap the region and try * again. This shouldn't be necessary, but we sometimes see it in -* the the VGA ROM space. +* the VGA ROM space. */ if (ioctl(container->fd, VFIO_IOMMU_MAP_DMA, &map) == 0 || (errno == EBUSY && vfio_dma_unmap(container, iova, size) == 0 &&
include/block/block.h +1 -1
@@ -23,7 +23,7 @@ typedef struct BlockDriverInfo {bool is_dirty;/* * True if unallocated blocks read back as zeroes. This is equivalent -* to the the LBPRZ flag in the SCSI logical block provisioning page. +* to the LBPRZ flag in the SCSI logical block provisioning page. */ bool unallocated_blocks_are_zero;/*
include/exec/memory.h +1 -1
@@ -324,7 +324,7 @@ void memory_region_unref(MemoryRegion *mr);* @owner: the object that tracks the region's reference count * @ops: a structure containing read and write callbacks to be used when * I/O is performed on the region. -* @opaque: passed to to the read and write callbacks of the @ops structure. +* @opaque: passed to the read and write callbacks of the @ops structure. * @name: used for debugging; not visible to the user or ABI * @size: size of the region. */
linux-user/elfload.c +1 -1
@@ -3016,7 +3016,7 @@ static int elf_core_dump(int signr, const CPUArchState *env)if (dump_write (fd, &elf,sizeof (elf)) !=0 ) goto out; -/* fill in in-memory version of notes */ +/* fill in the in-memory version of notes */ if (fill_note_info (&info, signr, env) <0 ) goto out;
migration/rdma.c +1 -1
@@ -778,7 +778,7 @@ static void qemu_rdma_dump_gid(const char *who, struct rdma_cm_id *id)* * If the source VM connects with an IPv4 address without knowing that the * destination has bound to '[::]' the migration will unconditionally fail -* unless the management software is explicitly listening on the the IPv4 +* unless the management software is explicitly listening on the IPv4 * address while using a RoCE-based device. * * If the source VM connects with an IPv6 address, then we're OK because we can
qemu-doc.texi +1 -1
@@ -1766,7 +1766,7 @@ Use @code{set architecture i8086} to dump 16 bit code. Then use Advanced debugging options: -The default single stepping behavior is step with the IRQs and timer service routines off. It is set this way because when gdb executes a single step it expects to advance beyond the current instruction. With the IRQs and and timer service routines on, a single step might jump into the one of the interrupt or exception vectors instead of executing the current instruction. This means you may hit the same breakpoint a number of times before executing the instruction gdb wants to have executed. Because there are rare circumstances where you want to single step into an interrupt vector the behavior can be controlled from GDB. There are three commands you can query and set the single step behavior: +The default single stepping behavior is step with the IRQs and timer service routines off. It is set this way because when gdb executes a single step it expects to advance beyond the current instruction. With the IRQs and timer service routines on, a single step might jump into the one of the interrupt or exception vectors instead of executing the current instruction. This means you may hit the same breakpoint a number of times before executing the instruction gdb wants to have executed. Because there are rare circumstances where you want to single step into an interrupt vector the behavior can be controlled from GDB. There are three commands you can query and set the single step behavior: @table @code @item maintenance packet qqemu.sstepbits
qemu-img.texi +1 -1
@@ -103,7 +103,7 @@ First image format @item -F Second image format @item -s -Strict mode - fail on on different image size or sector allocation +Strict mode - fail on different image size or sector allocation @end table Parameters to convert subcommand:
qemu-options.hx +1 -1
@@ -3147,7 +3147,7 @@ provide cycle accurate emulation. Modern CPUs contain superscalar out of order cores with complex cache hierarchies. The number of instructions executed often has little or no correlation with actual performance. -@option{align=on} will activate the delay algorithm which will try to +@option{align=on} will activate the delay algorithm which will try to synchronise the host clock and the virtual clock. The goal is to have a guest running at the real frequency imposed by the shift option. Whenever the guest clock is behind the host clock and if
target-arm/cpu.h +2 -2
@@ -172,7 +172,7 @@ typedef struct CPUARMState {uint32_t GE ;/* cpsr[19:16] */ uint32_t thumb;/* cpsr[5]. 0 = arm mode, 1 = thumb mode. */ uint32_t condexec_bits;/* IT bits. cpsr[15:10,26:25]. */ -uint64_t daif;/* exception masks, in the bits they are in in PSTATE */ +uint64_t daif;/* exception masks, in the bits they are in PSTATE */ uint64_t elr_el[4 ];/* AArch64 exception link regs */ uint64_t sp_el[4 ];/* AArch64 banked stack pointers */
@@ -1484,7 +1484,7 @@ bool write_list_to_cpustate(ARMCPU *cpu);*/ bool write_cpustate_to_list (ARMCPU *cpu); -/* Does the core conform to the the "MicroController" profile. e.g. Cortex-M3. +/* Does the core conform to the "MicroController" profile. e.g. Cortex-M3. Note the M in older cores (eg. ARM7TDMI) stands for Multiply. These are conventional cores (ie. Application or Realtime profile). */
target-arm/helper.c +1 -1
@@ -2094,7 +2094,7 @@ static void vmsa_ttbcr_raw_write(CPUARMState *env, const ARMCPRegInfo *ri, } } -/* Update the masks corresponding to the the TCR bank being written +/* Update the masks corresponding to the TCR bank being written * Note that we always calculate mask and base_mask, but * they are only used for short-descriptor tables (ie if EAE is 0); * for long-descriptor tables the TCR fields are used differently
target-arm/translate.c +1 -1
@@ -8500,7 +8500,7 @@ static void disas_arm_insn(DisasContext *s, unsigned int insn) }/* Perform base writeback before the loaded value to ensure correct behavior with overlapping index registers. -ldrd with base writeback is is undefined if the +ldrd with base writeback is undefined if the destination and index registers overlap. */ if (!(insn & (1 <<24 ))) {gen_add_datah_offset (s, insn, address_offset, addr);
target-lm32/helper.c +1 -1
@@ -81,7 +81,7 @@ void lm32_watchpoint_insert(CPULM32State *env, int idx, target_ulong address,switch (wp_type) {case LM32_WP_DISABLED : -/* nothing to to */ +/* nothing to do */ break ;case LM32_WP_READ : flags =BP_CPU |BP_STOP_BEFORE_ACCESS |BP_MEM_READ ;
target-microblaze/translate.c +1 -1
@@ -1027,7 +1027,7 @@ static void dec_load(DisasContext *dc)tcg_temp_free (v);if (ex) {/* lwx */ -/* no support for for AXI exclusive so always clear C */ +/* no support for AXI exclusive so always clear C */ write_carryi (dc,0 ); }
target-moxie/helper.c +1 -1
@@ -56,7 +56,7 @@ void helper_raise_exception(CPUMoxieState *env, int ex)/* Stash the address where the exception occurred. */ cpu_restore_state (cs,GETPC ()); env->sregs[5 ] = env->pc; -/* Jump the the exception handline routine. */ +/* Jump to the exception handline routine. */ env->pc = env->sregs[1 ];cpu_loop_exit (cs); }
util/bitmap.c +1 -1
@@ -14,7 +14,7 @@#include "qemu/atomic.h" /* -* bitmaps provide an array of bits, implemented using an an +* bitmaps provide an array of bits, implemented using an * array of unsigned longs. The number of valid bits in a * given bitmap does _not_ need to be an exact multiple of * BITS_PER_LONG.
Signature · 1 line
2.4.3
PATCH 7/7 maint: avoid useless "if (foo) free(foo)" pattern
In reply to Daniel P. BerrangeThe free() and g_free() functions both happily accept NULL on any platform QEMU builds on. As such putting a conditional 'if (foo)' check before calls to 'free(foo)' merely serves to bloat the lines of code.
--- backends/hostmem-file.c | 4 +--- bsd-user/elfload.c | 4 +--- disas/sparc.c | 3 +-- hw/bt/hci.c | 9 +++------ hw/core/loader.c | 3 +-- hw/core/qdev-properties.c | 4 +--- hw/display/exynos4210_fimd.c | 4 +--- hw/mips/mips_r4k.c | 4 +--- hw/net/fsl_etsec/rings.c | 4 +--- hw/net/rocker/rocker.c | 4 +--- hw/net/rocker/rocker_desc.c | 8 ++------ hw/nvram/fw_cfg.c | 4 +--- hw/pci-host/prep.c | 4 +--- hw/sd/sd.c | 3 +-- hw/usb/hcd-xhci.c | 4 +--- hw/xen/xen_pt_config_init.c | 4 +--- migration/savevm.c | 8 ++------ qemu-char.c | 4 +--- tests/bios-tables-test.c | 36 +++++++++++++----------------------- ui/spice-display.c | 14 ++++---------- 20 files changed, 39 insertions(+), 93 deletions(-)
backends/hostmem-file.c +1 -3
@@ -83,9 +83,7 @@ static void set_mem_path(Object *o, const char *str, Error **errp)error_setg (errp,"cannot change property value" );return ; } -if (fb->mem_path) { -g_free (fb->mem_path); - } +g_free (fb->mem_path); fb->mem_path =g_strdup (str); }
bsd-user/elfload.c +1 -3
@@ -1355,9 +1355,7 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, } }if (!bprm->p) { -if (elf_interpreter) { -free (elf_interpreter); - } +free (elf_interpreter);free (elf_phdata);close (bprm->fd);return -E2BIG ;
disas/sparc.c +1 -2
@@ -2622,8 +2622,7 @@ build_hash_table (const sparc_opcode **opcode_table,memset (hash_table,0 ,HASH_SIZE *sizeof (hash_table[0 ]));memset (hash_count,0 ,HASH_SIZE *sizeof (hash_count[0 ])); -if (hash_buf !=NULL ) -free (hash_buf); +free (hash_buf); hash_buf =malloc (sizeof (* hash_buf) * num_opcodes);for (i = num_opcodes -1 ; i >=0 ; --i) {
hw/bt/hci.c +3 -6
@@ -1151,8 +1151,7 @@ static void bt_hci_reset(struct bt_hci_s *hci) hci->event_mask[7 ] =0x00 ; hci->device.inquiry_scan =0 ; hci->device.page_scan =0 ; -if (hci->device.lmp_name) -g_free ((void *) hci->device.lmp_name); +g_free ((void *) hci->device.lmp_name); hci->device.lmp_name =NULL ; hci->device.class[0 ] =0x00 ; hci->device.class[1 ] =0x00 ;
@@ -1829,8 +1828,7 @@ static void bt_submit_hci(struct HCIInfo *info,case cmd_opcode_pack (OGF_HOST_CTL ,OCF_CHANGE_LOCAL_NAME ):LENGTH_CHECK (change_local_name); -if (hci->device.lmp_name) -g_free ((void *) hci->device.lmp_name); +g_free ((void *) hci->device.lmp_name); hci->device.lmp_name =g_strndup (PARAM (change_local_name, name),sizeof (PARAM (change_local_name, name)));bt_hci_event_complete_status (hci,HCI_SUCCESS );
@@ -2231,8 +2229,7 @@ static void bt_hci_done(struct HCIInfo *info)bt_device_done (&hci->device); -if (hci->device.lmp_name) -g_free ((void *) hci->device.lmp_name); +g_free ((void *) hci->device.lmp_name);/* Be gentle and send DISCONNECT to all connected peers and those * currently waiting for us to accept or reject a connection request.
hw/core/loader.c +1 -2
@@ -594,8 +594,7 @@ static int load_uboot_image(const char *filename, hwaddr *ep, hwaddr *loadaddr, ret = hdr->ih_size; out: -if (data) -g_free (data); +g_free (data);close (fd);return ret; }
hw/core/qdev-properties.c +1 -3
@@ -422,9 +422,7 @@ static void set_string(Object *obj, Visitor *v, void *opaque,error_propagate (errp, local_err);return ; } -if (*ptr) { -g_free (*ptr); - } +g_free (*ptr); *ptr = str; }
hw/display/exynos4210_fimd.c +1 -3
@@ -1354,9 +1354,7 @@ static void exynos4210_fimd_reset(DeviceState *d)fimd_update_get_alpha (s, w); } -if (s->ifb !=NULL ) { -g_free (s->ifb); - } +g_free (s->ifb); s->ifb =NULL ;exynos4210_fimd_invalidate (s);
hw/mips/mips_r4k.c +1 -3
@@ -252,9 +252,7 @@ void mips_r4k_init(MachineState *machine)fprintf (stderr,"qemu: Warning, could not load MIPS bios '%s'\n" , bios_name); } -if (filename) { -g_free (filename); - } +g_free (filename);if (kernel_filename) { loaderparams.ram_size = ram_size;
hw/net/fsl_etsec/rings.c +1 -3
@@ -464,9 +464,7 @@ static void rx_init_frame(eTSEC *etsec, const uint8_t *buf, size_t size) etsec->rx_fcb_size =0 ; } -if (etsec->rx_buffer !=NULL ) { -g_free (etsec->rx_buffer); - } +g_free (etsec->rx_buffer);/* Do not copy the frame for now */ etsec->rx_buffer = (uint8_t *)buf;
hw/net/rocker/rocker.c +1 -3
@@ -265,9 +265,7 @@ err_bad_io: err_no_mem: err_bad_attr:for (i =0 ; i <ROCKER_TX_FRAGS_MAX ; i++) { -if (iov[i].iov_base) { -g_free (iov[i].iov_base); - } +g_free (iov[i].iov_base); }return err;
hw/net/rocker/rocker_desc.c +2 -6
@@ -136,9 +136,7 @@ bool desc_ring_set_size(DescRing *ring, uint32_t size) }for (i =0 ; i < ring->size; i++) { -if (ring->info[i].buf) { -g_free (ring->info[i].buf); - } +g_free (ring->info[i].buf); } ring->size = size;
@@ -360,9 +358,7 @@ DescRing *desc_ring_alloc(Rocker *r, int index)void desc_ring_free (DescRing *ring) { -if (ring->info) { -g_free (ring->info); - } +g_free (ring->info);g_free (ring); }
hw/nvram/fw_cfg.c +1 -3
@@ -187,9 +187,7 @@ static void fw_cfg_bootsplash(FWCfgState *s)g_free (filename);return ; } -if (boot_splash_filedata !=NULL ) { -g_free (boot_splash_filedata); - } +g_free (boot_splash_filedata); boot_splash_filedata = (uint8_t *)file_data; boot_splash_filedata_size = file_size;
hw/pci-host/prep.c +1 -3
@@ -328,9 +328,7 @@ static void raven_realize(PCIDevice *d, Error **errp)if (bios_size <0 || bios_size >BIOS_SIZE ) {hw_error ("qemu: could not load bios image '%s'\n" , s->bios_name); } -if (filename) { -g_free (filename); - } +g_free (filename); } }
hw/sd/sd.c +1 -2
@@ -412,8 +412,7 @@ static void sd_reset(SDState *sd)sd_set_cardstatus (sd);sd_set_sdstatus (sd); -if (sd->wp_groups) -g_free (sd->wp_groups); +g_free (sd->wp_groups); sd->wp_switch = sd->blk ?blk_is_read_only (sd->blk) : false; sd->wpgrps_size = sect; sd->wp_groups =bitmap_new (sd->wpgrps_size);
hw/usb/hcd-xhci.c +1 -3
@@ -1453,9 +1453,7 @@ static int xhci_ep_nuke_one_xfer(XHCITransfer *t, TRBCCode report) t->running_retry =0 ; killed =1 ; } -if (t->trbs) { -g_free (t->trbs); - } +g_free (t->trbs); t->trbs =NULL ; t->trb_count = t->trb_alloced =0 ;
hw/xen/xen_pt_config_init.c +1 -3
@@ -1918,9 +1918,7 @@ void xen_pt_config_delete(XenPCIPassthroughState *s)if (s->msix) {xen_pt_msix_delete (s); } -if (s->msi) { -g_free (s->msi); - } +g_free (s->msi);/* free all register group entry */ QLIST_FOREACH_SAFE(reg_group, &s->reg_grps, entries, next_grp) {
migration/savevm.c +2 -6
@@ -551,9 +551,7 @@ void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque) QTAILQ_FOREACH_SAFE(se, &savevm_state.handlers, entry, new_se) {if (strcmp (se->idstr, id) ==0 && se->opaque == opaque) {QTAILQ_REMOVE (&savevm_state.handlers, se, entry); -if (se->compat) { -g_free (se->compat); - } +g_free (se->compat);g_free (se->ops);g_free (se); }
@@ -612,9 +610,7 @@ void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd, QTAILQ_FOREACH_SAFE(se, &savevm_state.handlers, entry, new_se) {if (se->vmsd == vmsd && se->opaque == opaque) {QTAILQ_REMOVE (&savevm_state.handlers, se, entry); -if (se->compat) { -g_free (se->compat); - } +g_free (se->compat);g_free (se); } }
qemu-char.c +1 -3
@@ -2710,9 +2710,7 @@ static int tcp_set_msgfds(CharDriverState *chr, int *fds, int num)TCPCharDriver *s = chr->opaque;/* clear old pending fd array */ -if (s->write_msgfds) { -g_free (s->write_msgfds); - } +g_free (s->write_msgfds);if (num) { s->write_msgfds =g_malloc (num *sizeof (int ));
tests/bios-tables-test.c +13 -23
@@ -161,31 +161,23 @@ static void free_test_data(test_data *data)AcpiSdtTable *temp;int i; -if (data->rsdt_tables_addr) { -g_free (data->rsdt_tables_addr); - } +g_free (data->rsdt_tables_addr);for (i =0 ; i < data->tables->len; ++i) { temp = &g_array_index (data->tables, AcpiSdtTable, i); -if (temp->aml) { -g_free (temp->aml); - } -if (temp->aml_file) { -if (!temp->tmp_files_retain && -g_strstr_len (temp->aml_file,-1 ,"aml-" )) { -unlink (temp->aml_file); - } -g_free (temp->aml_file); +g_free (temp->aml); +if (temp->aml_file && + !temp->tmp_files_retain && +g_strstr_len (temp->aml_file,-1 ,"aml-" )) { +unlink (temp->aml_file); } -if (temp->asl) { -g_free (temp->asl); - } -if (temp->asl_file) { -if (!temp->tmp_files_retain) { -unlink (temp->asl_file); - } -g_free (temp->asl_file); +g_free (temp->aml_file); +g_free (temp->asl); +if (temp->asl_file && + !temp->tmp_files_retain) { +unlink (temp->asl_file); } +g_free (temp->asl_file); }g_array_free (data->tables, false);
@@ -420,9 +412,7 @@ static void dump_aml_files(test_data *data, bool rebuild)close (fd); -if (aml_file) { -g_free (aml_file); - } +g_free (aml_file); } }
ui/spice-display.c +4 -10
@@ -737,9 +737,7 @@ static void display_mouse_set(DisplayChangeListener *dcl,qemu_mutex_lock (&ssd->lock); ssd->ptr_x = x; ssd->ptr_y = y; -if (ssd->ptr_move) { -g_free (ssd->ptr_move); - } +g_free (ssd->ptr_move); ssd->ptr_move =qemu_spice_create_cursor_update (ssd,NULL , on);qemu_mutex_unlock (&ssd->lock); }
@@ -752,13 +750,9 @@ static void display_mouse_define(DisplayChangeListener *dcl,qemu_mutex_lock (&ssd->lock); ssd->hot_x = c->hot_x; ssd->hot_y = c->hot_y; -if (ssd->ptr_move) { -g_free (ssd->ptr_move); - ssd->ptr_move =NULL ; - } -if (ssd->ptr_define) { -g_free (ssd->ptr_define); - } +g_free (ssd->ptr_move); + ssd->ptr_move =NULL ; +g_free (ssd->ptr_define); ssd->ptr_define =qemu_spice_create_cursor_update (ssd, c,0 );qemu_mutex_unlock (&ssd->lock); }
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH 1/7] maint: remove double semicolons in many files
In reply to Daniel P. BerrangeSignature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 2/7] maint: remove / fix many doubled words
In reply to Daniel P. Berrangenice :)
Re: [Qemu-devel] [PATCH 7/7] maint: avoid useless "if (foo) free(foo)" pattern
In reply to Daniel P. BerrangeHi
Quoted 429 lines · Daniel P. Berrange
The
free()andg_free()functions both happily accept NULL on any platform QEMU builds on. As such putting a conditional 'if (foo)' check before calls to 'free(foo)' merely serves to bloat the lines of code.Signed-off-by Daniel P. Berrange <[email protected]>--- backends/hostmem-file.c | 4 +--- bsd-user/elfload.c | 4 +--- disas/sparc.c | 3 +-- hw/bt/hci.c | 9 +++------ hw/core/loader.c | 3 +-- hw/core/qdev-properties.c | 4 +--- hw/display/exynos4210_fimd.c | 4 +--- hw/mips/mips_r4k.c | 4 +--- hw/net/fsl_etsec/rings.c | 4 +--- hw/net/rocker/rocker.c | 4 +--- hw/net/rocker/rocker_desc.c | 8 ++------ hw/nvram/fw_cfg.c | 4 +--- hw/pci-host/prep.c | 4 +--- hw/sd/sd.c | 3 +-- hw/usb/hcd-xhci.c | 4 +--- hw/xen/xen_pt_config_init.c | 4 +--- migration/savevm.c | 8 ++------ qemu-char.c | 4 +--- tests/bios-tables-test.c | 36 +++++++++++++----------------------- ui/spice-display.c | 14 ++++---------- 20 files changed, 39 insertions(+), 93 deletions(-)backends/hostmem-file.c +1
-3@@ -83,9 +83,7 @@ static void set_mem_path(Object *o, const char *str, Error **errp)error_setg (errp,"cannot change property value" );return ; } -if (fb->mem_path) { -g_free (fb->mem_path); - } +g_free (fb->mem_path); fb->mem_path =g_strdup (str); }bsd-user/elfload.c +1
-3@@ -1355,9 +1355,7 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, } }if (!bprm->p) { -if (elf_interpreter) { -free (elf_interpreter); - } +free (elf_interpreter);free (elf_phdata);close (bprm->fd);return -E2BIG ;disas/sparc.c +1
-2@@ -2622,8 +2622,7 @@ build_hash_table (const sparc_opcode **opcode_table,memset (hash_table,0 ,HASH_SIZE *sizeof (hash_table[0 ]));memset (hash_count,0 ,HASH_SIZE *sizeof (hash_count[0 ])); -if (hash_buf !=NULL ) -free (hash_buf); +free (hash_buf); hash_buf =malloc (sizeof (* hash_buf) * num_opcodes);for (i = num_opcodes -1 ; i >=0 ; --i) {hw/bt/hci.c +3
-6@@ -1151,8 +1151,7 @@ static void bt_hci_reset(struct bt_hci_s *hci) hci->event_mask[7 ] =0x00 ; hci->device.inquiry_scan =0 ; hci->device.page_scan =0 ; -if (hci->device.lmp_name) -g_free ((void *) hci->device.lmp_name); +g_free ((void *) hci->device.lmp_name); hci->device.lmp_name =NULL ; hci->device.class[0 ] =0x00 ; hci->device.class[1 ] =0x00 ;@@ -1829,8 +1828,7 @@ static void bt_submit_hci(struct HCIInfo *info,case cmd_opcode_pack (OGF_HOST_CTL ,OCF_CHANGE_LOCAL_NAME ):LENGTH_CHECK (change_local_name); -if (hci->device.lmp_name) -g_free ((void *) hci->device.lmp_name); +g_free ((void *) hci->device.lmp_name); hci->device.lmp_name =g_strndup (PARAM (change_local_name, name),sizeof (PARAM (change_local_name, name)));bt_hci_event_complete_status (hci,HCI_SUCCESS );@@ -2231,8 +2229,7 @@ static void bt_hci_done(struct HCIInfo *info)bt_device_done (&hci->device); -if (hci->device.lmp_name) -g_free ((void *) hci->device.lmp_name); +g_free ((void *) hci->device.lmp_name);/* Be gentle and send DISCONNECT to all connected peers and those * currently waiting for us to accept or reject a connection request. hw/core/loader.c +1
-2@@ -594,8 +594,7 @@ static int load_uboot_image(const char *filename, hwaddr *ep, hwaddr *loadaddr, ret = hdr->ih_size; out: -if (data) -g_free (data); +g_free (data);close (fd);return ret; }hw/core/qdev-properties.c +1
-3@@ -422,9 +422,7 @@ static void set_string(Object *obj, Visitor *v, void *opaque,error_propagate (errp, local_err);return ; } -if (*ptr) { -g_free (*ptr); - } +g_free (*ptr); *ptr = str; }hw/display/exynos4210_fimd.c +1
-3@@ -1354,9 +1354,7 @@ static void exynos4210_fimd_reset(DeviceState *d)fimd_update_get_alpha (s, w); } -if (s->ifb !=NULL ) { -g_free (s->ifb); - } +g_free (s->ifb); s->ifb =NULL ;exynos4210_fimd_invalidate (s);hw/mips/mips_r4k.c +1
-3@@ -252,9 +252,7 @@ void mips_r4k_init(MachineState *machine)fprintf (stderr,"qemu: Warning, could not load MIPS bios '%s'\n" , bios_name); } -if (filename) { -g_free (filename); - } +g_free (filename);if (kernel_filename) { loaderparams.ram_size = ram_size;hw/net/fsl_etsec/rings.c +1
-3@@ -464,9 +464,7 @@ static void rx_init_frame(eTSEC *etsec, const uint8_t *buf, size_t size) etsec->rx_fcb_size =0 ; } -if (etsec->rx_buffer !=NULL ) { -g_free (etsec->rx_buffer); - } +g_free (etsec->rx_buffer);/* Do not copy the frame for now */ etsec->rx_buffer = (uint8_t *)buf;hw/net/rocker/rocker.c +1
-3@@ -265,9 +265,7 @@ err_bad_io: err_no_mem: err_bad_attr:for (i =0 ; i <ROCKER_TX_FRAGS_MAX ; i++) { -if (iov[i].iov_base) { -g_free (iov[i].iov_base); - } +g_free (iov[i].iov_base); }return err;hw/net/rocker/rocker_desc.c +2
-6@@ -136,9 +136,7 @@ bool desc_ring_set_size(DescRing *ring, uint32_t size) }for (i =0 ; i < ring->size; i++) { -if (ring->info[i].buf) { -g_free (ring->info[i].buf); - } +g_free (ring->info[i].buf); } ring->size = size;@@ -360,9 +358,7 @@ DescRing *desc_ring_alloc(Rocker *r, int index)void desc_ring_free (DescRing *ring) { -if (ring->info) { -g_free (ring->info); - } +g_free (ring->info);g_free (ring); }hw/nvram/fw_cfg.c +1
-3@@ -187,9 +187,7 @@ static void fw_cfg_bootsplash(FWCfgState *s)g_free (filename);return ; } -if (boot_splash_filedata !=NULL ) { -g_free (boot_splash_filedata); - } +g_free (boot_splash_filedata); boot_splash_filedata = (uint8_t *)file_data; boot_splash_filedata_size = file_size;hw/pci-host/prep.c +1
-3@@ -328,9 +328,7 @@ static void raven_realize(PCIDevice *d, Error **errp)if (bios_size <0 || bios_size >BIOS_SIZE ) {hw_error ("qemu: could not load bios image '%s'\n" , s->bios_name); } -if (filename) { -g_free (filename); - } +g_free (filename); } }hw/sd/sd.c +1
-2@@ -412,8 +412,7 @@ static void sd_reset(SDState *sd)sd_set_cardstatus (sd);sd_set_sdstatus (sd); -if (sd->wp_groups) -g_free (sd->wp_groups); +g_free (sd->wp_groups); sd->wp_switch = sd->blk ?blk_is_read_only (sd->blk) : false; sd->wpgrps_size = sect; sd->wp_groups =bitmap_new (sd->wpgrps_size);hw/usb/hcd-xhci.c +1
-3@@ -1453,9 +1453,7 @@ static int xhci_ep_nuke_one_xfer(XHCITransfer *t, TRBCCode report) t->running_retry =0 ; killed =1 ; } -if (t->trbs) { -g_free (t->trbs); - } +g_free (t->trbs); t->trbs =NULL ; t->trb_count = t->trb_alloced =0 ;hw/xen/xen_pt_config_init.c +1
-3@@ -1918,9 +1918,7 @@ void xen_pt_config_delete(XenPCIPassthroughState *s)if (s->msix) {xen_pt_msix_delete (s); } -if (s->msi) { -g_free (s->msi); - } +g_free (s->msi);/* free all register group entry */ QLIST_FOREACH_SAFE(reg_group, &s->reg_grps, entries, next_grp) {migration/savevm.c +2
-6@@ -551,9 +551,7 @@ void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque) QTAILQ_FOREACH_SAFE(se, &savevm_state.handlers, entry, new_se) {if (strcmp (se->idstr, id) ==0 && se->opaque == opaque) {QTAILQ_REMOVE (&savevm_state.handlers, se, entry); -if (se->compat) { -g_free (se->compat); - } +g_free (se->compat);g_free (se->ops);g_free (se); }@@ -612,9 +610,7 @@ void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd, QTAILQ_FOREACH_SAFE(se, &savevm_state.handlers, entry, new_se) {if (se->vmsd == vmsd && se->opaque == opaque) {QTAILQ_REMOVE (&savevm_state.handlers, se, entry); -if (se->compat) { -g_free (se->compat); - } +g_free (se->compat);g_free (se); } }qemu-char.c +1
-3@@ -2710,9 +2710,7 @@ static int tcp_set_msgfds(CharDriverState *chr, int *fds, int num)TCPCharDriver *s = chr->opaque;/* clear old pending fd array */ -if (s->write_msgfds) { -g_free (s->write_msgfds); - } +g_free (s->write_msgfds);if (num) { s->write_msgfds =g_malloc (num *sizeof (int ));tests/bios-tables-test.c +13
-23@@ -161,31 +161,23 @@ static void free_test_data(test_data *data)AcpiSdtTable *temp;int i; -if (data->rsdt_tables_addr) { -g_free (data->rsdt_tables_addr); - } +g_free (data->rsdt_tables_addr);for (i =0 ; i < data->tables->len; ++i) { temp = &g_array_index (data->tables, AcpiSdtTable, i); -if (temp->aml) { -g_free (temp->aml); - } -if (temp->aml_file) { -if (!temp->tmp_files_retain && -g_strstr_len (temp->aml_file,-1 ,"aml-" )) { -unlink (temp->aml_file); - } -g_free (temp->aml_file); +g_free (temp->aml); +if (temp->aml_file && + !temp->tmp_files_retain && +g_strstr_len (temp->aml_file,-1 ,"aml-" )) { +unlink (temp->aml_file); } -if (temp->asl) { -g_free (temp->asl); - } -if (temp->asl_file) { -if (!temp->tmp_files_retain) { -unlink (temp->asl_file); - } -g_free (temp->asl_file); +g_free (temp->aml_file); +g_free (temp->asl); +if (temp->asl_file && + !temp->tmp_files_retain) { +unlink (temp->asl_file); } +g_free (temp->asl_file); }g_array_free (data->tables, false);@@ -420,9 +412,7 @@ static void dump_aml_files(test_data *data, bool rebuild)close (fd); -if (aml_file) { -g_free (aml_file); - } +g_free (aml_file); } }ui/spice-display.c +4
-11@@ -737,9 +737,7 @@ static void display_mouse_set(DisplayChangeListener *dcl,qemu_mutex_lock (&ssd->lock); ssd->ptr_x = x; ssd->ptr_y = y; -if (ssd->ptr_move) { -g_free (ssd->ptr_move); - } +g_free (ssd->ptr_move); ssd->ptr_move =qemu_spice_create_cursor_update (ssd,NULL , on);qemu_mutex_unlock (&ssd->lock); }@@ -752,13 +750,9 @@ static void display_mouse_define(DisplayChangeListener *dcl,qemu_mutex_lock (&ssd->lock); ssd->hot_x = c->hot_x; ssd->hot_y = c->hot_y; -if (ssd->ptr_move) { -g_free (ssd->ptr_move); - ssd->ptr_move =NULL ; - } -if (ssd->ptr_define) { -g_free (ssd->ptr_define); - } +g_free (ssd->ptr_move); + ssd->ptr_move =NULL ; +g_free (ssd->ptr_define); ssd->ptr_define =qemu_spice_create_cursor_update (ssd, c,0 );qemu_mutex_unlock (&ssd->lock); } --
Quoted 3 lines
2.4.3
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 7/7] maint: avoid useless "if (foo) free(foo)" pattern
In reply to Daniel P. BerrangeQuoted 2 lines · Daniel P. Berrange
The
free()andg_free()functions both happily accept NULL on any platform QEMU builds on.
Do systems where free(NULL) doesn't work even exist? Even C89 guarantees it does nothing.
Quoted 5 lines
As such putting a
conditional 'if (foo)' check before calls to 'free(foo)' merely serves to bloat the lines of code.Signed-off-by Daniel P. Berrange <[email protected]>
My Coccinelle semantic patch finds a few more, because it also fixes up the equally pointless conditional
if (foo) {
free(foo);
foo = NULL;
}@@
expression E;
@@
- if (E != NULL) {
- g_free(E);
- }
+ g_free(E);
@@
expression E;
@@
- if (E != NULL) {
- g_free(E);
- E = NULL;
- }
+ g_free(E);
+ E = NULL;
@@
expression E;
type T;
@@
- if (E != NULL) {
- g_free((T)E);
- }
+ g_free((T)E);
@@
expression E;
type T;
@@
- if (E != NULL) {
- g_free((T)E);
- E = NULL;
- }
+ g_free((T)E);
+ E = NULL;
Result (feel free to squash it into your patch):
hw/char/exynos4210_uart.c +2 -4
@@ -234,10 +234,8 @@ static int fifo_empty_elements_number(Exynos4210UartFIFO *q)static void fifo_reset (Exynos4210UartFIFO *q) { -if (q->data !=NULL ) { -g_free (q->data); - q->data =NULL ; - } +g_free (q->data); + q->data =NULL ; q->data = (uint8_t *)g_malloc0 (q->size);
hw/net/rtl8139.c +2 -4
@@ -3438,10 +3438,8 @@ static void pci_rtl8139_uninit(PCIDevice *dev) {RTL8139State *s =RTL8139 (dev); -if (s->cplus_txbuffer) { -g_free (s->cplus_txbuffer); - s->cplus_txbuffer =NULL ; - } +g_free (s->cplus_txbuffer); + s->cplus_txbuffer =NULL ;timer_del (s->timer);timer_free (s->timer);qemu_del_nic (s->nic);
hw/ppc/spapr_pci.c +4 -8
@@ -1460,10 +1460,8 @@ static void spapr_pci_pre_save(void *opaque)gpointer key, value;int i; -if (sphb->msi_devs) { -g_free (sphb->msi_devs); - sphb->msi_devs =NULL ; - } +g_free (sphb->msi_devs); + sphb->msi_devs =NULL ; sphb->msi_devs_num =g_hash_table_size (sphb->msi);if (!sphb->msi_devs_num) {return ;
@@ -1490,10 +1488,8 @@ static int spapr_pci_post_load(void *opaque, int version_id) sizeof(sphb->msi_devs[i].value));g_hash_table_insert (sphb->msi, key, value); } -if (sphb->msi_devs) { -g_free (sphb->msi_devs); - sphb->msi_devs =NULL ; - } +g_free (sphb->msi_devs); + sphb->msi_devs =NULL ; sphb->msi_devs_num =0 ;return 0 ;
hw/sd/sdhci.c +2 -4
@@ -1169,10 +1169,8 @@ static void sdhci_uninitfn(SDHCIState *s)qemu_free_irq (s->eject_cb);qemu_free_irq (s->ro_cb); -if (s->fifo_buffer) { -g_free (s->fifo_buffer); - s->fifo_buffer =NULL ; - } +g_free (s->fifo_buffer); + s->fifo_buffer =NULL ; }const VMStateDescription sdhci_vmstate = {
hw/usb/hcd-ehci-pci.c +2 -4
@@ -95,10 +95,8 @@ static void usb_ehci_pci_exit(PCIDevice *dev)usb_ehci_unrealize (s,DEVICE (dev),NULL ); -if (s->irq) { -g_free (s->irq); - s->irq =NULL ; - } +g_free (s->irq); + s->irq =NULL ; }static void usb_ehci_pci_reset (DeviceState *dev)
tests/test-hbitmap.c +2 -4
@@ -139,10 +139,8 @@ static void hbitmap_test_teardown(TestHBitmapData *data,hbitmap_free (data->hb); data->hb =NULL ; } -if (data->bits) { -g_free (data->bits); - data->bits =NULL ; - } +g_free (data->bits); + data->bits =NULL ; }/* Set a range in the HBitmap and in the shadow "simple" bitmap.
translate-all.c +2 -4
@@ -731,10 +731,8 @@ void tb_free(TranslationBlock *tb)static inline void invalidate_page_bitmap (PageDesc *p) { -if (p->code_bitmap) { -g_free (p->code_bitmap); - p->code_bitmap =NULL ; - } +g_free (p->code_bitmap); + p->code_bitmap =NULL ; p->code_write_count =0 ; }
vl.c +2 -4
@@ -534,10 +534,8 @@ const char *qemu_get_vm_name(void)static void res_free (void ) { -if (boot_splash_filedata !=NULL ) { -g_free (boot_splash_filedata); - boot_splash_filedata =NULL ; - } +g_free (boot_splash_filedata); + boot_splash_filedata =NULL ; }static int default_driver_check (void *opaque,QemuOpts *opts,Error **errp)
xen-mapcache.c +2 -4
@@ -169,10 +169,8 @@ static void xen_remap_bucket(MapCacheEntry *entry,exit (-1 ); } } -if (entry->valid_mapping !=NULL ) { -g_free (entry->valid_mapping); - entry->valid_mapping =NULL ; - } +g_free (entry->valid_mapping); + entry->valid_mapping =NULL ;for (i =0 ; i < nb_pfn; i++) { pfns[i] = (address_index << (MCACHE_BUCKET_SHIFT -XC_PAGE_SHIFT )) + i;
Quoted 10 lines · Daniel P. Berrange
This is a series of misc trivial code cleanups that I originally used to illustrate the use of GNULIB's syntax-check facility:
http://lists.nongnu.org/archive/html/qemu-devel/2015-07/msg06268.html
Since it appears the license of the GNULIB syntax-check is problematic, this series has separated the fixes out from the GNULIB additions, to allow for possibility of merging them as-is.
Series
Eric Blake
Reviewed-byRe: [Qemu-devel] [PATCH 7/7] maint: avoid useless "if (foo) free(foo)" pattern
In reply to Markus ArmbrusterQuoted 7 lines · Markus Armbruster
Quoted 2 lines · Daniel P. Berrange
The
free()andg_free()functions both happily accept NULL on any platform QEMU builds on.Do systems where free(NULL) doesn't work even exist? Even C89 guarantees it does nothing.
Solaris 4 was the last (pre-C89) system I am aware of that didn't like free(NULL). Ancient history nowadays.
Quoted 8 lines
My Coccinelle semantic patch finds a few more, because it also fixes up the equally pointless conditional
if (foo) { free(foo); foo = NULL; }
The assignment to foo is not pointless, but removing the conditional is indeed nice. gnulib's perl script is a lot weaker than coccinelle, obviously :)
Review
Quoted 10 lines
@@
expression E;
@@(quoted diff) +2
-4- if (E != NULL) { - g_free(E); - E = NULL; - } + g_free(E); + E = NULL;
This only checks for g_free() before assignment to NULL; are there any uses of raw free() that do the same?
Quoted 2 lines
Result (feel free to squash it into your patch):
Whether squashed in or separate, these additional changes and the original patch are:
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 7/7] maint: avoid useless "if (foo) free(foo)" pattern
Quoted 16 lines · Eric Blake
Quoted 7 lines · Markus Armbruster
Quoted 2 lines · Daniel P. Berrange
The
free()andg_free()functions both happily accept NULL on any platform QEMU builds on.Do systems where free(NULL) doesn't work even exist? Even C89 guarantees it does nothing.
Solaris 4 was the last (pre-C89) system I am aware of that didn't like free(NULL). Ancient history nowadays.
Quoted 4 lines
My Coccinelle semantic patch finds a few more, because it also fixes up the equally pointless conditional
Quoted 8 lines
Quoted 4 lines
if (foo) { free(foo); foo = NULL; }The assignment to foo is not pointless, but removing the conditional is indeed nice. gnulib's perl script is a lot weaker than coccinelle, obviously :)
I only called the conditional pointless :)
Quoted 13 lines
Review
Quoted 10 lines
@@
expression E;
@@(quoted diff) +2
-4- if (E != NULL) { - g_free(E); - E = NULL; - } + g_free(E); + E = NULL;This only checks for
g_free()before assignment to NULL; are there any uses of rawfree()that do the same?
Running Coccinelle again... wait... wait... yes, but only in libdecnumber/, which we stole from GCC. Not sure we want to mess with it. Patch appended anyway.
Quoted 6 lines
Quoted 2 lines
Result (feel free to squash it into your patch):
Whether squashed in or separate, these additional changes and the original patch are:
Reviewed-by Eric Blake <[email protected]>
libdecnumber/decNumber.c +40 -40
@@ -779,7 +779,7 @@ decNumber * decNumberFromString(decNumber *dn, const char chars[],/* decNumberShow(dn); */ }while (0 );/* [for break] */ -if (allocres!=NULL )free (allocres);/* drop any storage used */ +free (allocres);/* drop any storage used */ if (status!=0 )decStatus (dn, status, set);return dn; }/* decNumberFromString */
@@ -1038,8 +1038,8 @@ decNumber * decNumberCompareTotalMag(decNumber *res, const decNumber *lhs,decCompareOp (res, lhs, rhs, set,COMPTOTAL , &status); }while (0 );/* end protected */ -if (allocbufa!=NULL )free (allocbufa);/* drop any storage used */ -if (allocbufb!=NULL )free (allocbufb);/* .. */ +free (allocbufa);/* drop any storage used */ +free (allocbufb);/* .. */ if (status!=0 )decStatus (res, status, set);return res; }/* decNumberCompareTotalMag */
@@ -1142,7 +1142,7 @@ decNumber * decNumberExp(decNumber *res, const decNumber *rhs, }while (0 );/* end protected */ #if DECSUBSET -if (allocrhs !=NULL )free (allocrhs);/* drop any storage used */ +free (allocrhs);/* drop any storage used */ #endif /* apply significant status */ if (status!=0 )decStatus (res, status, set);
@@ -1237,7 +1237,7 @@ decNumber * decNumberFMA(decNumber *res, const decNumber *lhs,decAddOp (res, acc, fhs, set,0 , &status); }while (0 );/* end protected */ -if (allocbufa!=NULL )free (allocbufa);/* drop any storage used */ +free (allocbufa);/* drop any storage used */ if (status!=0 )decStatus (res, status, set);#if DECCHECK decCheckInexact (res, set);
@@ -1364,7 +1364,7 @@ decNumber * decNumberLn(decNumber *res, const decNumber *rhs, }while (0 );/* end protected */ #if DECSUBSET -if (allocrhs !=NULL )free (allocrhs);/* drop any storage used */ +free (allocrhs);/* drop any storage used */ #endif /* apply significant status */ if (status!=0 )decStatus (res, status, set);
@@ -1577,10 +1577,10 @@ decNumber * decNumberLog10(decNumber *res, const decNumber *rhs,decDivideOp (res, a, b, &aset,DIVIDE , &status);/* into result */ }while (0 );/* [for break] */ -if (allocbufa!=NULL )free (allocbufa);/* drop any storage used */ -if (allocbufb!=NULL )free (allocbufb);/* .. */ +free (allocbufa);/* drop any storage used */ +free (allocbufb);/* .. */ #if DECSUBSET -if (allocrhs !=NULL )free (allocrhs);/* .. */ +free (allocrhs);/* .. */ #endif /* apply significant status */ if (status!=0 )decStatus (res, status, set);
@@ -2320,11 +2320,11 @@ decNumber * decNumberPower(decNumber *res, const decNumber *lhs,#endif }while (0 );/* end protected */ -if (allocdac!=NULL )free (allocdac);/* drop any storage used */ -if (allocinv!=NULL )free (allocinv);/* .. */ +free (allocdac);/* drop any storage used */ +free (allocinv);/* .. */ #if DECSUBSET -if (alloclhs!=NULL )free (alloclhs);/* .. */ -if (allocrhs!=NULL )free (allocrhs);/* .. */ +free (alloclhs);/* .. */ +free (allocrhs);/* .. */ #endif if (status!=0 )decStatus (res, status, set);#if DECCHECK
@@ -2415,7 +2415,7 @@ decNumber * decNumberReduce(decNumber *res, const decNumber *rhs, }while (0 );/* end protected */ #if DECSUBSET -if (allocrhs !=NULL )free (allocrhs);/* .. */ +free (allocrhs);/* .. */ #endif if (status!=0 )decStatus (res, status, set);/* then report status */ return res;
@@ -3169,11 +3169,11 @@ decNumber * decNumberSquareRoot(decNumber *res, const decNumber *rhs,decNumberCopy (res, a);/* a is now the result */ }while (0 );/* end protected */ -if (allocbuff!=NULL )free (allocbuff);/* drop any storage used */ -if (allocbufa!=NULL )free (allocbufa);/* .. */ -if (allocbufb!=NULL )free (allocbufb);/* .. */ +free (allocbuff);/* drop any storage used */ +free (allocbufa);/* .. */ +free (allocbufb);/* .. */ #if DECSUBSET -if (allocrhs !=NULL )free (allocrhs);/* .. */ +free (allocrhs);/* .. */ #endif if (status!=0 )decStatus (res, status, set);/* then report status */ #if DECCHECK
@@ -4187,10 +4187,10 @@ static decNumber * decAddOp(decNumber *res, const decNumber *lhs, } }while (0 );/* end protected */ -if (allocacc!=NULL )free (allocacc);/* drop any storage used */ +free (allocacc);/* drop any storage used */ #if DECSUBSET -if (allocrhs!=NULL )free (allocrhs);/* .. */ -if (alloclhs!=NULL )free (alloclhs);/* .. */ +free (allocrhs);/* .. */ +free (alloclhs);/* .. */ #endif return res; }/* decAddOp */
@@ -4839,11 +4839,11 @@ static decNumber * decDivideOp(decNumber *res,#endif }while (0 );/* end protected */ -if (varalloc!=NULL )free (varalloc);/* drop any storage used */ -if (allocacc!=NULL )free (allocacc);/* .. */ +free (varalloc);/* drop any storage used */ +free (allocacc);/* .. */ #if DECSUBSET -if (allocrhs!=NULL )free (allocrhs);/* .. */ -if (alloclhs!=NULL )free (alloclhs);/* .. */ +free (allocrhs);/* .. */ +free (alloclhs);/* .. */ #endif return res; }/* decDivideOp */
@@ -5184,14 +5184,14 @@ static decNumber * decMultiplyOp(decNumber *res, const decNumber *lhs,decFinish (res, set, &residue, status);/* final cleanup */ }while (0 );/* end protected */ -if (allocacc!=NULL )free (allocacc);/* drop any storage used */ +free (allocacc);/* drop any storage used */ #if DECSUBSET -if (allocrhs!=NULL )free (allocrhs);/* .. */ -if (alloclhs!=NULL )free (alloclhs);/* .. */ +free (allocrhs);/* .. */ +free (alloclhs);/* .. */ #endif #if FASTMUL -if (allocrhi!=NULL )free (allocrhi);/* .. */ -if (alloclhi!=NULL )free (alloclhi);/* .. */ +free (allocrhi);/* .. */ +free (alloclhi);/* .. */ #endif return res; }/* decMultiplyOp */
@@ -5540,9 +5540,9 @@ static decNumber *decExpOp(decNumber *res, const decNumber *rhs,decFinish (res, set, &residue, status);/* cleanup/set flags */ }while (0 );/* end protected */ -if (allocrhs !=NULL )free (allocrhs);/* drop any storage used */ -if (allocbufa!=NULL )free (allocbufa);/* .. */ -if (allocbuft!=NULL )free (allocbuft);/* .. */ +free (allocrhs);/* drop any storage used */ +free (allocbufa);/* .. */ +free (allocbuft);/* .. */ /* [status is handled by caller] */ return res; }/* decExpOp */
@@ -5852,8 +5852,8 @@ static decNumber *decLnOp(decNumber *res, const decNumber *rhs,decFinish (res, set, &residue, status);/* cleanup/set flags */ }while (0 );/* end protected */ -if (allocbufa!=NULL )free (allocbufa);/* drop any storage used */ -if (allocbufb!=NULL )free (allocbufb);/* .. */ +free (allocbufa);/* drop any storage used */ +free (allocbufb);/* .. */ /* [status is handled by caller] */ return res; }/* decLnOp */
@@ -6017,8 +6017,8 @@ static decNumber * decQuantizeOp(decNumber *res, const decNumber *lhs, }while (0 );/* end protected */ #if DECSUBSET -if (allocrhs!=NULL )free (allocrhs);/* drop any storage used */ -if (alloclhs!=NULL )free (alloclhs);/* .. */ +free (allocrhs);/* drop any storage used */ +free (alloclhs);/* .. */ #endif return res; }/* decQuantizeOp */
@@ -6200,8 +6200,8 @@ static decNumber *decCompareOp(decNumber *res, const decNumber *lhs, } }#if DECSUBSET -if (allocrhs!=NULL )free (allocrhs);/* free any storage used */ -if (alloclhs!=NULL )free (alloclhs);/* .. */ +free (allocrhs);/* free any storage used */ +free (alloclhs);/* .. */ #endif return res; }/* decCompareOp */
@@ -6335,7 +6335,7 @@ static Int decUnitCompare(const Unit *a, Int alength, result=(*u==0 ?0 :+1 ); }/* clean up and return the result */ -if (allocacc!=NULL )free (allocacc);/* drop any storage used */ +free (allocacc);/* drop any storage used */ return result; }/* decUnitCompare */
Michael Tokarev
AppliedQuoted 10 lines · Daniel P. Berrange
This is a series of misc trivial code cleanups that I originally used to illustrate the use of GNULIB's syntax-check facility:
http://lists.nongnu.org/archive/html/qemu-devel/2015-07/msg06268.html
Since it appears the license of the GNULIB syntax-check is problematic, this series has separated the fixes out from the GNULIB additions, to allow for possibility of merging them as-is.
Applied all 7 to -trivial.
With additional patch by Markus being 8/7 ;)
Nice work, thank you!
/mjt