linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/20] remove unneeded null test before free
@ 2015-05-01 19:37 Julia Lawall
  2015-05-01 19:37 ` [PATCH 20/20] staging: lustre: ptlrpc: service: " Julia Lawall
                   ` (19 more replies)
  0 siblings, 20 replies; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:37 UTC (permalink / raw)
  To: linux-kernel
  Cc: kernel-janitors, devel, HPDD-discuss, Greg Kroah-Hartman,
	Andreas Dilger, Oleg Drokin

These patches are motivated by the preceding patch series that converts
uses of OBD_FREE and OBD_FREE_PTR to kfree.  These patches should thus be
applied after that previous patch series (subject: Use kzalloc and kfree).


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

* [PATCH 20/20] staging: lustre: ptlrpc: service: remove unneeded null test before free
  2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
@ 2015-05-01 19:37 ` Julia Lawall
  2015-05-01 19:37 ` [PATCH 19/20] staging: lustre: ptlrpc: sec_plain: " Julia Lawall
                   ` (18 subsequent siblings)
  19 siblings, 0 replies; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:37 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel

Kfree can cope with a null argument, so drop null tests.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL)
  kfree(ptr);

@@ expression ptr; @@

- if (ptr != NULL) {
  kfree(ptr);
  ptr = NULL;
- }
// </smpl>

In the first case, specific labels are introduced to free only what is needed.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/staging/lustre/lustre/ptlrpc/service.c |   39 ++++++++-----------------
 1 file changed, 14 insertions(+), 25 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c
index d0758ab..d85db06 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/service.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/service.c
@@ -641,7 +641,7 @@ ptlrpc_service_part_init(struct ptlrpc_service *svc,
 	OBD_CPT_ALLOC(array->paa_reqs_count,
 		      svc->srv_cptable, cpt, sizeof(__u32) * size);
 	if (array->paa_reqs_count == NULL)
-		goto failed;
+		goto free_reqs_array;
 
 	cfs_timer_init(&svcpt->scp_at_timer, ptlrpc_at_timer, svcpt);
 	/* At SOW, service time should be quick; 10s seems generous. If client
@@ -655,20 +655,16 @@ ptlrpc_service_part_init(struct ptlrpc_service *svc,
 	/* We shouldn't be under memory pressure at startup, so
 	 * fail if we can't allocate all our buffers at this time. */
 	if (rc != 0)
-		goto failed;
+		goto free_reqs_count;
 
 	return 0;
 
- failed:
-	if (array->paa_reqs_count != NULL) {
-		kfree(array->paa_reqs_count);
-		array->paa_reqs_count = NULL;
-	}
-
-	if (array->paa_reqs_array != NULL) {
-		kfree(array->paa_reqs_array);
-		array->paa_reqs_array = NULL;
-	}
+free_reqs_count:
+	kfree(array->paa_reqs_count);
+	array->paa_reqs_count = NULL;
+free_reqs_array:
+	kfree(array->paa_reqs_array);
+	array->paa_reqs_array = NULL;
 
 	return -ENOMEM;
 }
@@ -722,8 +718,7 @@ ptlrpc_register_service(struct ptlrpc_service_conf *conf,
 			if (rc <= 0) {
 				CERROR("%s: failed to parse CPT array %s: %d\n",
 				       conf->psc_name, cconf->cc_pattern, rc);
-				if (cpts != NULL)
-					kfree(cpts);
+				kfree(cpts);
 				return ERR_PTR(rc < 0 ? rc : -EINVAL);
 			}
 			ncpts = rc;
@@ -733,8 +728,7 @@ ptlrpc_register_service(struct ptlrpc_service_conf *conf,
 	service = kzalloc(offsetof(struct ptlrpc_service, srv_parts[ncpts]),
 			  GFP_NOFS);
 	if (service == NULL) {
-		if (cpts != NULL)
-			kfree(cpts);
+		kfree(cpts);
 		return ERR_PTR(-ENOMEM);
 	}
 
@@ -2997,15 +2991,10 @@ ptlrpc_service_free(struct ptlrpc_service *svc)
 		cfs_timer_disarm(&svcpt->scp_at_timer);
 		array = &svcpt->scp_at_array;
 
-		if (array->paa_reqs_array != NULL) {
-			kfree(array->paa_reqs_array);
-			array->paa_reqs_array = NULL;
-		}
-
-		if (array->paa_reqs_count != NULL) {
-			kfree(array->paa_reqs_count);
-			array->paa_reqs_count = NULL;
-		}
+		kfree(array->paa_reqs_array);
+		array->paa_reqs_array = NULL;
+		kfree(array->paa_reqs_count);
+		array->paa_reqs_count = NULL;
 	}
 
 	ptlrpc_service_for_each_part(svcpt, i, svc)


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

* [PATCH 19/20] staging: lustre: ptlrpc: sec_plain: remove unneeded null test before free
  2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
  2015-05-01 19:37 ` [PATCH 20/20] staging: lustre: ptlrpc: service: " Julia Lawall
@ 2015-05-01 19:37 ` Julia Lawall
  2015-05-02  9:14   ` walter harms
  2015-05-01 19:37 ` [PATCH 18/20] Staging: lustre: ptlrpc: lproc_ptlrpc: " Julia Lawall
                   ` (17 subsequent siblings)
  19 siblings, 1 reply; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:37 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel

Kfree can cope with a null argument, so drop null tests.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL)
  kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/staging/lustre/lustre/ptlrpc/sec_plain.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c b/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c
index 604e511..989cdcd 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c
@@ -384,8 +384,7 @@ struct ptlrpc_cli_ctx *plain_sec_install_ctx(struct plain_sec *plsec)
 	if (ctx) {
 		atomic_inc(&ctx->cc_refcount);
 
-		if (ctx_new)
-			kfree(ctx_new);
+		kfree(ctx_new);
 	} else if (ctx_new) {
 		ctx = ctx_new;
 


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

* [PATCH 18/20] Staging: lustre: ptlrpc: lproc_ptlrpc: remove unneeded null test before free
  2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
  2015-05-01 19:37 ` [PATCH 20/20] staging: lustre: ptlrpc: service: " Julia Lawall
  2015-05-01 19:37 ` [PATCH 19/20] staging: lustre: ptlrpc: sec_plain: " Julia Lawall
@ 2015-05-01 19:37 ` Julia Lawall
  2015-05-01 19:37 ` [PATCH 17/20] Staging: lustre: osc: " Julia Lawall
                   ` (16 subsequent siblings)
  19 siblings, 0 replies; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:37 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel

Kfree can cope with a null argument, so drop null tests.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL)
  kfree(ptr);
// </smpl>

In the first case, the only cleanup needed is the unlock, so jump to that
directly.

Likewise, in the first two failure cases of ptlrpc_lprocfs_nrs_seq_write,
no cleanup is needed, so just drop the goto and return directly.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c |   26 ++++++--------------
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c b/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c
index 1391784..aeceef5 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c
@@ -510,7 +510,7 @@ static int ptlrpc_lprocfs_nrs_seq_show(struct seq_file *m, void *n)
 	infos = kcalloc(num_pols, sizeof(*infos), GFP_NOFS);
 	if (infos == NULL) {
 		rc = -ENOMEM;
-		goto out;
+		goto unlock;
 	}
 again:
 
@@ -617,10 +617,8 @@ again:
 		goto again;
 	}
 
-out:
-	if (infos)
-		kfree(infos);
-
+	kfree(infos);
+unlock:
 	mutex_unlock(&nrs_core.nrs_mutex);
 
 	return rc;
@@ -650,16 +648,12 @@ static ssize_t ptlrpc_lprocfs_nrs_seq_write(struct file *file,
 	char			       *token;
 	int				rc = 0;
 
-	if (count >= LPROCFS_NRS_WR_MAX_CMD) {
-		rc = -EINVAL;
-		goto out;
-	}
+	if (count >= LPROCFS_NRS_WR_MAX_CMD)
+		return -EINVAL;
 
 	cmd = kzalloc(LPROCFS_NRS_WR_MAX_CMD, GFP_NOFS);
-	if (cmd == NULL) {
-		rc = -ENOMEM;
-		goto out;
-	}
+	if (cmd == NULL)
+		return -ENOMEM;
 	/**
 	 * strsep() modifies its argument, so keep a copy
 	 */
@@ -716,8 +710,7 @@ default_queue:
 
 	mutex_unlock(&nrs_core.nrs_mutex);
 out:
-	if (cmd_copy)
-		kfree(cmd_copy);
+	kfree(cmd_copy);
 
 	return rc < 0 ? rc : count;
 }
@@ -860,8 +853,7 @@ ptlrpc_lprocfs_svc_req_history_stop(struct seq_file *s, void *iter)
 {
 	struct ptlrpc_srh_iterator *srhi = iter;
 
-	if (srhi != NULL)
-		kfree(srhi);
+	kfree(srhi);
 }
 
 static void *


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

* [PATCH 17/20] Staging: lustre: osc: remove unneeded null test before free
  2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
                   ` (2 preceding siblings ...)
  2015-05-01 19:37 ` [PATCH 18/20] Staging: lustre: ptlrpc: lproc_ptlrpc: " Julia Lawall
@ 2015-05-01 19:37 ` Julia Lawall
  2015-05-01 19:37 ` [PATCH 16/20] staging: lustre: obdecho: " Julia Lawall
                   ` (15 subsequent siblings)
  19 siblings, 0 replies; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:37 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel

Kfree can cope with a null argument, so drop null tests.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL)
  kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/staging/lustre/lustre/osc/osc_request.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c b/drivers/staging/lustre/lustre/osc/osc_request.c
index 7ddf46b..ded184e 100644
--- a/drivers/staging/lustre/lustre/osc/osc_request.c
+++ b/drivers/staging/lustre/lustre/osc/osc_request.c
@@ -2064,8 +2064,7 @@ out:
 
 		if (oa)
 			OBDO_FREE(oa);
-		if (pga)
-			kfree(pga);
+		kfree(pga);
 		/* this should happen rarely and is pretty bad, it makes the
 		 * pending list not follow the dirty order */
 		while (!list_empty(ext_list)) {


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

* [PATCH 16/20] staging: lustre: obdecho: remove unneeded null test before free
  2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
                   ` (3 preceding siblings ...)
  2015-05-01 19:37 ` [PATCH 17/20] Staging: lustre: osc: " Julia Lawall
@ 2015-05-01 19:37 ` Julia Lawall
  2015-05-01 19:37 ` [PATCH 15/20] staging: lustre: obdclass: obd_mount: " Julia Lawall
                   ` (14 subsequent siblings)
  19 siblings, 0 replies; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:37 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel

Kfree can cope with a null argument, so drop null tests.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL)
  kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/staging/lustre/lustre/obdecho/echo_client.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/lustre/lustre/obdecho/echo_client.c b/drivers/staging/lustre/lustre/obdecho/echo_client.c
index cf64538..5376178 100644
--- a/drivers/staging/lustre/lustre/obdecho/echo_client.c
+++ b/drivers/staging/lustre/lustre/obdecho/echo_client.c
@@ -1737,10 +1737,8 @@ static int echo_client_prep_commit(const struct lu_env *env,
 	}
 
 out:
-	if (lnb)
-		kfree(lnb);
-	if (rnb)
-		kfree(rnb);
+	kfree(lnb);
+	kfree(rnb);
 	return ret;
 }
 


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

* [PATCH 15/20] staging: lustre: obdclass: obd_mount: remove unneeded null test before free
  2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
                   ` (4 preceding siblings ...)
  2015-05-01 19:37 ` [PATCH 16/20] staging: lustre: obdecho: " Julia Lawall
@ 2015-05-01 19:37 ` Julia Lawall
  2015-05-01 19:37 ` [PATCH 14/20] staging: lustre: obdclass: obd_config: " Julia Lawall
                   ` (13 subsequent siblings)
  19 siblings, 0 replies; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:37 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel

Kfree can cope with a null argument, so drop null tests.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL)
  kfree(ptr);

@@ expression ptr; @@

- if (ptr != NULL) {
  kfree(ptr);
  ptr = NULL;
- }
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/staging/lustre/lustre/obdclass/obd_mount.c |   45 +++++++--------------
 1 file changed, 15 insertions(+), 30 deletions(-)

diff --git a/drivers/staging/lustre/lustre/obdclass/obd_mount.c b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
index 04a22169..1f9a5f7 100644
--- a/drivers/staging/lustre/lustre/obdclass/obd_mount.c
+++ b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
@@ -464,12 +464,9 @@ out:
 out_free:
 	mutex_unlock(&mgc_start_lock);
 
-	if (data)
-		kfree(data);
-	if (mgcname)
-		kfree(mgcname);
-	if (niduuid)
-		kfree(niduuid);
+	kfree(data);
+	kfree(mgcname);
+	kfree(niduuid);
 	return rc;
 }
 
@@ -538,8 +535,7 @@ static int lustre_stop_mgc(struct super_block *sb)
 			       niduuid, rc);
 	}
 out:
-	if (niduuid)
-		kfree(niduuid);
+	kfree(niduuid);
 
 	/* class_import_put will get rid of the additional connections */
 	mutex_unlock(&mgc_start_lock);
@@ -585,22 +581,15 @@ static int lustre_free_lsi(struct super_block *sb)
 	LASSERT(atomic_read(&lsi->lsi_mounts) == 0);
 
 	if (lsi->lsi_lmd != NULL) {
-		if (lsi->lsi_lmd->lmd_dev != NULL)
-			kfree(lsi->lsi_lmd->lmd_dev);
-		if (lsi->lsi_lmd->lmd_profile != NULL)
-			kfree(lsi->lsi_lmd->lmd_profile);
-		if (lsi->lsi_lmd->lmd_mgssec != NULL)
-			kfree(lsi->lsi_lmd->lmd_mgssec);
-		if (lsi->lsi_lmd->lmd_opts != NULL)
-			kfree(lsi->lsi_lmd->lmd_opts);
+		kfree(lsi->lsi_lmd->lmd_dev);
+		kfree(lsi->lsi_lmd->lmd_profile);
+		kfree(lsi->lsi_lmd->lmd_mgssec);
+		kfree(lsi->lsi_lmd->lmd_opts);
 		if (lsi->lsi_lmd->lmd_exclude_count)
 			kfree(lsi->lsi_lmd->lmd_exclude);
-		if (lsi->lsi_lmd->lmd_mgs != NULL)
-			kfree(lsi->lsi_lmd->lmd_mgs);
-		if (lsi->lsi_lmd->lmd_osd_type != NULL)
-			kfree(lsi->lsi_lmd->lmd_osd_type);
-		if (lsi->lsi_lmd->lmd_params != NULL)
-			kfree(lsi->lsi_lmd->lmd_params);
+		kfree(lsi->lsi_lmd->lmd_mgs);
+		kfree(lsi->lsi_lmd->lmd_osd_type);
+		kfree(lsi->lsi_lmd->lmd_params);
 
 		kfree(lsi->lsi_lmd);
 	}
@@ -886,10 +875,8 @@ static int lmd_parse_mgssec(struct lustre_mount_data *lmd, char *ptr)
 	char   *tail;
 	int     length;
 
-	if (lmd->lmd_mgssec != NULL) {
-		kfree(lmd->lmd_mgssec);
-		lmd->lmd_mgssec = NULL;
-	}
+	kfree(lmd->lmd_mgssec);
+	lmd->lmd_mgssec = NULL;
 
 	tail = strchr(ptr, ',');
 	if (tail == NULL)
@@ -914,10 +901,8 @@ static int lmd_parse_string(char **handle, char *ptr)
 	if ((handle == NULL) || (ptr == NULL))
 		return -EINVAL;
 
-	if (*handle != NULL) {
-		kfree(*handle);
-		*handle = NULL;
-	}
+	kfree(*handle);
+	*handle = NULL;
 
 	tail = strchr(ptr, ',');
 	if (tail == NULL)


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

* [PATCH 14/20] staging: lustre: obdclass: obd_config: remove unneeded null test before free
  2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
                   ` (5 preceding siblings ...)
  2015-05-01 19:37 ` [PATCH 15/20] staging: lustre: obdclass: obd_mount: " Julia Lawall
@ 2015-05-01 19:37 ` Julia Lawall
  2015-05-01 19:37 ` [PATCH 13/20] staging: lustre: obdclass: llog: " Julia Lawall
                   ` (12 subsequent siblings)
  19 siblings, 0 replies; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:37 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel

Kfree can cope with a null argument, so drop null tests.

The semantic patch that identifies this issue is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL)
  kfree(ptr);
// </smpl>

The first part of the patch introduces new labels to avoid unnecessary
calls to kfree.  In addition, lprof->lp_md is always null in the cleanup
code at the end of the function, so that kfree is just dropped.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/staging/lustre/lustre/obdclass/obd_config.c |   24 ++++++++------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/lustre/lustre/obdclass/obd_config.c b/drivers/staging/lustre/lustre/obdclass/obd_config.c
index 687fbbd..0bda9c5 100644
--- a/drivers/staging/lustre/lustre/obdclass/obd_config.c
+++ b/drivers/staging/lustre/lustre/obdclass/obd_config.c
@@ -869,7 +869,7 @@ int class_add_profile(int proflen, char *prof, int osclen, char *osc,
 	lprof->lp_profile = kzalloc(proflen, GFP_NOFS);
 	if (lprof->lp_profile == NULL) {
 		err = -ENOMEM;
-		goto out;
+		goto free_lprof;
 	}
 	memcpy(lprof->lp_profile, prof, proflen);
 
@@ -877,7 +877,7 @@ int class_add_profile(int proflen, char *prof, int osclen, char *osc,
 	lprof->lp_dt = kzalloc(osclen, GFP_NOFS);
 	if (lprof->lp_dt == NULL) {
 		err = -ENOMEM;
-		goto out;
+		goto free_lp_profile;
 	}
 	memcpy(lprof->lp_dt, osc, osclen);
 
@@ -886,7 +886,7 @@ int class_add_profile(int proflen, char *prof, int osclen, char *osc,
 		lprof->lp_md = kzalloc(mdclen, GFP_NOFS);
 		if (lprof->lp_md == NULL) {
 			err = -ENOMEM;
-			goto out;
+			goto free_lp_dt;
 		}
 		memcpy(lprof->lp_md, mdc, mdclen);
 	}
@@ -894,13 +894,11 @@ int class_add_profile(int proflen, char *prof, int osclen, char *osc,
 	list_add(&lprof->lp_list, &lustre_profile_list);
 	return err;
 
-out:
-	if (lprof->lp_md)
-		kfree(lprof->lp_md);
-	if (lprof->lp_dt)
-		kfree(lprof->lp_dt);
-	if (lprof->lp_profile)
-		kfree(lprof->lp_profile);
+free_lp_dt:
+	kfree(lprof->lp_dt);
+free_lp_profile:
+	kfree(lprof->lp_profile);
+free_lprof:
 	kfree(lprof);
 	return err;
 }
@@ -916,8 +914,7 @@ void class_del_profile(const char *prof)
 		list_del(&lprof->lp_list);
 		kfree(lprof->lp_profile);
 		kfree(lprof->lp_dt);
-		if (lprof->lp_md)
-			kfree(lprof->lp_md);
+		kfree(lprof->lp_md);
 		kfree(lprof);
 	}
 }
@@ -932,8 +929,7 @@ void class_del_profiles(void)
 		list_del(&lprof->lp_list);
 		kfree(lprof->lp_profile);
 		kfree(lprof->lp_dt);
-		if (lprof->lp_md)
-			kfree(lprof->lp_md);
+		kfree(lprof->lp_md);
 		kfree(lprof);
 	}
 }


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

* [PATCH 13/20] staging: lustre: obdclass: llog: remove unneeded null test before free
  2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
                   ` (6 preceding siblings ...)
  2015-05-01 19:37 ` [PATCH 14/20] staging: lustre: obdclass: obd_config: " Julia Lawall
@ 2015-05-01 19:37 ` Julia Lawall
  2015-05-01 19:37 ` [PATCH 12/20] staging: lustre: obdclass: genops: " Julia Lawall
                   ` (11 subsequent siblings)
  19 siblings, 0 replies; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:37 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel

Kfree can cope with a null argument, so drop null tests.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL)
  kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/staging/lustre/lustre/obdclass/llog.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/lustre/lustre/obdclass/llog.c b/drivers/staging/lustre/lustre/obdclass/llog.c
index 636df94..4fa52d1 100644
--- a/drivers/staging/lustre/lustre/obdclass/llog.c
+++ b/drivers/staging/lustre/lustre/obdclass/llog.c
@@ -563,8 +563,7 @@ int llog_reverse_process(const struct lu_env *env,
 	}
 
 out:
-	if (buf)
-		kfree(buf);
+	kfree(buf);
 	return rc;
 }
 EXPORT_SYMBOL(llog_reverse_process);


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

* [PATCH 12/20] staging: lustre: obdclass: genops: remove unneeded null test before free
  2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
                   ` (7 preceding siblings ...)
  2015-05-01 19:37 ` [PATCH 13/20] staging: lustre: obdclass: llog: " Julia Lawall
@ 2015-05-01 19:37 ` Julia Lawall
  2015-05-01 19:37 ` [PATCH 11/20] staging: lustre: mdc: " Julia Lawall
                   ` (10 subsequent siblings)
  19 siblings, 0 replies; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:37 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel

Kfree can cope with a null argument, so drop null tests.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL)
  kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/staging/lustre/lustre/obdclass/genops.c |   15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/lustre/lustre/obdclass/genops.c b/drivers/staging/lustre/lustre/obdclass/genops.c
index a107aea..37d6aef 100644
--- a/drivers/staging/lustre/lustre/obdclass/genops.c
+++ b/drivers/staging/lustre/lustre/obdclass/genops.c
@@ -213,12 +213,9 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,
 	return 0;
 
  failed:
-	if (type->typ_name != NULL)
-		kfree(type->typ_name);
-	if (type->typ_md_ops != NULL)
-		kfree(type->typ_md_ops);
-	if (type->typ_dt_ops != NULL)
-		kfree(type->typ_dt_ops);
+	kfree(type->typ_name);
+	kfree(type->typ_md_ops);
+	kfree(type->typ_dt_ops);
 	kfree(type);
 	return rc;
 }
@@ -253,10 +250,8 @@ int class_unregister_type(const char *name)
 	list_del(&type->typ_chain);
 	spin_unlock(&obd_types_lock);
 	kfree(type->typ_name);
-	if (type->typ_dt_ops != NULL)
-		kfree(type->typ_dt_ops);
-	if (type->typ_md_ops != NULL)
-		kfree(type->typ_md_ops);
+	kfree(type->typ_dt_ops);
+	kfree(type->typ_md_ops);
 	kfree(type);
 	return 0;
 } /* class_unregister_type */


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

* [PATCH 11/20] staging: lustre: mdc: remove unneeded null test before free
  2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
                   ` (8 preceding siblings ...)
  2015-05-01 19:37 ` [PATCH 12/20] staging: lustre: obdclass: genops: " Julia Lawall
@ 2015-05-01 19:37 ` Julia Lawall
  2015-05-01 19:37 ` [PATCH 10/20] staging: lustre: lov: lov_dev: " Julia Lawall
                   ` (9 subsequent siblings)
  19 siblings, 0 replies; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:37 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel

Kfree can cope with a null argument, so drop null tests.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL)
  kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---

 drivers/staging/lustre/lustre/mdc/mdc_request.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/lustre/lustre/mdc/mdc_request.c b/drivers/staging/lustre/lustre/mdc/mdc_request.c
--- a/drivers/staging/lustre/lustre/mdc/mdc_request.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_request.c
@@ -1644,8 +1644,7 @@ out:
 		llog_cat_close(NULL, llh);
 	if (ctxt)
 		llog_ctxt_put(ctxt);
-	if (cs->cs_buf)
-		kfree(cs->cs_buf);
+	kfree(cs->cs_buf);
 	kfree(cs);
 	return rc;
 }

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

* [PATCH 10/20] staging: lustre: lov: lov_dev: remove unneeded null test before free
  2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
                   ` (9 preceding siblings ...)
  2015-05-01 19:37 ` [PATCH 11/20] staging: lustre: mdc: " Julia Lawall
@ 2015-05-01 19:37 ` Julia Lawall
  2015-05-01 19:37 ` [PATCH 9/20] staging: lustre: lmv: " Julia Lawall
                   ` (8 subsequent siblings)
  19 siblings, 0 replies; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:37 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel

Kfree can cope with a null argument, so drop null tests.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL)
  kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/staging/lustre/lustre/lov/lov_dev.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/lustre/lustre/lov/lov_dev.c b/drivers/staging/lustre/lustre/lov/lov_dev.c
index 63db87a..504b24a 100644
--- a/drivers/staging/lustre/lustre/lov/lov_dev.c
+++ b/drivers/staging/lustre/lustre/lov/lov_dev.c
@@ -298,8 +298,7 @@ static struct lu_device *lov_device_free(const struct lu_env *env,
 	const int	  nr = ld->ld_target_nr;
 
 	cl_device_fini(lu2cl_dev(d));
-	if (ld->ld_target != NULL)
-		kfree(ld->ld_target);
+	kfree(ld->ld_target);
 	if (ld->ld_emrg != NULL)
 		lov_emerg_free(ld->ld_emrg, nr);
 	kfree(ld);


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

* [PATCH 9/20] staging: lustre: lmv: remove unneeded null test before free
  2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
                   ` (10 preceding siblings ...)
  2015-05-01 19:37 ` [PATCH 10/20] staging: lustre: lov: lov_dev: " Julia Lawall
@ 2015-05-01 19:37 ` Julia Lawall
  2015-05-01 19:37 ` [PATCH 8/20] staging: lustre: llite: statahead: " Julia Lawall
                   ` (7 subsequent siblings)
  19 siblings, 0 replies; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:37 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel

Kfree can cope with a null argument, so drop null tests.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL)
  kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/staging/lustre/lustre/lmv/lmv_obd.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/lustre/lustre/lmv/lmv_obd.c b/drivers/staging/lustre/lustre/lmv/lmv_obd.c
index 59b8fac..8e05852 100644
--- a/drivers/staging/lustre/lustre/lmv/lmv_obd.c
+++ b/drivers/staging/lustre/lustre/lmv/lmv_obd.c
@@ -504,8 +504,7 @@ static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
 		lmv->tgts = newtgts;
 		lmv->tgts_size = newsize;
 		smp_rmb();
-		if (old)
-			kfree(old);
+		kfree(old);
 
 		CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
 		       lmv->tgts_size);
@@ -780,8 +779,7 @@ repeat_fid2path:
 	goto repeat_fid2path;
 
 out_fid2path:
-	if (remote_gf != NULL)
-		kfree(remote_gf);
+	kfree(remote_gf);
 	return rc;
 }
 


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

* [PATCH 8/20] staging: lustre: llite: statahead: remove unneeded null test before free
  2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
                   ` (11 preceding siblings ...)
  2015-05-01 19:37 ` [PATCH 9/20] staging: lustre: lmv: " Julia Lawall
@ 2015-05-01 19:37 ` Julia Lawall
  2015-05-01 19:38 ` [PATCH 7/20] Staging: lustre: llite: llite_lib: " Julia Lawall
                   ` (6 subsequent siblings)
  19 siblings, 0 replies; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:37 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel

Kfree can cope with a null argument, so drop null tests.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL)
  kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/staging/lustre/lustre/llite/statahead.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/lustre/lustre/llite/statahead.c b/drivers/staging/lustre/lustre/llite/statahead.c
index fdf953f..f97371d 100644
--- a/drivers/staging/lustre/lustre/llite/statahead.c
+++ b/drivers/staging/lustre/lustre/llite/statahead.c
@@ -1719,8 +1719,7 @@ int do_statahead_enter(struct inode *dir, struct dentry **dentryp,
 	return -EAGAIN;
 
 out:
-	if (sai != NULL)
-		kfree(sai);
+	kfree(sai);
 	spin_lock(&lli->lli_sa_lock);
 	lli->lli_opendir_key = NULL;
 	lli->lli_opendir_pid = 0;


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

* [PATCH 7/20] Staging: lustre: llite: llite_lib: remove unneeded null test before free
  2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
                   ` (12 preceding siblings ...)
  2015-05-01 19:37 ` [PATCH 8/20] staging: lustre: llite: statahead: " Julia Lawall
@ 2015-05-01 19:38 ` Julia Lawall
  2015-05-01 19:38 ` [PATCH 6/20] Staging: lustre: llite: file: " Julia Lawall
                   ` (5 subsequent siblings)
  19 siblings, 0 replies; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:38 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel

Kfree can cope with a null argument, so drop null tests.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL)
  kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/staging/lustre/lustre/llite/llite_lib.c |   12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c
index e5bac94..c6611b1 100644
--- a/drivers/staging/lustre/lustre/llite/llite_lib.c
+++ b/drivers/staging/lustre/lustre/llite/llite_lib.c
@@ -574,10 +574,8 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
 		get_uuid2fsid(uuid->uuid, strlen(uuid->uuid), &sbi->ll_fsid);
 	}
 
-	if (data != NULL)
-		kfree(data);
-	if (osfs != NULL)
-		kfree(osfs);
+	kfree(data);
+	kfree(osfs);
 
 	return err;
 out_root:
@@ -595,10 +593,8 @@ out_md:
 	obd_disconnect(sbi->ll_md_exp);
 	sbi->ll_md_exp = NULL;
 out:
-	if (data != NULL)
-		kfree(data);
-	if (osfs != NULL)
-		kfree(osfs);
+	kfree(data);
+	kfree(osfs);
 	lprocfs_unregister_mountpoint(sbi);
 	return err;
 }


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

* [PATCH 6/20] Staging: lustre: llite: file: remove unneeded null test before free
  2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
                   ` (13 preceding siblings ...)
  2015-05-01 19:38 ` [PATCH 7/20] Staging: lustre: llite: llite_lib: " Julia Lawall
@ 2015-05-01 19:38 ` Julia Lawall
  2015-05-01 19:38 ` [PATCH 5/20] Staging: lustre: llite: dir: " Julia Lawall
                   ` (4 subsequent siblings)
  19 siblings, 0 replies; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:38 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel

Kfree can cope with a null argument, so drop null tests.

The semantic patch that finds this issue is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL)
  kfree(ptr);
// </smpl>

In the first case, llss can never be null at the point of the kfree anyway.

In the second set of changes, the gotos are either eliminated, when no
freeing is needed (hss failure case), or rewritten so that there is no call
to free on data that has not yet been allocated (free_hss goto case).
There is no goto at which attr is not null, so the out label is simply
dropped.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/staging/lustre/lustre/llite/file.c |   23 ++++++++---------------
 1 file changed, 8 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/lustre/lustre/llite/file.c b/drivers/staging/lustre/lustre/llite/file.c
index 6e50b35..702f62d 100644
--- a/drivers/staging/lustre/lustre/llite/file.c
+++ b/drivers/staging/lustre/lustre/llite/file.c
@@ -2109,8 +2109,7 @@ putgl:
 	}
 
 free:
-	if (llss != NULL)
-		kfree(llss);
+	kfree(llss);
 
 	return rc;
 }
@@ -2152,22 +2151,20 @@ static int ll_hsm_import(struct inode *inode, struct file *file,
 
 	/* set HSM flags */
 	hss = kzalloc(sizeof(*hss), GFP_NOFS);
-	if (!hss) {
-		rc = -ENOMEM;
-		goto out;
-	}
+	if (!hss)
+		return -ENOMEM;
 
 	hss->hss_valid = HSS_SETMASK | HSS_ARCHIVE_ID;
 	hss->hss_archive_id = hui->hui_archive_id;
 	hss->hss_setmask = HS_ARCHIVED | HS_EXISTS | HS_RELEASED;
 	rc = ll_hsm_state_set(inode, hss);
 	if (rc != 0)
-		goto out;
+		goto free_hss;
 
 	attr = kzalloc(sizeof(*attr), GFP_NOFS);
 	if (!attr) {
 		rc = -ENOMEM;
-		goto out;
+		goto free_hss;
 	}
 
 	attr->ia_mode = hui->hui_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
@@ -2193,13 +2190,9 @@ static int ll_hsm_import(struct inode *inode, struct file *file,
 
 	mutex_unlock(&inode->i_mutex);
 
-out:
-	if (hss != NULL)
-		kfree(hss);
-
-	if (attr != NULL)
-		kfree(attr);
-
+	kfree(attr);
+free_hss:
+	kfree(hss);
 	return rc;
 }
 


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

* [PATCH 5/20] Staging: lustre: llite: dir: remove unneeded null test before free
  2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
                   ` (14 preceding siblings ...)
  2015-05-01 19:38 ` [PATCH 6/20] Staging: lustre: llite: file: " Julia Lawall
@ 2015-05-01 19:38 ` Julia Lawall
  2015-05-01 19:38 ` [PATCH 4/20] staging: lustre: libcfs: linux: " Julia Lawall
                   ` (3 subsequent siblings)
  19 siblings, 0 replies; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:38 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel

Kfree can cope with a null argument, so drop null tests.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL)
  kfree(ptr);
// </smpl>

This patch additionally simplifies one case where the free, and thus the
jump to the end of the function, is not needed.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/staging/lustre/lustre/llite/dir.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
index f17154a..4b0de8d 100644
--- a/drivers/staging/lustre/lustre/llite/dir.c
+++ b/drivers/staging/lustre/lustre/llite/dir.c
@@ -754,10 +754,8 @@ int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
 		char *buf;
 
 		param = kzalloc(MGS_PARAM_MAXLEN, GFP_NOFS);
-		if (!param) {
-			rc = -ENOMEM;
-			goto end;
-		}
+		if (!param)
+			return -ENOMEM;
 
 		buf = param;
 		/* Get fsname and assume devname to be -MDT0000. */
@@ -786,8 +784,7 @@ int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
 		rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
 
 end:
-		if (param != NULL)
-			kfree(param);
+		kfree(param);
 	}
 	return rc;
 }


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

* [PATCH 4/20] staging: lustre: libcfs: linux: remove unneeded null test before free
  2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
                   ` (15 preceding siblings ...)
  2015-05-01 19:38 ` [PATCH 5/20] Staging: lustre: llite: dir: " Julia Lawall
@ 2015-05-01 19:38 ` Julia Lawall
  2015-05-01 19:38 ` [PATCH 3/20] staging: lustre: ldlm: ldlm_resource: " Julia Lawall
                   ` (2 subsequent siblings)
  19 siblings, 0 replies; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:38 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel

Kfree can cope with a null argument, so drop null tests.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL) {
  kfree(ptr);
  ptr = NULL;
- }
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
index c8e2930..483cbc8 100644
--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
@@ -102,11 +102,10 @@ void cfs_tracefile_fini_arch(void)
 	int    j;
 
 	for (i = 0; i < num_possible_cpus(); i++)
-		for (j = 0; j < 3; j++)
-			if (cfs_trace_console_buffers[i][j] != NULL) {
-				kfree(cfs_trace_console_buffers[i][j]);
-				cfs_trace_console_buffers[i][j] = NULL;
-			}
+		for (j = 0; j < 3; j++) {
+			kfree(cfs_trace_console_buffers[i][j]);
+			cfs_trace_console_buffers[i][j] = NULL;
+		}
 
 	for (i = 0; cfs_trace_data[i] != NULL; i++) {
 		kfree(cfs_trace_data[i]);


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

* [PATCH 3/20] staging: lustre: ldlm: ldlm_resource: remove unneeded null test before free
  2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
                   ` (16 preceding siblings ...)
  2015-05-01 19:38 ` [PATCH 4/20] staging: lustre: libcfs: linux: " Julia Lawall
@ 2015-05-01 19:38 ` Julia Lawall
  2015-05-01 19:38 ` [PATCH 2/20] staging: lustre: ldlm: ldlm_lock: " Julia Lawall
  2015-05-01 19:38 ` [PATCH 1/20] staging: lustre: ldlm: ldlm_lib: " Julia Lawall
  19 siblings, 0 replies; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:38 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel

Kfree can cope with a null argument, so drop null tests.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL) {
  kfree(ptr);
  ptr = NULL;
- }
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/staging/lustre/lustre/ldlm/ldlm_resource.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
index 5922069..7149eda 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
@@ -1137,10 +1137,8 @@ ldlm_resource_get(struct ldlm_namespace *ns, struct ldlm_resource *parent,
 			CERROR("%s: lvbo_init failed for resource %#llx:%#llx: rc = %d\n",
 			       ns->ns_obd->obd_name, name->name[0],
 			       name->name[1], rc);
-			if (res->lr_lvb_data) {
-				kfree(res->lr_lvb_data);
-				res->lr_lvb_data = NULL;
-			}
+			kfree(res->lr_lvb_data);
+			res->lr_lvb_data = NULL;
 			res->lr_lvb_len = rc;
 			mutex_unlock(&res->lr_lvb_mutex);
 			ldlm_resource_putref(res);


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

* [PATCH 2/20] staging: lustre: ldlm: ldlm_lock: remove unneeded null test before free
  2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
                   ` (17 preceding siblings ...)
  2015-05-01 19:38 ` [PATCH 3/20] staging: lustre: ldlm: ldlm_resource: " Julia Lawall
@ 2015-05-01 19:38 ` Julia Lawall
  2015-05-01 19:38 ` [PATCH 1/20] staging: lustre: ldlm: ldlm_lib: " Julia Lawall
  19 siblings, 0 replies; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:38 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel

Kfree can cope with a null argument, so drop null tests.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL)
  kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/staging/lustre/lustre/ldlm/ldlm_lock.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
index 2c5fe14..6a22f41 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
@@ -208,8 +208,7 @@ void ldlm_lock_put(struct ldlm_lock *lock)
 			lock->l_export = NULL;
 		}
 
-		if (lock->l_lvb_data != NULL)
-			kfree(lock->l_lvb_data);
+		kfree(lock->l_lvb_data);
 
 		ldlm_interval_free(ldlm_interval_detach(lock));
 		lu_ref_fini(&lock->l_reference);


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

* [PATCH 1/20] staging: lustre: ldlm: ldlm_lib: remove unneeded null test before free
  2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
                   ` (18 preceding siblings ...)
  2015-05-01 19:38 ` [PATCH 2/20] staging: lustre: ldlm: ldlm_lock: " Julia Lawall
@ 2015-05-01 19:38 ` Julia Lawall
  2015-05-02 20:55   ` Dan Carpenter
  19 siblings, 1 reply; 23+ messages in thread
From: Julia Lawall @ 2015-05-01 19:38 UTC (permalink / raw)
  To: Oleg Drokin
  Cc: kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel

Kfree can cope with a null argument, so drop null tests.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@ expression ptr; @@

- if (ptr != NULL)
  kfree(ptr);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/staging/lustre/lustre/ldlm/ldlm_lib.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c
index d066771..0a0b435 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c
@@ -119,8 +119,7 @@ static int import_set_conn(struct obd_import *imp, struct obd_uuid *uuid,
 	spin_unlock(&imp->imp_lock);
 	return 0;
 out_free:
-	if (imp_conn)
-		kfree(imp_conn);
+	kfree(imp_conn);
 out_put:
 	ptlrpc_connection_put(ptlrpc_conn);
 	return rc;


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

* Re: [PATCH 19/20] staging: lustre: ptlrpc: sec_plain: remove unneeded null test before free
  2015-05-01 19:37 ` [PATCH 19/20] staging: lustre: ptlrpc: sec_plain: " Julia Lawall
@ 2015-05-02  9:14   ` walter harms
  0 siblings, 0 replies; 23+ messages in thread
From: walter harms @ 2015-05-02  9:14 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Oleg Drokin, kernel-janitors, Andreas Dilger, Greg Kroah-Hartman,
	HPDD-discuss, devel, linux-kernel



Am 01.05.2015 21:37, schrieb Julia Lawall:
> Kfree can cope with a null argument, so drop null tests.
> 
> The semantic patch that makes this change is as follows:
> (http://coccinelle.lip6.fr/)
> 
> // <smpl>
> @@ expression ptr; @@
> 
> - if (ptr != NULL)
>   kfree(ptr);
> // </smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> ---
>  drivers/staging/lustre/lustre/ptlrpc/sec_plain.c |    3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c b/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c
> index 604e511..989cdcd 100644
> --- a/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c
> +++ b/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c
> @@ -384,8 +384,7 @@ struct ptlrpc_cli_ctx *plain_sec_install_ctx(struct plain_sec *plsec)
>  	if (ctx) {
>  		atomic_inc(&ctx->cc_refcount);
>  
> -		if (ctx_new)
> -			kfree(ctx_new);
> +		kfree(ctx_new);
>  	} else if (ctx_new) {
>  		ctx = ctx_new;
>  

The error handling here is not obvious
the
OBD_ALLOC_PTR(ctx_new);
should have something like
if (!ctx_new)
	return NULL;


just my 2 cents
re,
 wh

> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

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

* Re: [PATCH 1/20] staging: lustre: ldlm: ldlm_lib: remove unneeded null test before free
  2015-05-01 19:38 ` [PATCH 1/20] staging: lustre: ldlm: ldlm_lib: " Julia Lawall
@ 2015-05-02 20:55   ` Dan Carpenter
  0 siblings, 0 replies; 23+ messages in thread
From: Dan Carpenter @ 2015-05-02 20:55 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Oleg Drokin, devel, Andreas Dilger, Greg Kroah-Hartman,
	kernel-janitors, linux-kernel, HPDD-discuss

Somehow git is threading them in the reverse order.  The last thread as
well.

regards,
dan carpenter


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

end of thread, other threads:[~2015-05-02 20:55 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-01 19:37 [PATCH 0/20] remove unneeded null test before free Julia Lawall
2015-05-01 19:37 ` [PATCH 20/20] staging: lustre: ptlrpc: service: " Julia Lawall
2015-05-01 19:37 ` [PATCH 19/20] staging: lustre: ptlrpc: sec_plain: " Julia Lawall
2015-05-02  9:14   ` walter harms
2015-05-01 19:37 ` [PATCH 18/20] Staging: lustre: ptlrpc: lproc_ptlrpc: " Julia Lawall
2015-05-01 19:37 ` [PATCH 17/20] Staging: lustre: osc: " Julia Lawall
2015-05-01 19:37 ` [PATCH 16/20] staging: lustre: obdecho: " Julia Lawall
2015-05-01 19:37 ` [PATCH 15/20] staging: lustre: obdclass: obd_mount: " Julia Lawall
2015-05-01 19:37 ` [PATCH 14/20] staging: lustre: obdclass: obd_config: " Julia Lawall
2015-05-01 19:37 ` [PATCH 13/20] staging: lustre: obdclass: llog: " Julia Lawall
2015-05-01 19:37 ` [PATCH 12/20] staging: lustre: obdclass: genops: " Julia Lawall
2015-05-01 19:37 ` [PATCH 11/20] staging: lustre: mdc: " Julia Lawall
2015-05-01 19:37 ` [PATCH 10/20] staging: lustre: lov: lov_dev: " Julia Lawall
2015-05-01 19:37 ` [PATCH 9/20] staging: lustre: lmv: " Julia Lawall
2015-05-01 19:37 ` [PATCH 8/20] staging: lustre: llite: statahead: " Julia Lawall
2015-05-01 19:38 ` [PATCH 7/20] Staging: lustre: llite: llite_lib: " Julia Lawall
2015-05-01 19:38 ` [PATCH 6/20] Staging: lustre: llite: file: " Julia Lawall
2015-05-01 19:38 ` [PATCH 5/20] Staging: lustre: llite: dir: " Julia Lawall
2015-05-01 19:38 ` [PATCH 4/20] staging: lustre: libcfs: linux: " Julia Lawall
2015-05-01 19:38 ` [PATCH 3/20] staging: lustre: ldlm: ldlm_resource: " Julia Lawall
2015-05-01 19:38 ` [PATCH 2/20] staging: lustre: ldlm: ldlm_lock: " Julia Lawall
2015-05-01 19:38 ` [PATCH 1/20] staging: lustre: ldlm: ldlm_lib: " Julia Lawall
2015-05-02 20:55   ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).