[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-trivial] [PULL 11/26] maint: avoid useless "if (foo) free(foo)" pa
From: |
Michael Tokarev |
Subject: |
[Qemu-trivial] [PULL 11/26] maint: avoid useless "if (foo) free(foo)" pattern |
Date: |
Fri, 11 Sep 2015 14:03:35 +0300 |
From: Markus Armbruster <address@hidden>
My Coccinelle semantic patch finds a few more, because it also fixes up
the equally pointless conditional
if (foo) {
free(foo);
foo = NULL;
}
Result (feel free to squash it into your patch):
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Michael Tokarev <address@hidden>
---
hw/char/exynos4210_uart.c | 6 ++----
hw/net/rtl8139.c | 6 ++----
hw/ppc/spapr_pci.c | 12 ++++--------
hw/sd/sdhci.c | 6 ++----
hw/usb/hcd-ehci-pci.c | 6 ++----
tests/test-hbitmap.c | 6 ++----
translate-all.c | 6 ++----
vl.c | 6 ++----
xen-mapcache.c | 6 ++----
9 files changed, 20 insertions(+), 40 deletions(-)
diff --git a/hw/char/exynos4210_uart.c b/hw/char/exynos4210_uart.c
index 7614e58..215f962 100644
--- a/hw/char/exynos4210_uart.c
+++ b/hw/char/exynos4210_uart.c
@@ -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);
diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c
index 2040618..b0d6c40 100644
--- a/hw/net/rtl8139.c
+++ b/hw/net/rtl8139.c
@@ -3391,10 +3391,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);
diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
index a8f79d8..a2feb4c 100644
--- a/hw/ppc/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -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;
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index e63367b..65304cf 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -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 = {
diff --git a/hw/usb/hcd-ehci-pci.c b/hw/usb/hcd-ehci-pci.c
index 7afa5f9..16fb845 100644
--- a/hw/usb/hcd-ehci-pci.c
+++ b/hw/usb/hcd-ehci-pci.c
@@ -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)
diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c
index 161eeb4..abcea0c 100644
--- a/tests/test-hbitmap.c
+++ b/tests/test-hbitmap.c
@@ -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.
diff --git a/translate-all.c b/translate-all.c
index 2a40530..8eb4512 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -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;
}
diff --git a/vl.c b/vl.c
index 76e0bb2..1c8b28d 100644
--- a/vl.c
+++ b/vl.c
@@ -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)
diff --git a/xen-mapcache.c b/xen-mapcache.c
index 8cefd0c..97fece2 100644
--- a/xen-mapcache.c
+++ b/xen-mapcache.c
@@ -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;
--
2.1.4
- [Qemu-trivial] [PULL 17/26] Target-ppc: Remove unnecessary variable, (continued)
- [Qemu-trivial] [PULL 17/26] Target-ppc: Remove unnecessary variable, Michael Tokarev, 2015/09/11
- [Qemu-trivial] [PULL 10/26] maint: avoid useless "if (foo) free(foo)" pattern, Michael Tokarev, 2015/09/11
- [Qemu-trivial] [PULL 05/26] maint: remove / fix many doubled words, Michael Tokarev, 2015/09/11
- [Qemu-trivial] [PULL 03/26] i6300esb: fix timer overflow, Michael Tokarev, 2015/09/11
- [Qemu-trivial] [PULL 24/26] hw/gpio/zaurus: Remove meaningless blank Property, Michael Tokarev, 2015/09/11
- [Qemu-trivial] [PULL 04/26] maint: remove double semicolons in many files, Michael Tokarev, 2015/09/11
- [Qemu-trivial] [PULL 20/26] qapi-schema: remove legacy<> from doc, Michael Tokarev, 2015/09/11
- [Qemu-trivial] [PULL 26/26] virtio-vga: enable for i386, Michael Tokarev, 2015/09/11
- [Qemu-trivial] [PULL 21/26] typofixes - v4, Michael Tokarev, 2015/09/11
- [Qemu-trivial] [PULL 18/26] help: dd missing newline, Michael Tokarev, 2015/09/11
- [Qemu-trivial] [PULL 11/26] maint: avoid useless "if (foo) free(foo)" pattern,
Michael Tokarev <=
- [Qemu-trivial] [PULL 12/26] trivial: remove trailing newline from error_report, Michael Tokarev, 2015/09/11
- [Qemu-trivial] [PULL 07/26] maint: remove unused include for dirent.h, Michael Tokarev, 2015/09/11
- [Qemu-trivial] [PULL 23/26] hw/virtio/virtio-pci: Remove meaningless blank Property, Michael Tokarev, 2015/09/11
- [Qemu-trivial] [PULL 16/26] baum: Fix build with debugging enabled, Michael Tokarev, 2015/09/11
- [Qemu-trivial] [PULL 02/26] Trivial: fix commandline help message, Michael Tokarev, 2015/09/11
- [Qemu-trivial] [PULL 22/26] hw/s390x/s390-virtio-bus: Remove meaningless blank Property, Michael Tokarev, 2015/09/11
- [Qemu-trivial] [PULL 19/26] disas/microblaze: Remove unused code, Michael Tokarev, 2015/09/11
- [Qemu-trivial] [PULL 08/26] maint: remove unused include for signal.h, Michael Tokarev, 2015/09/11
- [Qemu-trivial] [PULL 14/26] opts: produce valid command line in qemu_opts_print, Michael Tokarev, 2015/09/11
- Re: [Qemu-trivial] [Qemu-devel] [PULL 00/26] Trivial patches for 2015-09-11, Peter Maydell, 2015/09/11