All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xen/many: xfree() can tolerate NULL pointers
@ 2015-01-19 10:42 Andrew Cooper
  2015-01-19 10:54 ` Ian Campbell
  0 siblings, 1 reply; 9+ messages in thread
From: Andrew Cooper @ 2015-01-19 10:42 UTC (permalink / raw)
  To: Xen-devel
  Cc: Keir Fraser, Ian Campbell, Andrew Cooper, Ian Jackson, Tim Deegan,
	Jan Beulich

Replace instances of "if ( p ) xfree(p)" with just "xfree(p)"

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Keir Fraser <keir@xen.org>
CC: Jan Beulich <JBeulich@suse.com>
CC: Tim Deegan <tim@xen.org>
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>

---

This was from some experimentation with semantic patches.  'spatch' can't
currently parse some of our macros (e.g. XEN_GUEST_HANDLE()), which cases it
to skip large numbers of functions in the codebase
---
 xen/arch/x86/cpu/mcheck/mctelem.c |    3 +--
 xen/arch/x86/mm/hap/hap.c         |    3 +--
 xen/common/kexec.c                |    3 +--
 xen/common/sched_credit2.c        |    3 +--
 xen/common/sched_sedf.c           |    3 +--
 xen/common/schedule.c             |    5 +----
 xen/xsm/flask/ss/policydb.c       |    8 ++++----
 7 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/xen/arch/x86/cpu/mcheck/mctelem.c b/xen/arch/x86/cpu/mcheck/mctelem.c
index b8da465..95e83c5 100644
--- a/xen/arch/x86/cpu/mcheck/mctelem.c
+++ b/xen/arch/x86/cpu/mcheck/mctelem.c
@@ -260,8 +260,7 @@ void __init mctelem_init(unsigned int datasz)
 	if ((mctctl.mctc_elems = xmalloc_array(struct mctelem_ent,
 	    MC_NENT)) == NULL ||
 	    (datarr = xmalloc_bytes(MC_NENT * datasz)) == NULL) {
-		if (mctctl.mctc_elems)
-			xfree(mctctl.mctc_elems);
+		xfree(mctctl.mctc_elems);
 		printk("Allocations for MCA telemetry failed\n");
 		return;
 	}
diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c
index abf3d7a..97f5168 100644
--- a/xen/arch/x86/mm/hap/hap.c
+++ b/xen/arch/x86/mm/hap/hap.c
@@ -168,8 +168,7 @@ int hap_track_dirty_vram(struct domain *d,
                                   p2m_ram_logdirty, p2m_ram_rw);
     }
 out:
-    if ( dirty_bitmap )
-        xfree(dirty_bitmap);
+    xfree(dirty_bitmap);
 
     return rc;
 }
diff --git a/xen/common/kexec.c b/xen/common/kexec.c
index 2239ee8..d4c11cd 100644
--- a/xen/common/kexec.c
+++ b/xen/common/kexec.c
@@ -454,8 +454,7 @@ static int kexec_init_cpu_notes(const unsigned long cpu)
         spin_unlock(&crash_notes_lock);
         /* Always return ok, because whether we successfully allocated or not,
          * another CPU has successfully allocated. */
-        if ( note )
-            xfree(note);
+        xfree(note);
     }
     else
     {
diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c
index 1ca521b..ad0a5d4 100644
--- a/xen/common/sched_credit2.c
+++ b/xen/common/sched_credit2.c
@@ -2138,8 +2138,7 @@ csched2_deinit(const struct scheduler *ops)
     struct csched2_private *prv;
 
     prv = CSCHED2_PRIV(ops);
-    if ( prv != NULL )
-        xfree(prv);
+    xfree(prv);
 }
 
 
diff --git a/xen/common/sched_sedf.c b/xen/common/sched_sedf.c
index 7c80bad..c4f4b60 100644
--- a/xen/common/sched_sedf.c
+++ b/xen/common/sched_sedf.c
@@ -729,8 +729,7 @@ static void sedf_deinit(const struct scheduler *ops)
     struct sedf_priv_info *prv;
 
     prv = SEDF_PRIV(ops);
-    if ( prv != NULL )
-        xfree(prv);
+    xfree(prv);
 }
 
 
diff --git a/xen/common/schedule.c b/xen/common/schedule.c
index 6285a6e..b73177f 100644
--- a/xen/common/schedule.c
+++ b/xen/common/schedule.c
@@ -260,10 +260,7 @@ int sched_move_domain(struct domain *d, struct cpupool *c)
         if ( vcpu_priv[v->vcpu_id] == NULL )
         {
             for_each_vcpu ( d, v )
-            {
-                if ( vcpu_priv[v->vcpu_id] != NULL )
-                    xfree(vcpu_priv[v->vcpu_id]);
-            }
+                xfree(vcpu_priv[v->vcpu_id]);
             xfree(vcpu_priv);
             SCHED_OP(c->sched, free_domdata, domdata);
             return -ENOMEM;
diff --git a/xen/xsm/flask/ss/policydb.c b/xen/xsm/flask/ss/policydb.c
index 50b2c78..b88ea56 100644
--- a/xen/xsm/flask/ss/policydb.c
+++ b/xen/xsm/flask/ss/policydb.c
@@ -682,17 +682,17 @@ void policydb_destroy(struct policydb *p)
 
     for ( tr = p->role_tr; tr; tr = tr->next )
     {
-        if ( ltr ) xfree(ltr);
+        xfree(ltr);
         ltr = tr;
     }
-    if ( ltr ) xfree(ltr);
+    xfree(ltr);
 
     for ( ra = p->role_allow; ra; ra = ra -> next )
     {
-        if ( lra ) xfree(lra);
+        xfree(lra);
         lra = ra;
     }
-    if ( lra ) xfree(lra);
+    xfree(lra);
 
     for ( rt = p->range_tr; rt; rt = rt -> next )
     {
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-01-19 12:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-19 10:42 [PATCH] xen/many: xfree() can tolerate NULL pointers Andrew Cooper
2015-01-19 10:54 ` Ian Campbell
2015-01-19 11:12   ` Andrew Cooper
2015-01-19 11:18     ` Ian Campbell
2015-01-19 11:47       ` Ian Jackson
2015-01-19 12:14         ` Jan Beulich
2015-01-19 12:19           ` Ian Jackson
2015-01-19 11:29     ` Jan Beulich
2015-01-19 11:43   ` Ian Jackson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.