mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-06 09:13:55 -06:00
maint: avoid useless "if (foo) free(foo)" pattern
The 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. Signed-off-by: Daniel P. Berrange <berrange@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
This commit is contained in:
parent
4595a48a10
commit
ef1e1e0782
20 changed files with 39 additions and 93 deletions
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -2081,9 +2081,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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue