[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen master] tools: remove unnecessary null pointer checks before frees
commit c07134ccca7d61534aa00294126dadd9fd6cb2a2 Author: Matthew Daley <mattjd@xxxxxxxxx> AuthorDate: Tue Oct 15 18:18:02 2013 +1300 Commit: Ian Campbell <ian.campbell@xxxxxxxxxx> CommitDate: Thu Oct 31 20:04:25 2013 +0000 tools: remove unnecessary null pointer checks before frees Patch generated by the following semantic patch (http://coccinelle.lip6.fr/): @@ expression *P; @@ - if(P) free(P); + free(P); ...and then by filtering through the following command: filterdiff -p1 -x 'stubdom/*' -x 'tools/firmware/*' -x 'tools/qemu-*' -x 'tools/blktap*' Signed-off-by: Matthew Daley <mattjd@xxxxxxxxx> Acked-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxx> Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx> --- extras/mini-os/blkfront.c | 14 ++++++------ extras/mini-os/console/xenbus.c | 8 +++--- extras/mini-os/fbfront.c | 38 +++++++++++++++++----------------- extras/mini-os/kernel.c | 4 +- extras/mini-os/lib/sys.c | 3 +- extras/mini-os/netfront.c | 18 ++++++++-------- extras/mini-os/pcifront.c | 14 ++++++------ tools/flask/utils/loadpolicy.c | 3 +- tools/libxc/xc_compression.c | 15 ++++--------- tools/libxc/xc_core_x86.c | 6 +--- tools/libxc/xc_domain_save.c | 6 +--- tools/libxc/xc_gnttab.c | 3 +- tools/libxc/xc_offline_page.c | 9 ++----- tools/libxl/libxl_event.c | 3 +- tools/libxl/libxl_qmp.c | 6 +--- tools/libxl/libxl_utils.c | 2 +- tools/memshr/bidir-hash.c | 4 +- tools/misc/gtraceview.c | 3 +- tools/tests/xen-access/xen-access.c | 6 +--- tools/xenbackendd/xenbackendd.c | 6 +--- 20 files changed, 74 insertions(+), 97 deletions(-) diff --git a/extras/mini-os/blkfront.c b/extras/mini-os/blkfront.c index aead6bd..62a32c5 100644 --- a/extras/mini-os/blkfront.c +++ b/extras/mini-os/blkfront.c @@ -160,7 +160,7 @@ again: err = xenbus_transaction_end(xbt, 0, &retry); - if (err) free(err); + free(err); if (retry) { goto again; printk("completing transaction\n"); @@ -271,7 +271,7 @@ void shutdown_blkfront(struct blkfront_dev *dev) state = xenbus_read_integer(path); while (err == NULL && state < XenbusStateClosing) err = xenbus_wait_for_state_change(path, &state, &dev->events); - if (err) free(err); + free(err); if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateClosed)) != NULL) { printk("shutdown_blkfront: error changing state to %d: %s\n", @@ -281,7 +281,7 @@ void shutdown_blkfront(struct blkfront_dev *dev) state = xenbus_read_integer(path); while (state < XenbusStateClosed) { err = xenbus_wait_for_state_change(path, &state, &dev->events); - if (err) free(err); + free(err); } if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateInitialising)) != NULL) { @@ -294,16 +294,16 @@ void shutdown_blkfront(struct blkfront_dev *dev) err = xenbus_wait_for_state_change(path, &state, &dev->events); close: - if (err) free(err); + free(err); err2 = xenbus_unwatch_path_token(XBT_NIL, path, path); - if (err2) free(err2); + free(err2); snprintf(nodename, sizeof(nodename), "%s/ring-ref", dev->nodename); err2 = xenbus_rm(XBT_NIL, nodename); - if (err2) free(err2); + free(err2); snprintf(nodename, sizeof(nodename), "%s/event-channel", dev->nodename); err2 = xenbus_rm(XBT_NIL, nodename); - if (err2) free(err2); + free(err2); if (!err) free_blkfront(dev); diff --git a/extras/mini-os/console/xenbus.c b/extras/mini-os/console/xenbus.c index b317114..1c9a590 100644 --- a/extras/mini-os/console/xenbus.c +++ b/extras/mini-os/console/xenbus.c @@ -32,7 +32,7 @@ void free_consfront(struct consfront_dev *dev) state = xenbus_read_integer(path); while (err == NULL && state < XenbusStateClosing) err = xenbus_wait_for_state_change(path, &state, &dev->events); - if (err) free(err); + free(err); if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateClosed)) != NULL) { printk("free_consfront: error changing state to %d: %s\n", @@ -41,9 +41,9 @@ void free_consfront(struct consfront_dev *dev) } close: - if (err) free(err); + free(err); err = xenbus_unwatch_path_token(XBT_NIL, path, path); - if (err) free(err); + free(err); mask_evtchn(dev->evtchn); unbind_evtchn(dev->evtchn); @@ -134,7 +134,7 @@ again: err = xenbus_transaction_end(xbt, 0, &retry); - if (err) free(err); + free(err); if (retry) { goto again; printk("completing transaction\n"); diff --git a/extras/mini-os/fbfront.c b/extras/mini-os/fbfront.c index a276193..1e01513 100644 --- a/extras/mini-os/fbfront.c +++ b/extras/mini-os/fbfront.c @@ -131,7 +131,7 @@ again: } err = xenbus_transaction_end(xbt, 0, &retry); - if (err) free(err); + free(err); if (retry) { goto again; printk("completing transaction\n"); @@ -171,7 +171,7 @@ done: err = xenbus_wait_for_state_change(path, &state, &dev->events); if (state != XenbusStateConnected) { printk("backend not available, state=%d\n", state); - if (err) free(err); + free(err); err = xenbus_unwatch_path_token(XBT_NIL, path, path); goto error; } @@ -256,7 +256,7 @@ void shutdown_kbdfront(struct kbdfront_dev *dev) state = xenbus_read_integer(path); while (err == NULL && state < XenbusStateClosing) err = xenbus_wait_for_state_change(path, &state, &dev->events); - if (err) free(err); + free(err); if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateClosed)) != NULL) { printk("shutdown_kbdfront: error changing state to %d: %s\n", @@ -266,7 +266,7 @@ void shutdown_kbdfront(struct kbdfront_dev *dev) state = xenbus_read_integer(path); while (state < XenbusStateClosed) { err = xenbus_wait_for_state_change(path, &state, &dev->events); - if (err) free(err); + free(err); } if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateInitialising)) != NULL) { @@ -279,19 +279,19 @@ void shutdown_kbdfront(struct kbdfront_dev *dev) err = xenbus_wait_for_state_change(path, &state, &dev->events); close_kbdfront: - if (err) free(err); + free(err); err2 = xenbus_unwatch_path_token(XBT_NIL, path, path); - if (err2) free(err2); + free(err2); snprintf(nodename, sizeof(nodename), "%s/page-ref", dev->nodename); err2 = xenbus_rm(XBT_NIL, nodename); - if (err2) free(err2); + free(err2); snprintf(nodename, sizeof(nodename), "%s/event-channel", dev->nodename); err2 = xenbus_rm(XBT_NIL, nodename); - if (err2) free(err2); + free(err2); snprintf(nodename, sizeof(nodename), "%s/request-abs-pointer", dev->nodename); err2 = xenbus_rm(XBT_NIL, nodename); - if (err2) free(err2); + free(err2); if (!err) free_kbdfront(dev); @@ -498,7 +498,7 @@ again: } err = xenbus_transaction_end(xbt, 0, &retry); - if (err) free(err); + free(err); if (retry) { goto again; printk("completing transaction\n"); @@ -538,7 +538,7 @@ done: err = xenbus_wait_for_state_change(path, &state, &dev->events); if (state != XenbusStateConnected) { printk("backend not available, state=%d\n", state); - if (err) free(err); + free(err); err = xenbus_unwatch_path_token(XBT_NIL, path, path); goto error; } @@ -654,7 +654,7 @@ void shutdown_fbfront(struct fbfront_dev *dev) state = xenbus_read_integer(path); while (err == NULL && state < XenbusStateClosing) err = xenbus_wait_for_state_change(path, &state, &dev->events); - if (err) free(err); + free(err); if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateClosed)) != NULL) { printk("shutdown_fbfront: error changing state to %d: %s\n", @@ -664,7 +664,7 @@ void shutdown_fbfront(struct fbfront_dev *dev) state = xenbus_read_integer(path); if (state < XenbusStateClosed) { err = xenbus_wait_for_state_change(path, &state, &dev->events); - if (err) free(err); + free(err); } if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateInitialising)) != NULL) { @@ -677,22 +677,22 @@ void shutdown_fbfront(struct fbfront_dev *dev) err = xenbus_wait_for_state_change(path, &state, &dev->events); close_fbfront: - if (err) free(err); + free(err); err2 = xenbus_unwatch_path_token(XBT_NIL, path, path); - if (err2) free(err2); + free(err2); snprintf(nodename, sizeof(nodename), "%s/page-ref", dev->nodename); err2 = xenbus_rm(XBT_NIL, nodename); - if (err2) free(err2); + free(err2); snprintf(nodename, sizeof(nodename), "%s/event-channel", dev->nodename); err2 = xenbus_rm(XBT_NIL, nodename); - if (err2) free(err2); + free(err2); snprintf(nodename, sizeof(nodename), "%s/protocol", dev->nodename); err2 = xenbus_rm(XBT_NIL, nodename); - if (err2) free(err2); + free(err2); snprintf(nodename, sizeof(nodename), "%s/feature-update", dev->nodename); err2 = xenbus_rm(XBT_NIL, nodename); - if (err2) free(err2); + free(err2); if (!err) free_fbfront(dev); diff --git a/extras/mini-os/kernel.c b/extras/mini-os/kernel.c index 24fa25c..ea409f4 100644 --- a/extras/mini-os/kernel.c +++ b/extras/mini-os/kernel.c @@ -85,9 +85,9 @@ static void shutdown_thread(void *p) xenbus_wait_for_watch(&events); } err = xenbus_unwatch_path_token(XBT_NIL, path, token); - if (err) free(err); + free(err); err = xenbus_write(XBT_NIL, path, ""); - if (err) free(err); + free(err); printk("Shutting down (%s)\n", shutdown); if (!strcmp(shutdown, "poweroff")) diff --git a/extras/mini-os/lib/sys.c b/extras/mini-os/lib/sys.c index cfbdc90..13e7e59 100644 --- a/extras/mini-os/lib/sys.c +++ b/extras/mini-os/lib/sys.c @@ -1156,8 +1156,7 @@ LWIP_STUB(int, getsockname, (int s, struct sockaddr *name, socklen_t *namelen), static char *syslog_ident; void openlog(const char *ident, int option, int facility) { - if (syslog_ident) - free(syslog_ident); + free(syslog_ident); syslog_ident = strdup(ident); } diff --git a/extras/mini-os/netfront.c b/extras/mini-os/netfront.c index 3a5be64..44c3995 100644 --- a/extras/mini-os/netfront.c +++ b/extras/mini-os/netfront.c @@ -412,7 +412,7 @@ again: } err = xenbus_transaction_end(xbt, 0, &retry); - if (err) free(err); + free(err); if (retry) { goto again; printk("completing transaction\n"); @@ -525,7 +525,7 @@ void shutdown_netfront(struct netfront_dev *dev) state = xenbus_read_integer(path); while (err == NULL && state < XenbusStateClosing) err = xenbus_wait_for_state_change(path, &state, &dev->events); - if (err) free(err); + free(err); if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateClosed)) != NULL) { printk("shutdown_netfront: error changing state to %d: %s\n", @@ -535,7 +535,7 @@ void shutdown_netfront(struct netfront_dev *dev) state = xenbus_read_integer(path); while (state < XenbusStateClosed) { err = xenbus_wait_for_state_change(path, &state, &dev->events); - if (err) free(err); + free(err); } if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateInitialising)) != NULL) { @@ -548,22 +548,22 @@ void shutdown_netfront(struct netfront_dev *dev) err = xenbus_wait_for_state_change(path, &state, &dev->events); close: - if (err) free(err); + free(err); err2 = xenbus_unwatch_path_token(XBT_NIL, path, path); - if (err2) free(err2); + free(err2); snprintf(nodename, sizeof(nodename), "%s/tx-ring-ref", dev->nodename); err2 = xenbus_rm(XBT_NIL, nodename); - if (err2) free(err2); + free(err2); snprintf(nodename, sizeof(nodename), "%s/rx-ring-ref", dev->nodename); err2 = xenbus_rm(XBT_NIL, nodename); - if (err2) free(err2); + free(err2); snprintf(nodename, sizeof(nodename), "%s/event-channel", dev->nodename); err2 = xenbus_rm(XBT_NIL, nodename); - if (err2) free(err2); + free(err2); snprintf(nodename, sizeof(nodename), "%s/request-rx-copy", dev->nodename); err2 = xenbus_rm(XBT_NIL, nodename); - if (err2) free(err2); + free(err2); if (!err) free_netfront(dev); diff --git a/extras/mini-os/pcifront.c b/extras/mini-os/pcifront.c index 7838021..16a4b49 100644 --- a/extras/mini-os/pcifront.c +++ b/extras/mini-os/pcifront.c @@ -212,7 +212,7 @@ again: } err = xenbus_transaction_end(xbt, 0, &retry); - if (err) free(err); + free(err); if (retry) { goto again; printk("completing transaction\n"); @@ -251,7 +251,7 @@ done: err = xenbus_wait_for_state_change(path, &state, &dev->events); if (state != XenbusStateConnected) { printk("backend not avalable, state=%d\n", state); - if (err) free(err); + free(err); err = xenbus_unwatch_path_token(XBT_NIL, path, path); goto error; } @@ -342,7 +342,7 @@ void shutdown_pcifront(struct pcifront_dev *dev) state = xenbus_read_integer(path); while (err == NULL && state < XenbusStateClosing) err = xenbus_wait_for_state_change(path, &state, &dev->events); - if (err) free(err); + free(err); if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateClosed)) != NULL) { printk("shutdown_pcifront: error changing state to %d: %s\n", @@ -365,16 +365,16 @@ void shutdown_pcifront(struct pcifront_dev *dev) err = xenbus_wait_for_state_change(path, &state, &dev->events); close_pcifront: - if (err) free(err); + free(err); err2 = xenbus_unwatch_path_token(XBT_NIL, path, path); - if (err2) free(err2); + free(err2); snprintf(nodename, sizeof(nodename), "%s/info-ref", dev->nodename); err2 = xenbus_rm(XBT_NIL, nodename); - if (err2) free(err2); + free(err2); snprintf(nodename, sizeof(nodename), "%s/event-channel", dev->nodename); err2 = xenbus_rm(XBT_NIL, nodename); - if (err2) free(err2); + free(err2); if (!err) free_pcifront(dev); diff --git a/tools/flask/utils/loadpolicy.c b/tools/flask/utils/loadpolicy.c index f347b97..2edcf97 100644 --- a/tools/flask/utils/loadpolicy.c +++ b/tools/flask/utils/loadpolicy.c @@ -108,8 +108,7 @@ int main (int argCnt, const char *args[]) } done: - if ( polMemCp ) - free(polMemCp); + free(polMemCp); if ( polMem ) { ret = munmap(polMem, info.st_size); diff --git a/tools/libxc/xc_compression.c b/tools/libxc/xc_compression.c index 89f1be7..8f0b89d 100644 --- a/tools/libxc/xc_compression.c +++ b/tools/libxc/xc_compression.c @@ -457,16 +457,11 @@ void xc_compression_free_context(xc_interface *xch, comp_ctx *ctx) { if (!ctx) return; - if (ctx->inputbuf) - free(ctx->inputbuf); - if (ctx->sendbuf_pfns) - free(ctx->sendbuf_pfns); - if (ctx->cache_base) - free(ctx->cache_base); - if (ctx->pfn2cache) - free(ctx->pfn2cache); - if (ctx->cache) - free(ctx->cache); + free(ctx->inputbuf); + free(ctx->sendbuf_pfns); + free(ctx->cache_base); + free(ctx->pfn2cache); + free(ctx->cache); free(ctx); } diff --git a/tools/libxc/xc_core_x86.c b/tools/libxc/xc_core_x86.c index a9681f7..e328dcf 100644 --- a/tools/libxc/xc_core_x86.c +++ b/tools/libxc/xc_core_x86.c @@ -180,11 +180,9 @@ out: if ( live_p2m_frame_list ) munmap(live_p2m_frame_list, P2M_FLL_ENTRIES * PAGE_SIZE); - if ( p2m_frame_list_list ) - free(p2m_frame_list_list); + free(p2m_frame_list_list); - if ( p2m_frame_list ) - free(p2m_frame_list); + free(p2m_frame_list); errno = err; return ret; diff --git a/tools/libxc/xc_domain_save.c b/tools/libxc/xc_domain_save.c index fbc15e9..673d1e9 100644 --- a/tools/libxc/xc_domain_save.c +++ b/tools/libxc/xc_domain_save.c @@ -773,11 +773,9 @@ static xen_pfn_t *map_and_save_p2m_table(xc_interface *xch, if ( live_p2m_frame_list ) munmap(live_p2m_frame_list, P2M_FLL_ENTRIES * PAGE_SIZE); - if ( p2m_frame_list_list ) - free(p2m_frame_list_list); + free(p2m_frame_list_list); - if ( p2m_frame_list ) - free(p2m_frame_list); + free(p2m_frame_list); return success ? p2m : NULL; } diff --git a/tools/libxc/xc_gnttab.c b/tools/libxc/xc_gnttab.c index a8cc381..79dab40 100644 --- a/tools/libxc/xc_gnttab.c +++ b/tools/libxc/xc_gnttab.c @@ -124,8 +124,7 @@ static void *_gnttab_map_table(xc_interface *xch, int domid, int *gnt_num) err: if ( frame_list ) xc_hypercall_buffer_free(xch, frame_list); - if ( pfn_list ) - free(pfn_list); + free(pfn_list); return gnt; } diff --git a/tools/libxc/xc_offline_page.c b/tools/libxc/xc_offline_page.c index 8195efb..0b4cdf9 100644 --- a/tools/libxc/xc_offline_page.c +++ b/tools/libxc/xc_offline_page.c @@ -626,14 +626,11 @@ failed: } } - if (mmu) - free(mmu); + free(mmu); - if (old_ptes.entries) - free(old_ptes.entries); + free(old_ptes.entries); - if (backup) - free(backup); + free(backup); if (gnttab_v1) munmap(gnttab_v1, gnt_num / (PAGE_SIZE/sizeof(grant_entry_v1_t))); diff --git a/tools/libxl/libxl_event.c b/tools/libxl/libxl_event.c index a5c52bc..c5e9426 100644 --- a/tools/libxl/libxl_event.c +++ b/tools/libxl/libxl_event.c @@ -578,8 +578,7 @@ int libxl__ev_xswatch_register(libxl__gc *gc, libxl__ev_xswatch *w, out_rc: if (use) LIBXL_SLIST_INSERT_HEAD(&CTX->watch_freeslots, use, empty); - if (path_copy) - free(path_copy); + free(path_copy); CTX_UNLOCK; return rc; } diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index f681f3a..7e825ee 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -406,12 +406,10 @@ static void qmp_close(libxl__qmp_handler *qmp) close(qmp->qmp_fd); LIBXL_STAILQ_FOREACH(pp, &qmp->callback_list, next) { - if (tmp) - free(tmp); + free(tmp); tmp = pp; } - if (tmp) - free(tmp); + free(tmp); } static int qmp_next(libxl__gc *gc, libxl__qmp_handler *qmp) diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c index 1bcac7e..682f874 100644 --- a/tools/libxl/libxl_utils.c +++ b/tools/libxl/libxl_utils.c @@ -355,7 +355,7 @@ int libxl_read_file_contents(libxl_ctx *ctx, const char *filename, e = errno; assert(e != ENOENT); if (f) fclose(f); - if (data) free(data); + free(data); return e; } diff --git a/tools/memshr/bidir-hash.c b/tools/memshr/bidir-hash.c index bed8179..3d34637 100644 --- a/tools/memshr/bidir-hash.c +++ b/tools/memshr/bidir-hash.c @@ -208,8 +208,8 @@ static void free_buckets(struct __hash *h, struct bucket *buckets, struct bucket_lock *bucket_locks) { - if(buckets) free(buckets); - if(bucket_locks) free(bucket_locks); + free(buckets); + free(bucket_locks); } static int max_entries(struct __hash *h) diff --git a/tools/misc/gtraceview.c b/tools/misc/gtraceview.c index d8b4589..cf9287c 100644 --- a/tools/misc/gtraceview.c +++ b/tools/misc/gtraceview.c @@ -959,8 +959,7 @@ int time_mode_rebuild(uint64_t start_time, uint64_t time_scale) state = malloc(sizeof(struct state) * number); if (!state) return 1; - if (this->state) - free(this->state); + free(this->state); this->state = state; this->width = 9; this->row = 0; diff --git a/tools/tests/xen-access/xen-access.c b/tools/tests/xen-access/xen-access.c index 49195a8..b00c05a 100644 --- a/tools/tests/xen-access/xen-access.c +++ b/tools/tests/xen-access/xen-access.c @@ -219,10 +219,8 @@ int xenaccess_teardown(xc_interface *xch, xenaccess_t *xenaccess) } xenaccess->xc_handle = NULL; - if ( xenaccess->platform_info ) - free(xenaccess->platform_info); - if ( xenaccess->domain_info ) - free(xenaccess->domain_info); + free(xenaccess->platform_info); + free(xenaccess->domain_info); free(xenaccess); return 0; diff --git a/tools/xenbackendd/xenbackendd.c b/tools/xenbackendd/xenbackendd.c index 5381a2a..f1eb1f5 100644 --- a/tools/xenbackendd/xenbackendd.c +++ b/tools/xenbackendd/xenbackendd.c @@ -291,8 +291,7 @@ main(int argc, char * const argv[]) switch(type) { case DEVTYPE_VIF: - if (s) - free(s); + free(s); snprintf(buf, sizeof(buf), "%s/script", vec[XS_WATCH_PATH]); s = xs_read(xs, XBT_NULL, buf, 0); @@ -314,8 +313,7 @@ main(int argc, char * const argv[]) } next2: - if (s) - free(s); + free(s); free(sstate); next1: -- generated by git-patchbot for /home/xen/git/xen.git#master _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |