Linux-CIFS Archive on lore.kernel.org
 help / color / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: linux-cifs@vger.kernel.org, samba-technical@lists.samba.org,
	Steve French <sfrench@samba.org>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 5/8] CIFS: Less function calls in cifs_mknod() after error detection
Date: Sun, 20 Aug 2017 18:39:11 +0200
Message-ID: <ad73c46d-a1a3-3ae3-7263-1e8812303809@users.sourceforge.net> (raw)
In-Reply-To: <826310e5-e01c-38af-90df-c5630f761a4d@users.sourceforge.net>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 20 Aug 2017 16:56:18 +0200

The kfree() function was called in a few cases by the
cifs_mknod() function during error handling even if
the passed variable contained a null pointer.

* Adjust jump targets according to the Linux coding style convention.

* Delete an initialisation for the variables "buf" and "full_path"
  which became unnecessary with this refactoring.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 fs/cifs/dir.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index 41039ab12643..2c9cbd8393d6 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -620,12 +620,12 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
 	struct tcon_link *tlink;
 	struct cifs_tcon *tcon;
 	struct cifs_io_parms io_parms;
-	char *full_path = NULL;
+	char *full_path;
 	struct inode *newinode = NULL;
 	__u32 oplock = 0;
 	struct cifs_fid fid;
 	struct cifs_open_parms oparms;
-	FILE_ALL_INFO *buf = NULL;
+	FILE_ALL_INFO *buf;
 	unsigned int bytes_written;
 	struct win_dev *pdev;
 	struct kvec iov[2];
@@ -645,7 +645,7 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
 	full_path = build_path_from_dentry(direntry);
 	if (full_path == NULL) {
 		rc = -ENOMEM;
-		goto mknod_out;
+		goto put_link;
 	}
 
 	if (tcon->unix_ext) {
@@ -667,18 +667,18 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
 					    cifs_sb->local_nls,
 					    cifs_remap(cifs_sb));
 		if (rc)
-			goto mknod_out;
+			goto free_path;
 
 		rc = cifs_get_inode_info_unix(&newinode, full_path,
 						inode->i_sb, xid);
 
 		if (rc == 0)
 			d_instantiate(direntry, newinode);
-		goto mknod_out;
+		goto free_path;
 	}
 
 	if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
-		goto mknod_out;
+		goto free_path;
 
 
 	cifs_dbg(FYI, "sfu compat create special file\n");
@@ -708,7 +708,7 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
 		oplock = 0;
 	rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf);
 	if (rc)
-		goto mknod_out;
+		goto free_buffer;
 
 	/*
 	 * BB Do not bother to decode buf since no local inode yet to put
@@ -740,9 +740,11 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
 
 	/* FIXME: add code here to set EAs */
 
-mknod_out:
-	kfree(full_path);
+free_buffer:
 	kfree(buf);
+free_path:
+	kfree(full_path);
+put_link:
 	cifs_put_tlink(tlink);
 free_id:
 	free_xid(xid);
-- 
2.14.0

  parent reply index

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-20 16:32 [PATCH 0/8] CIFS: Adjustments for several function implementations SF Markus Elfring
2017-08-20 16:33 ` [PATCH 1/8] CIFS: Delete 11 error messages for a failed memory allocation SF Markus Elfring
2017-08-20 16:38 ` [PATCH 4/8] CIFS: Use common error handling code in cifs_mknod() SF Markus Elfring
2017-08-20 16:39 ` SF Markus Elfring [this message]
     [not found] ` <826310e5-e01c-38af-90df-c5630f761a4d-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2017-08-20 16:35   ` [PATCH 2/8] CIFS: Improve 27 size determinations SF Markus Elfring
2017-08-20 16:36   ` [PATCH 3/8] CIFS: One function call less in cifs_lookup() after error detection SF Markus Elfring
2017-08-20 16:40   ` [PATCH 6/8] CIFS: Return directly after a failed build_path_from_dentry() in cifs_do_create() SF Markus Elfring
2019-11-07  3:34     ` Steve French
2017-08-20 16:41 ` [PATCH 7/8] CIFS: Delete an unnecessary variable initialisation " SF Markus Elfring
2017-08-20 16:42 ` [PATCH 8/8] CIFS: One function call less in cifs_do_create() after error detection SF Markus Elfring

Reply instructions:

You may reply publically 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=ad73c46d-a1a3-3ae3-7263-1e8812303809@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=samba-technical@lists.samba.org \
    --cc=sfrench@samba.org \
    /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

Linux-CIFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-cifs/0 linux-cifs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-cifs linux-cifs/ https://lore.kernel.org/linux-cifs \
		linux-cifs@vger.kernel.org
	public-inbox-index linux-cifs

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-cifs


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git