Remove unnecessary NULL checks before freeing memory blocks.

The following functions check for NULL internally:
 free, kfree, xfree, free_xenheap_page[s]

Signed-off-by: Keir Fraser <keir@xensource.com>
This commit is contained in:
kaf24@firebug.cl.cam.ac.uk committed 2005-11-11 12:55:47 +01:00
1 parent 8b31a682c1
commit f8e8438eef
35 files changed
+89 -173

No files matched your search

@@ -97,9 +97,7 @@ static inline unsigned char *
transmission_set_buffer(struct transmission *t,
unsigned char *buffer, unsigned int len)
{
if (NULL != t->request) {
kfree(t->request);
}
kfree(t->request);
t->request = kmalloc(len, GFP_KERNEL);
if (t->request) {
memcpy(t->request,
@@ -113,12 +111,8 @@ transmission_set_buffer(struct transmission *t,
static inline void
transmission_free(struct transmission *t)
{
if (t->request) {
kfree(t->request);
}
if (t->rcv_buffer) {
kfree(t->rcv_buffer);
}
kfree(t->request);
kfree(t->rcv_buffer);
kfree(t);
}
@@ -48,8 +48,7 @@ static int blkback_remove(struct xenbus_device *dev)
unregister_xenbus_watch(&be->backend_watch);
if (be->blkif)
blkif_put(be->blkif);
if (be->frontpath)
kfree(be->frontpath);
kfree(be->frontpath);
kfree(be);
return 0;
}
@@ -274,8 +273,7 @@ static int blkback_probe(struct xenbus_device *dev,
free_be:
if (be->backend_watch.node)
unregister_xenbus_watch(&be->backend_watch);
if (frontend)
kfree(frontend);
kfree(frontend);
kfree(be);
return err;
}
@@ -607,8 +607,7 @@ again:
destroy_blkring:
blkif_free(info);
out:
if (backend)
kfree(backend);
kfree(backend);
return err;
}
@@ -52,8 +52,7 @@ static int blkback_remove(struct xenbus_device *dev)
unregister_xenbus_watch(&be->backend_watch);
if (be->blkif)
blkif_put(be->blkif);
if (be->frontpath)
kfree(be->frontpath);
kfree(be->frontpath);
kfree(be);
return 0;
}
@@ -201,8 +200,7 @@ static int blkback_probe(struct xenbus_device *dev,
free_be:
if (be->backend_watch.node)
unregister_xenbus_watch(&be->backend_watch);
if (frontend)
kfree(frontend);
kfree(frontend);
kfree(be);
return err;
}
@@ -160,10 +160,8 @@ static int __init make_loopback(int i)
return 0;
fail:
if (dev1 != NULL)
kfree(dev1);
if (dev2 != NULL)
kfree(dev2);
kfree(dev1);
kfree(dev2);
return err;
}
@@ -46,8 +46,7 @@ static int netback_remove(struct xenbus_device *dev)
unregister_xenbus_watch(&be->backend_watch);
if (be->netif)
netif_disconnect(be->netif);
if (be->frontpath)
kfree(be->frontpath);
kfree(be->frontpath);
kfree(be);
return 0;
}
@@ -253,8 +252,7 @@ static int netback_probe(struct xenbus_device *dev,
free_be:
if (be->backend_watch.node)
unregister_xenbus_watch(&be->backend_watch);
if (frontend)
kfree(frontend);
kfree(frontend);
kfree(be);
return err;
}
@@ -917,7 +917,7 @@ static int create_netdev(int handle, struct xenbus_device *dev,
np->netdev = netdev;
exit:
if ((err != 0) && (netdev != NULL))
if (err != 0)
kfree(netdev);
else if (val != NULL)
*val = netdev;
@@ -167,9 +167,7 @@ static void inline
packet_free(struct packet *pak)
{
del_singleshot_timer_sync(&pak->processing_timer);
if (pak->data_buffer) {
kfree(pak->data_buffer);
}
kfree(pak->data_buffer);
/*
* cannot do tpmif_put(pak->tpmif); bad things happen
* on the last tpmif_put()
@@ -41,19 +41,16 @@ static int tpmback_remove(struct xenbus_device *dev)
{
struct backend_info *be = dev->data;
if (be->watch.node) {
if (be->watch.node)
unregister_xenbus_watch(&be->watch);
}
unregister_xenbus_watch(&be->backend_watch);
tpmif_vtpm_close(be->instance);
if (be->tpmif) {
if (be->tpmif)
tpmif_put(be->tpmif);
}
if (be->frontpath)
kfree(be->frontpath);
kfree(be->frontpath);
kfree(be);
return 0;
}
@@ -258,8 +255,7 @@ static int tpmback_probe(struct xenbus_device *dev,
free_be:
if (be->backend_watch.node)
unregister_xenbus_watch(&be->backend_watch);
if (frontend)
kfree(frontend);
kfree(frontend);
kfree(be);
return err;
}
@@ -387,8 +387,7 @@ abort_transaction:
destroy_tpmring:
destroy_tpmring(info, &my_private);
out:
if (backend)
kfree(backend);
kfree(backend);
return err;
}
+1 -2
View File
@@ -108,8 +108,7 @@ void free_blkif(blkif_t *blkif)
}
pblkif = &curs->hash_next;
}
if (blkif != NULL)
free(blkif);
free(blkif);
}
void blkif_register_request_hook(blkif_t *blkif, char *name,
+2 -4
View File
@@ -604,8 +604,7 @@ void *readblock_indiv(int server, uint64_t id) {
return block;
err:
if (qe->block)
free(qe->block);
free(qe->block);
free((void *)qe);
return NULL;
}
@@ -1072,7 +1071,7 @@ uint64_t allocblock_hint(void *block, uint64_t hint) {
*
* @return: pointer to new block, NULL on error
*/
void *newblock() {
void *newblock(void) {
void *block = malloc(BLOCK_SIZE);
if (block == NULL) {
perror("newblock");
@@ -1089,7 +1088,6 @@ void *newblock() {
* @block: block to be freed
*/
void freeblock(void *block) {
if (block != NULL)
free(block);
}
+1 -2
View File
@@ -232,7 +232,7 @@ uint64_t allocblock(void *block) {
*
* @return: pointer to new block, NULL on error
*/
void *newblock() {
void *newblock(void) {
void *block = malloc(BLOCK_SIZE);
if (block == NULL) {
perror("newblock");
@@ -249,7 +249,6 @@ void *newblock() {
* @block: block to be freed
*/
void freeblock(void *block) {
if (block != NULL)
free(block);
}
+1 -1
View File
@@ -715,7 +715,7 @@ static void write_cb(struct io_ret r, void *param)
r.u.i = -1;
/* free any saved node vals. */
for (i=0; i<3; i++)
if (req->radix[i] != 0) free(req->radix[i]);
free(req->radix[i]);
free(req);
cb(r, req_param);
}
+7 -14
View File
@@ -339,10 +339,8 @@ static int backend_remove(struct xs_handle *h, struct backend_info *be)
/* Free everything else. */
if (be->blkif)
free_blkif(be->blkif);
if (be->frontpath)
free(be->frontpath);
if (be->backpath)
free(be->backpath);
free(be->frontpath);
free(be->backpath);
free(be);
return 0;
}
@@ -406,8 +404,7 @@ static void frontend_changed(struct xs_handle *h, struct xenbus_watch *w,
return;
fail:
if (fepath)
free(fepath);
free(fepath);
}
@@ -460,9 +457,7 @@ static void backend_changed(struct xs_handle *h, struct xenbus_watch *w,
}
fail:
if (path)
free(path);
free(path);
}
static void blkback_probe(struct xs_handle *h, struct xenbus_watch *w,
@@ -537,12 +532,10 @@ static void blkback_probe(struct xs_handle *h, struct xenbus_watch *w,
return;
free_be:
if ((be) && (be->backend_watch.node))
if (be && (be->backend_watch.node))
unregister_xenbus_watch(h, &be->backend_watch);
if (frontend)
free(frontend);
if (bepath)
free(bepath);
free(frontend);
free(bepath);
free(be);
return;
}
+6 -11
View File
@@ -344,8 +344,7 @@ static struct domain *create_domain(int domid)
return dom;
out:
if (dom->conspath)
free(dom->conspath);
free(dom->conspath);
free(dom);
return NULL;
}
@@ -380,20 +379,16 @@ static void cleanup_domain(struct domain *d)
if (!buffer_empty(&d->buffer))
return;
if (d->buffer.data) {
free(d->buffer.data);
d->buffer.data = NULL;
}
if (d->tty_fd != -1) {
close(d->tty_fd);
d->tty_fd = -1;
}
if (d->conspath) {
free(d->conspath);
d->conspath = NULL;
}
free(d->buffer.data);
d->buffer.data = NULL;
free(d->conspath);
d->conspath = NULL;
remove_domain(d);
}
+2 -4
View File
@@ -196,10 +196,8 @@ static void load_symbols(struct elfhdr *ehdr, int fd)
goto error_freesyms;
/* Commit */
if (disas_symtab)
qemu_free(disas_symtab); /* XXX Merge with old symbols? */
if (disas_strtab)
qemu_free(disas_strtab);
qemu_free(disas_symtab); /* XXX Merge with old symbols? */
qemu_free(disas_strtab);
disas_symtab = syms;
disas_num_syms = nsyms;
disas_strtab = str;
+2 -4
View File
@@ -187,8 +187,7 @@ static void mouse_find_bounding_box_of_difference(int* x,int* y,int* w,int* h) {
static void start_mouse_calibration() {
int size = screen->height*screen->paddedWidthInBytes;
if(mouse_magic->calibration)
free(mouse_magic->calibration);
free(mouse_magic->calibration);
mouse_magic->calibration = malloc(size);
memcpy(mouse_magic->calibration, screen->frameBuffer, size);
calibration_step=0;
@@ -198,8 +197,7 @@ static void start_mouse_calibration() {
}
static void stop_mouse_calibration() {
if(mouse_magic->calibration)
free(mouse_magic->calibration);
free(mouse_magic->calibration);
mouse_magic->calibration = 0;
}
+4 -8
View File
@@ -77,7 +77,7 @@ int xc_ia64_copy_to_domain_pages(int xc_handle, uint32_t domid,
{
// N.B. gva should be page aligned
unsigned long *page_array=NULL;
unsigned long *page_array = NULL;
int i;
if ( (page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL ){
@@ -99,8 +99,7 @@ int xc_ia64_copy_to_domain_pages(int xc_handle, uint32_t domid,
return 0;
error_out:
if (page_array)
free(page_array);
free(page_array);
return -1;
}
@@ -657,8 +656,7 @@ int xc_vmx_build(int xc_handle,
goto error_out;
}
if ( image != NULL )
free(image);
free(image);
ctxt->flags = VGCF_VMX_GUEST;
ctxt->regs.cr_iip = 0x80000000ffffffb0UL;
@@ -675,9 +673,7 @@ int xc_vmx_build(int xc_handle,
return rc;
error_out:
if ( image != NULL )
free(image);
free(image);
return -1;
}
+4 -9
View File
@@ -670,10 +670,8 @@ static int setup_guest(int xc_handle,
return 0;
error_out:
if ( mmu != NULL )
free(mmu);
if ( page_array != NULL )
free(page_array);
free(mmu);
free(page_array);
return -1;
}
#endif
@@ -768,8 +766,7 @@ int xc_linux_build(int xc_handle,
close(initrd_fd);
if ( initrd_gfd )
gzclose(initrd_gfd);
if ( image != NULL )
free(image);
free(image);
#ifdef __ia64__
/* based on new_thread in xen/arch/ia64/domain.c */
@@ -858,9 +855,7 @@ int xc_linux_build(int xc_handle,
gzclose(initrd_gfd);
else if ( initrd_fd >= 0 )
close(initrd_fd);
if ( image != NULL )
free(image);
free(image);
return -1;
}
+4 -9
View File
@@ -565,10 +565,8 @@ static int setup_guest(int xc_handle,
return 0;
error_out:
if ( mmu != NULL )
free(mmu);
if ( page_array != NULL )
free(page_array);
free(mmu);
free(page_array);
return -1;
}
@@ -663,8 +661,7 @@ int xc_vmx_build(int xc_handle,
goto error_out;
}
if ( image != NULL )
free(image);
free(image);
ctxt->flags = VGCF_VMX_GUEST;
/* FPU is set up to default initial state. */
@@ -710,9 +707,7 @@ int xc_vmx_build(int xc_handle,
return rc;
error_out:
if ( image != NULL )
free(image);
free(image);
return -1;
}
+3 -6
View File
@@ -114,8 +114,7 @@ static PyObject *xspy_read(PyObject *self, PyObject *args, PyObject *kwds)
}
val = PyString_FromStringAndSize(xsval, xsval_n);
exit:
if (xsval)
free(xsval);
free(xsval);
return val;
}
@@ -427,8 +426,7 @@ static PyObject *xspy_set_permissions(PyObject *self, PyObject *args,
val = Py_None;
exit:
Py_XDECREF(tuple0);
if (xsperms)
free(xsperms);
free(xsperms);
return val;
}
@@ -541,8 +539,7 @@ again:
/* Create tuple (path, token). */
val = Py_BuildValue("(sO)", xsval[XS_WATCH_PATH], token);
exit:
if (xsval)
free(xsval);
free(xsval);
return val;
}
+1 -2
View File
@@ -393,8 +393,7 @@ TPM_RESULT VTPM_LoadService(void) {
vtpmlogerror(VTPM_LOG_VTPM, "Failed to load service data with error = %s\n", tpm_get_error_name(status));
egress:
if (flat_global)
free(flat_global);
free(flat_global);
close(fh);
return status;
+1 -2
View File
@@ -616,8 +616,7 @@ static void BSG_Destroy_private(BSG_Type type, BSG_BYTE** src) {
else if (format == __FMT_SIZE || format == __FMT_HSIZE) {
s += size;
BSG_BYTE* ptr = *(BSG_BYTE**) s;
if (ptr)
free(ptr);
free(ptr);
s += sizeof(void*);
} else if (format == __FMT_PACKED) {
+2 -4
View File
@@ -284,10 +284,8 @@ void xenstat_free_node(xenstat_node * node)
if (node) {
if (node->domains) {
for (i = 0; i < node->num_domains; i++) {
if (node->domains[i].name)
free(node->domains[i].name);
}
for (i = 0; i < node->num_domains; i++)
free(node->domains[i].name);
for (i = 0; i < NUM_COLLECTORS; i++)
if((node->flags & collectors[i].flag)
-2
View File
@@ -1411,8 +1411,6 @@ static void manual_node(const char *name, const char *child)
talloc_free(node);
}
#
static void setup_structure(void)
{
char *tdbname;
+9 -18
View File
@@ -117,8 +117,7 @@ static int chwall_init_domain_ssid(void **chwall_ssid, ssidref_t ssidref)
static void chwall_free_domain_ssid(void *chwall_ssid)
{
traceprintk("%s.\n", __func__);
if (chwall_ssid != NULL)
xfree(chwall_ssid);
xfree(chwall_ssid);
return;
}
@@ -344,14 +343,10 @@ static int chwall_set_policy(u8 * buf, u32 buf_size)
chwall_bin_pol.max_types = chwall_buf->chwall_max_types;
chwall_bin_pol.max_ssidrefs = chwall_buf->chwall_max_ssidrefs;
chwall_bin_pol.max_conflictsets = chwall_buf->chwall_max_conflictsets;
if (chwall_bin_pol.ssidrefs != NULL)
xfree(chwall_bin_pol.ssidrefs);
if (chwall_bin_pol.conflict_aggregate_set != NULL)
xfree(chwall_bin_pol.conflict_aggregate_set);
if (chwall_bin_pol.running_types != NULL)
xfree(chwall_bin_pol.running_types);
if (chwall_bin_pol.conflict_sets != NULL)
xfree(chwall_bin_pol.conflict_sets);
xfree(chwall_bin_pol.ssidrefs);
xfree(chwall_bin_pol.conflict_aggregate_set);
xfree(chwall_bin_pol.running_types);
xfree(chwall_bin_pol.conflict_sets);
chwall_bin_pol.ssidrefs = ssids;
chwall_bin_pol.conflict_aggregate_set = conflict_aggregate_set;
chwall_bin_pol.running_types = running_types;
@@ -360,14 +355,10 @@ static int chwall_set_policy(u8 * buf, u32 buf_size)
error_free:
printk("%s: ERROR setting policy.\n", __func__);
if (ssids != NULL)
xfree(ssids);
if (conflict_sets != NULL)
xfree(conflict_sets);
if (running_types != NULL)
xfree(running_types);
if (conflict_aggregate_set != NULL)
xfree(conflict_aggregate_set);
xfree(ssids);
xfree(conflict_sets);
xfree(running_types);
xfree(conflict_aggregate_set);
return -EFAULT;
}
+3 -5
View File
@@ -130,8 +130,7 @@ static void
ste_free_domain_ssid(void *ste_ssid)
{
traceprintk("%s.\n", __func__);
if (ste_ssid != NULL)
xfree(ste_ssid);
xfree(ste_ssid);
return;
}
@@ -320,8 +319,7 @@ ste_set_policy(u8 *buf, u32 buf_size)
/* 3. replace old policy (activate new policy) */
ste_bin_pol.max_types = ste_buf->ste_max_types;
ste_bin_pol.max_ssidrefs = ste_buf->ste_max_ssidrefs;
if (ste_bin_pol.ssidrefs)
xfree(ste_bin_pol.ssidrefs);
xfree(ste_bin_pol.ssidrefs);
ste_bin_pol.ssidrefs = (domaintype_t *)ssidrefsbuf;
/* clear all ste caches */
@@ -338,7 +336,7 @@ ste_set_policy(u8 *buf, u32 buf_size)
error_free:
printk("%s: ERROR setting policy.\n", __func__);
if (ssidrefsbuf != NULL) xfree(ssidrefsbuf);
xfree(ssidrefsbuf);
return -EFAULT;
}
+1 -2
View File
@@ -1348,8 +1348,7 @@ grant_table_create(
if ( t != NULL )
{
xfree(t->active);
if ( t->maptrack != NULL )
free_xenheap_page(t->maptrack);
free_xenheap_page(t->maptrack);
xfree(t);
}
return -ENOMEM;
+2 -4
View File
@@ -3369,10 +3369,8 @@ int ptwr_init(struct domain *d)
if ( (x == NULL) || (y == NULL) )
{
if ( x != NULL )
free_xenheap_page(x);
if ( y != NULL )
free_xenheap_page(y);
free_xenheap_page(x);
free_xenheap_page(y);
return -ENOMEM;
}
+1 -2
View File
@@ -71,8 +71,7 @@ void __init get_mtrr_state(void)
/* Free resources associated with a struct mtrr_state */
void __init finalize_mtrr_state(void)
{
if (mtrr_state.var_ranges)
xfree(mtrr_state.var_ranges);
xfree(mtrr_state.var_ranges);
mtrr_state.var_ranges = NULL;
}
+8 -13
View File
@@ -564,19 +564,14 @@ err_out:
void destroy_vmcs(struct arch_vmx_struct *arch_vmx)
{
if(arch_vmx->vmcs != NULL)
free_vmcs(arch_vmx->vmcs);
if(arch_vmx->io_bitmap_a != 0) {
free_xenheap_pages(
arch_vmx->io_bitmap_a, get_order_from_bytes(0x1000));
arch_vmx->io_bitmap_a = 0;
}
if(arch_vmx->io_bitmap_b != 0) {
free_xenheap_pages(
arch_vmx->io_bitmap_b, get_order_from_bytes(0x1000));
arch_vmx->io_bitmap_b = 0;
}
arch_vmx->vmcs = 0;
free_vmcs(arch_vmx->vmcs);
arch_vmx->vmcs = NULL;
free_xenheap_pages(arch_vmx->io_bitmap_a, get_order_from_bytes(0x1000));
arch_vmx->io_bitmap_a = NULL;
free_xenheap_pages(arch_vmx->io_bitmap_b, get_order_from_bytes(0x1000));
arch_vmx->io_bitmap_b = NULL;
}
/*
+1 -2
View File
@@ -621,8 +621,7 @@ void evtchn_destroy(struct domain *d)
(void)__evtchn_close(d, i);
for ( i = 0; i < NR_EVTCHN_BUCKETS; i++ )
if ( d->evtchn[i] != NULL )
xfree(d->evtchn[i]);
xfree(d->evtchn[i]);
}
/*
+1 -2
View File
@@ -1107,8 +1107,7 @@ grant_table_create(
if ( t != NULL )
{
xfree(t->active);
if ( t->maptrack != NULL )
free_xenheap_page(t->maptrack);
free_xenheap_page(t->maptrack);
xfree(t);
}
return -ENOMEM;
+3
View File
@@ -470,6 +470,9 @@ void free_xenheap_pages(void *v, unsigned int order)
{
unsigned long flags;
if ( v == NULL )
return;
memguard_guard_range(v, 1 << (order + PAGE_SHIFT));
local_irq_save(flags);
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.