linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Julia Lawall <Julia.Lawall@lip6.fr>
To: Oleg Drokin <oleg.drokin@intel.com>
Cc: kernel-janitors@vger.kernel.org,
	Andreas Dilger <andreas.dilger@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	HPDD-discuss@ml01.01.org, devel@driverdev.osuosl.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 6/20] Staging: lustre: llite: file: remove unneeded null test before free
Date: Fri,  1 May 2015 21:38:01 +0200	[thread overview]
Message-ID: <1430509086-22132-16-git-send-email-Julia.Lawall@lip6.fr> (raw)
In-Reply-To: <1430509086-22132-1-git-send-email-Julia.Lawall@lip6.fr>

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;
 }
 


  parent reply	other threads:[~2015-05-01 19:48 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Julia Lawall [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1430509086-22132-16-git-send-email-Julia.Lawall@lip6.fr \
    --to=julia.lawall@lip6.fr \
    --cc=HPDD-discuss@ml01.01.org \
    --cc=andreas.dilger@intel.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg.drokin@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).