linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] CIFS: Adjustments for several function implementations
@ 2017-08-20 16:32 SF Markus Elfring
  2017-08-20 16:33 ` [PATCH 1/8] CIFS: Delete 11 error messages for a failed memory allocation SF Markus Elfring
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: SF Markus Elfring @ 2017-08-20 16:32 UTC (permalink / raw)
  To: linux-cifs-u79uwXL29TY76Z2rM5mHXA,
	samba-technical-w/Ol4Ecudpl8XjKLYN78aQ, Steve French
  Cc: LKML, kernel-janitors-u79uwXL29TY76Z2rM5mHXA

From: Markus Elfring <elfring-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Date: Sun, 20 Aug 2017 18:24:56 +0200

Some update suggestions were taken into account
from static source code analysis.

Markus Elfring (8):
  Delete 11 error messages for a failed memory allocation
  Improve 27 size determinations
  One function call less in cifs_lookup() after error detection
  Use common error handling code in cifs_mknod()
  Less function calls in cifs_mknod() after error detection
  Return directly after a failed build_path_from_dentry() in cifs_do_create()
  Delete an unnecessary variable initialisation in cifs_do_create()
  One function call less in cifs_do_create() after error detection

 fs/cifs/cifsacl.c       |  8 +++----
 fs/cifs/cifsfs.c        |  2 +-
 fs/cifs/cifssmb.c       |  4 +---
 fs/cifs/connect.c       | 17 ++++-----------
 fs/cifs/dir.c           | 55 +++++++++++++++++++++++++------------------------
 fs/cifs/ioctl.c         |  2 +-
 fs/cifs/readdir.c       |  2 +-
 fs/cifs/sess.c          |  9 +++-----
 fs/cifs/smb1ops.c       |  2 +-
 fs/cifs/smb2file.c      |  4 ++--
 fs/cifs/smb2misc.c      |  2 +-
 fs/cifs/smb2ops.c       | 21 ++++++++-----------
 fs/cifs/smb2pdu.c       | 17 +++++----------
 fs/cifs/smb2transport.c |  1 -
 14 files changed, 61 insertions(+), 85 deletions(-)

-- 
2.14.0

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

* [PATCH 1/8] CIFS: Delete 11 error messages for a failed memory allocation
  2017-08-20 16:32 [PATCH 0/8] CIFS: Adjustments for several function implementations SF Markus Elfring
@ 2017-08-20 16:33 ` SF Markus Elfring
  2017-08-20 16:38 ` [PATCH 4/8] CIFS: Use common error handling code in cifs_mknod() SF Markus Elfring
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: SF Markus Elfring @ 2017-08-20 16:33 UTC (permalink / raw)
  To: linux-cifs, samba-technical, Steve French; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 20 Aug 2017 14:35:36 +0200

Omit extra messages for a memory allocation failure in these functions.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 fs/cifs/connect.c       | 17 ++++-------------
 fs/cifs/sess.c          |  7 ++-----
 fs/cifs/smb2ops.c       |  1 -
 fs/cifs/smb2pdu.c       |  6 ------
 fs/cifs/smb2transport.c |  1 -
 5 files changed, 6 insertions(+), 26 deletions(-)

diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 59647eb72c5f..b67a3c132a8f 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -1737,10 +1737,8 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
 			/* Now build new password string */
 			temp_len = strlen(value);
 			vol->password = kzalloc(temp_len+1, GFP_KERNEL);
-			if (vol->password == NULL) {
-				pr_warn("CIFS: no memory for password\n");
+			if (!vol->password)
 				goto cifs_parse_mount_err;
-			}
 
 			for (i = 0, j = 0; i < temp_len; i++, j++) {
 				vol->password[j] = value[i];
@@ -1780,10 +1778,9 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
 
 			kfree(vol->domainname);
 			vol->domainname = kstrdup(string, GFP_KERNEL);
-			if (!vol->domainname) {
-				pr_warn("CIFS: no memory for domainname\n");
+			if (!vol->domainname)
 				goto cifs_parse_mount_err;
-			}
+
 			cifs_dbg(FYI, "Domain name set\n");
 			break;
 		case Opt_srcaddr:
@@ -1813,10 +1810,8 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
 				kfree(vol->iocharset);
 				vol->iocharset = kstrdup(string,
 							 GFP_KERNEL);
-				if (!vol->iocharset) {
-					pr_warn("CIFS: no memory for charset\n");
+				if (!vol->iocharset)
 					goto cifs_parse_mount_err;
-				}
 			}
 			/* if iocharset not set then load_nls_default
 			 * is used by caller
@@ -2494,8 +2489,6 @@ cifs_set_cifscreds(struct smb_vol *vol, struct cifs_ses *ses)
 
 	vol->username = kstrndup(payload, len, GFP_KERNEL);
 	if (!vol->username) {
-		cifs_dbg(FYI, "Unable to allocate %zd bytes for username\n",
-			 len);
 		rc = -ENOMEM;
 		goto out_key_put;
 	}
@@ -2513,8 +2506,6 @@ cifs_set_cifscreds(struct smb_vol *vol, struct cifs_ses *ses)
 	++delim;
 	vol->password = kstrndup(delim, len, GFP_KERNEL);
 	if (!vol->password) {
-		cifs_dbg(FYI, "Unable to allocate %zd bytes for password\n",
-			 len);
 		rc = -ENOMEM;
 		kfree(vol->username);
 		vol->username = NULL;
diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c
index 8b0502cd39af..2fb36bbaf5b0 100644
--- a/fs/cifs/sess.c
+++ b/fs/cifs/sess.c
@@ -317,10 +317,9 @@ int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
 	if (tilen) {
 		ses->auth_key.response = kmemdup(bcc_ptr + tioffset, tilen,
 						 GFP_KERNEL);
-		if (!ses->auth_key.response) {
-			cifs_dbg(VFS, "Challenge target info alloc failure");
+		if (!ses->auth_key.response)
 			return -ENOMEM;
-		}
+
 		ses->auth_key.len = tilen;
 	}
 
@@ -1048,8 +1047,6 @@ sess_auth_kerberos(struct sess_data *sess_data)
 	ses->auth_key.response = kmemdup(msg->data, msg->sesskey_len,
 					 GFP_KERNEL);
 	if (!ses->auth_key.response) {
-		cifs_dbg(VFS, "Kerberos can't allocate (%u bytes) memory",
-				msg->sesskey_len);
 		rc = -ENOMEM;
 		goto out_put_spnego_key;
 	}
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index cfacf2c97e94..783b5d263704 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -1988,7 +1988,6 @@ crypt_message(struct TCP_Server_Info *server, struct smb_rqst *rqst, int enc)
 	iv_len = crypto_aead_ivsize(tfm);
 	iv = kzalloc(iv_len, GFP_KERNEL);
 	if (!iv) {
-		cifs_dbg(VFS, "%s: Failed to alloc IV", __func__);
 		rc = -ENOMEM;
 		goto free_sg;
 	}
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 5fb2fc2d0080..668732e6f80f 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -851,9 +851,6 @@ SMB2_auth_kerberos(struct SMB2_sess_data *sess_data)
 	ses->auth_key.response = kmemdup(msg->data, msg->sesskey_len,
 					 GFP_KERNEL);
 	if (!ses->auth_key.response) {
-		cifs_dbg(VFS,
-			"Kerberos can't allocate (%u bytes) memory",
-			msg->sesskey_len);
 		rc = -ENOMEM;
 		goto out_put_spnego_key;
 	}
@@ -2122,9 +2119,6 @@ query_info(const unsigned int xid, struct cifs_tcon *tcon,
 		if (!*data) {
 			*data = kmalloc(*dlen, GFP_KERNEL);
 			if (!*data) {
-				cifs_dbg(VFS,
-					"Error %d allocating memory for acl\n",
-					rc);
 				*dlen = 0;
 				goto qinf_exit;
 			}
diff --git a/fs/cifs/smb2transport.c b/fs/cifs/smb2transport.c
index 67367cf1f8cd..abfcc759e75d 100644
--- a/fs/cifs/smb2transport.c
+++ b/fs/cifs/smb2transport.c
@@ -100,7 +100,6 @@ smb3_crypto_shash_allocate(struct TCP_Server_Info *server)
 			crypto_shash_descsize(server->secmech.cmacaes);
 	server->secmech.sdesccmacaes = kmalloc(size, GFP_KERNEL);
 	if (!server->secmech.sdesccmacaes) {
-		cifs_dbg(VFS, "%s: Can't alloc cmacaes\n", __func__);
 		kfree(server->secmech.sdeschmacsha256);
 		server->secmech.sdeschmacsha256 = NULL;
 		crypto_free_shash(server->secmech.hmacsha256);
-- 
2.14.0

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

* [PATCH 2/8] CIFS: Improve 27 size determinations
       [not found] ` <826310e5-e01c-38af-90df-c5630f761a4d-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
@ 2017-08-20 16:35   ` 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
  2 siblings, 0 replies; 10+ messages in thread
From: SF Markus Elfring @ 2017-08-20 16:35 UTC (permalink / raw)
  To: linux-cifs-u79uwXL29TY76Z2rM5mHXA,
	samba-technical-w/Ol4Ecudpl8XjKLYN78aQ, Steve French
  Cc: LKML, kernel-janitors-u79uwXL29TY76Z2rM5mHXA

From: Markus Elfring <elfring-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Date: Sun, 20 Aug 2017 15:40:55 +0200

Replace the specification of data structures by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
---
 fs/cifs/cifsacl.c  |  8 ++++----
 fs/cifs/cifsfs.c   |  2 +-
 fs/cifs/cifssmb.c  |  4 +---
 fs/cifs/dir.c      |  4 ++--
 fs/cifs/ioctl.c    |  2 +-
 fs/cifs/readdir.c  |  2 +-
 fs/cifs/sess.c     |  2 +-
 fs/cifs/smb1ops.c  |  2 +-
 fs/cifs/smb2file.c |  4 ++--
 fs/cifs/smb2misc.c |  2 +-
 fs/cifs/smb2ops.c  | 20 +++++++++-----------
 fs/cifs/smb2pdu.c  | 11 +++++------
 12 files changed, 29 insertions(+), 34 deletions(-)

diff --git a/fs/cifs/cifsacl.c b/fs/cifs/cifsacl.c
index b98436f5c7c7..e92a2e70fdea 100644
--- a/fs/cifs/cifsacl.c
+++ b/fs/cifs/cifsacl.c
@@ -945,8 +945,8 @@ static int build_sec_desc(struct cifs_ntsd *pntsd, struct cifs_ntsd *pnntsd,
 			uid_t id;
 			owner_sid_ptr = (struct cifs_sid *)((char *)pnntsd +
 					le32_to_cpu(pnntsd->osidoffset));
-			nowner_sid_ptr = kmalloc(sizeof(struct cifs_sid),
-								GFP_KERNEL);
+			nowner_sid_ptr = kmalloc(sizeof(*nowner_sid_ptr),
+						 GFP_KERNEL);
 			if (!nowner_sid_ptr)
 				return -ENOMEM;
 			id = from_kuid(&init_user_ns, uid);
@@ -965,8 +965,8 @@ static int build_sec_desc(struct cifs_ntsd *pntsd, struct cifs_ntsd *pnntsd,
 			gid_t id;
 			group_sid_ptr = (struct cifs_sid *)((char *)pnntsd +
 					le32_to_cpu(pnntsd->gsidoffset));
-			ngroup_sid_ptr = kmalloc(sizeof(struct cifs_sid),
-								GFP_KERNEL);
+			ngroup_sid_ptr = kmalloc(sizeof(*ngroup_sid_ptr),
+						 GFP_KERNEL);
 			if (!ngroup_sid_ptr)
 				return -ENOMEM;
 			id = from_kgid(&init_user_ns, gid);
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index 180b3356ff86..b5694ac68ef5 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -686,7 +686,7 @@ cifs_do_mount(struct file_system_type *fs_type,
 	if (IS_ERR(volume_info))
 		return ERR_CAST(volume_info);
 
-	cifs_sb = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL);
+	cifs_sb = kzalloc(sizeof(*cifs_sb), GFP_KERNEL);
 	if (cifs_sb == NULL) {
 		root = ERR_PTR(-ENOMEM);
 		goto out_nls;
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 118a63e7e221..8c61a1fd2bf8 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -6432,9 +6432,7 @@ int CIFSSMBNotify(const unsigned int xid, struct cifs_tcon *tcon,
 	} else {
 		/* Add file to outstanding requests */
 		/* BB change to kmem cache alloc */
-		dnotify_req = kmalloc(
-						sizeof(struct dir_notify_req),
-						 GFP_KERNEL);
+		dnotify_req = kmalloc(sizeof(*dnotify_req), GFP_KERNEL);
 		if (dnotify_req) {
 			dnotify_req->Pid = pSMB->hdr.Pid;
 			dnotify_req->PidHigh = pSMB->hdr.PidHigh;
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index 56366e984076..7dd7ca1afe0b 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -339,7 +339,7 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
 		goto out;
 	}
 
-	buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
+	buf = kmalloc(sizeof(*buf), GFP_KERNEL);
 	if (buf == NULL) {
 		rc = -ENOMEM;
 		goto out;
@@ -683,7 +683,7 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
 
 	cifs_dbg(FYI, "sfu compat create special file\n");
 
-	buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
+	buf = kmalloc(sizeof(*buf), GFP_KERNEL);
 	if (buf == NULL) {
 		kfree(full_path);
 		rc = -ENOMEM;
diff --git a/fs/cifs/ioctl.c b/fs/cifs/ioctl.c
index 54f32f9143a9..140c49c128b3 100644
--- a/fs/cifs/ioctl.c
+++ b/fs/cifs/ioctl.c
@@ -89,7 +89,7 @@ static long smb_mnt_get_fsinfo(unsigned int xid, struct cifs_tcon *tcon,
 	int rc = 0;
 	struct smb_mnt_fs_info *fsinf;
 
-	fsinf = kzalloc(sizeof(struct smb_mnt_fs_info), GFP_KERNEL);
+	fsinf = kzalloc(sizeof(*fsinf), GFP_KERNEL);
 	if (fsinf == NULL)
 		return -ENOMEM;
 
diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
index a27fc8791551..a3cfb2e1cfcd 100644
--- a/fs/cifs/readdir.c
+++ b/fs/cifs/readdir.c
@@ -280,7 +280,7 @@ initiate_cifs_search(const unsigned int xid, struct file *file)
 		if (IS_ERR(tlink))
 			return PTR_ERR(tlink);
 
-		cifsFile = kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL);
+		cifsFile = kzalloc(sizeof(*cifsFile), GFP_KERNEL);
 		if (cifsFile == NULL) {
 			rc = -ENOMEM;
 			goto error_exit;
diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c
index 2fb36bbaf5b0..382f868279f6 100644
--- a/fs/cifs/sess.c
+++ b/fs/cifs/sess.c
@@ -1446,7 +1446,7 @@ int CIFS_SessSetup(const unsigned int xid, struct cifs_ses *ses,
 		return -EINVAL;
 	}
 
-	sess_data = kzalloc(sizeof(struct sess_data), GFP_KERNEL);
+	sess_data = kzalloc(sizeof(*sess_data), GFP_KERNEL);
 	if (!sess_data)
 		return -ENOMEM;
 
diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
index a723df3e0197..aad345a91ac9 100644
--- a/fs/cifs/smb1ops.c
+++ b/fs/cifs/smb1ops.c
@@ -525,7 +525,7 @@ cifs_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
 	int rc;
 	FILE_ALL_INFO *file_info;
 
-	file_info = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
+	file_info = kmalloc(sizeof(*file_info), GFP_KERNEL);
 	if (file_info == NULL)
 		return -ENOMEM;
 
diff --git a/fs/cifs/smb2file.c b/fs/cifs/smb2file.c
index b4b1f0305f29..21bff61cf818 100644
--- a/fs/cifs/smb2file.c
+++ b/fs/cifs/smb2file.c
@@ -131,7 +131,7 @@ smb2_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
 		return -EINVAL;
 
 	max_num = max_buf / sizeof(struct smb2_lock_element);
-	buf = kcalloc(max_num, sizeof(struct smb2_lock_element), GFP_KERNEL);
+	buf = kcalloc(max_num, sizeof(*buf), GFP_KERNEL);
 	if (!buf)
 		return -ENOMEM;
 
@@ -267,7 +267,7 @@ smb2_push_mandatory_locks(struct cifsFileInfo *cfile)
 	}
 
 	max_num = max_buf / sizeof(struct smb2_lock_element);
-	buf = kcalloc(max_num, sizeof(struct smb2_lock_element), GFP_KERNEL);
+	buf = kcalloc(max_num, sizeof(*buf), GFP_KERNEL);
 	if (!buf) {
 		free_xid(xid);
 		return -ENOMEM;
diff --git a/fs/cifs/smb2misc.c b/fs/cifs/smb2misc.c
index 7b08a1446a7f..6f0997a25ea8 100644
--- a/fs/cifs/smb2misc.c
+++ b/fs/cifs/smb2misc.c
@@ -537,7 +537,7 @@ smb2_is_valid_lease_break(char *buffer)
 	struct cifs_tcon *tcon;
 	struct smb2_lease_break_work *lw;
 
-	lw = kmalloc(sizeof(struct smb2_lease_break_work), GFP_KERNEL);
+	lw = kmalloc(sizeof(*lw), GFP_KERNEL);
 	if (!lw)
 		return false;
 
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index 783b5d263704..fc3e598ac1c6 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -608,8 +608,7 @@ smb2_copychunk_range(const unsigned int xid,
 	bool chunk_sizes_updated = false;
 	ssize_t bytes_written, total_bytes_written = 0;
 
-	pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
-
+	pcchunk = kmalloc(sizeof(*pcchunk), GFP_KERNEL);
 	if (pcchunk == NULL)
 		return -ENOMEM;
 
@@ -1750,7 +1749,7 @@ smb2_create_lease_buf(u8 *lease_key, u8 oplock)
 {
 	struct create_lease *buf;
 
-	buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
+	buf = kzalloc(sizeof(*buf), GFP_KERNEL);
 	if (!buf)
 		return NULL;
 
@@ -1777,7 +1776,7 @@ smb3_create_lease_buf(u8 *lease_key, u8 oplock)
 {
 	struct create_lease_v2 *buf;
 
-	buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
+	buf = kzalloc(sizeof(*buf), GFP_KERNEL);
 	if (!buf)
 		return NULL;
 
@@ -1860,7 +1859,7 @@ init_sg(struct smb_rqst *rqst, u8 *sign)
 	unsigned int i;
 	unsigned int j;
 
-	sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
+	sg = kmalloc_array(sg_len, sizeof(*sg), GFP_KERNEL);
 	if (!sg)
 		return NULL;
 
@@ -2029,7 +2028,7 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq,
 	int i;
 	int rc = -ENOMEM;
 
-	pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
+	pages = kmalloc_array(npages, sizeof(*pages), GFP_KERNEL);
 	if (!pages)
 		return rc;
 
@@ -2044,7 +2043,7 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq,
 			goto err_free_pages;
 	}
 
-	iov = kmalloc_array(old_rq->rq_nvec, sizeof(struct kvec), GFP_KERNEL);
+	iov = kmalloc_array(old_rq->rq_nvec, sizeof(*iov), GFP_KERNEL);
 	if (!iov)
 		goto err_free_pages;
 
@@ -2054,7 +2053,7 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq,
 	new_rq->rq_iov = iov;
 	new_rq->rq_nvec = old_rq->rq_nvec;
 
-	tr_hdr = kmalloc(sizeof(struct smb2_transform_hdr), GFP_KERNEL);
+	tr_hdr = kmalloc(sizeof(*tr_hdr), GFP_KERNEL);
 	if (!tr_hdr)
 		goto err_free_iov;
 
@@ -2185,7 +2184,7 @@ init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
 	struct bio_vec *bvec;
 	int i;
 
-	bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
+	bvec = kcalloc(npages, sizeof(*bvec), GFP_KERNEL);
 	if (!bvec)
 		return -ENOMEM;
 
@@ -2355,8 +2354,7 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid)
 	len = le32_to_cpu(tr_hdr->OriginalMessageSize) + 4 -
 						server->vals->read_rsp_size;
 	npages = DIV_ROUND_UP(len, PAGE_SIZE);
-
-	pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
+	pages = kmalloc_array(npages, sizeof(*pages), GFP_KERNEL);
 	if (!pages) {
 		rc = -ENOMEM;
 		goto discard_data;
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 668732e6f80f..328fefeaf924 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -1075,7 +1075,7 @@ SMB2_sess_setup(const unsigned int xid, struct cifs_ses *ses,
 		return -EIO;
 	}
 
-	sess_data = kzalloc(sizeof(struct SMB2_sess_data), GFP_KERNEL);
+	sess_data = kzalloc(sizeof(*sess_data), GFP_KERNEL);
 	if (!sess_data)
 		return -ENOMEM;
 
@@ -1320,7 +1320,7 @@ create_durable_buf(void)
 {
 	struct create_durable *buf;
 
-	buf = kzalloc(sizeof(struct create_durable), GFP_KERNEL);
+	buf = kzalloc(sizeof(*buf), GFP_KERNEL);
 	if (!buf)
 		return NULL;
 
@@ -1343,7 +1343,7 @@ create_reconnect_durable_buf(struct cifs_fid *fid)
 {
 	struct create_durable *buf;
 
-	buf = kzalloc(sizeof(struct create_durable), GFP_KERNEL);
+	buf = kzalloc(sizeof(*buf), GFP_KERNEL);
 	if (!buf)
 		return NULL;
 
@@ -1420,7 +1420,7 @@ create_durable_v2_buf(struct cifs_fid *pfid)
 {
 	struct create_durable_v2 *buf;
 
-	buf = kzalloc(sizeof(struct create_durable_v2), GFP_KERNEL);
+	buf = kzalloc(sizeof(*buf), GFP_KERNEL);
 	if (!buf)
 		return NULL;
 
@@ -1449,8 +1449,7 @@ create_reconnect_durable_v2_buf(struct cifs_fid *fid)
 {
 	struct create_durable_handle_reconnect_v2 *buf;
 
-	buf = kzalloc(sizeof(struct create_durable_handle_reconnect_v2),
-			GFP_KERNEL);
+	buf = kzalloc(sizeof(*buf), GFP_KERNEL);
 	if (!buf)
 		return NULL;
 
-- 
2.14.0

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

* [PATCH 3/8] CIFS: One function call less in cifs_lookup() after error detection
       [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   ` 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
  2 siblings, 0 replies; 10+ messages in thread
From: SF Markus Elfring @ 2017-08-20 16:36 UTC (permalink / raw)
  To: linux-cifs-u79uwXL29TY76Z2rM5mHXA,
	samba-technical-w/Ol4Ecudpl8XjKLYN78aQ, Steve French
  Cc: LKML, kernel-janitors-u79uwXL29TY76Z2rM5mHXA

From: Markus Elfring <elfring-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Date: Sun, 20 Aug 2017 16:26:44 +0200

The kfree() function was called in up to two cases by the
cifs_lookup() function during error handling even if the passed variable
contained a null pointer.

* Adjust a jump target according to the Linux coding style convention.

* Delete an initialisation for the variable "full_path" at the beginning
  which became unnecessary with this refactoring.

Signed-off-by: Markus Elfring <elfring-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
---
 fs/cifs/dir.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index 7dd7ca1afe0b..b43e535ced8a 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -759,7 +759,7 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
 	struct tcon_link *tlink;
 	struct cifs_tcon *pTcon;
 	struct inode *newInode = NULL;
-	char *full_path = NULL;
+	char *full_path;
 
 	xid = get_xid();
 
@@ -778,7 +778,7 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
 
 	rc = check_name(direntry);
 	if (rc)
-		goto lookup_out;
+		goto put_link;
 
 	/* can not grab the rename sem here since it would
 	deadlock in the cases (beginning of sys_rename itself)
@@ -786,7 +786,7 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
 	full_path = build_path_from_dentry(direntry);
 	if (full_path == NULL) {
 		rc = -ENOMEM;
-		goto lookup_out;
+		goto put_link;
 	}
 
 	if (d_really_is_positive(direntry)) {
@@ -823,8 +823,8 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
 		is a common return code */
 	}
 
-lookup_out:
 	kfree(full_path);
+put_link:
 	cifs_put_tlink(tlink);
 	free_xid(xid);
 	return ERR_PTR(rc);
-- 
2.14.0

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

* [PATCH 4/8] CIFS: Use common error handling code in cifs_mknod()
  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 ` SF Markus Elfring
  2017-08-20 16:39 ` [PATCH 5/8] CIFS: Less function calls in cifs_mknod() after error detection SF Markus Elfring
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: SF Markus Elfring @ 2017-08-20 16:38 UTC (permalink / raw)
  To: linux-cifs, samba-technical, Steve French; +Cc: LKML, kernel-janitors

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

Add a jump target so that a bit of exception handling can be better reused
in this function.

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

diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index b43e535ced8a..41039ab12643 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -687,8 +687,7 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
 	if (buf == NULL) {
 		kfree(full_path);
 		rc = -ENOMEM;
-		free_xid(xid);
-		return rc;
+		goto free_id;
 	}
 
 	if (backup_cred(cifs_sb))
@@ -744,8 +743,9 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
 mknod_out:
 	kfree(full_path);
 	kfree(buf);
-	free_xid(xid);
 	cifs_put_tlink(tlink);
+free_id:
+	free_xid(xid);
 	return rc;
 }
 
-- 
2.14.0

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

* [PATCH 5/8] CIFS: Less function calls in cifs_mknod() after error detection
  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
       [not found] ` <826310e5-e01c-38af-90df-c5630f761a4d-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: SF Markus Elfring @ 2017-08-20 16:39 UTC (permalink / raw)
  To: linux-cifs, samba-technical, Steve French; +Cc: LKML, kernel-janitors

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

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

* [PATCH 6/8] CIFS: Return directly after a failed build_path_from_dentry() in cifs_do_create()
       [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   ` SF Markus Elfring
  2019-11-07  3:34     ` Steve French
  2 siblings, 1 reply; 10+ messages in thread
From: SF Markus Elfring @ 2017-08-20 16:40 UTC (permalink / raw)
  To: linux-cifs-u79uwXL29TY76Z2rM5mHXA,
	samba-technical-w/Ol4Ecudpl8XjKLYN78aQ, Steve French
  Cc: LKML, kernel-janitors-u79uwXL29TY76Z2rM5mHXA

From: Markus Elfring <elfring-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Date: Sun, 20 Aug 2017 17:17:30 +0200

Return directly after a call of the function "build_path_from_dentry"
failed at the beginning.

Signed-off-by: Markus Elfring <elfring-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
---
 fs/cifs/dir.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index 2c9cbd8393d6..248aead1f3f4 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -239,10 +239,8 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
 		*oplock = REQ_OPLOCK;
 
 	full_path = build_path_from_dentry(direntry);
-	if (full_path == NULL) {
-		rc = -ENOMEM;
-		goto out;
-	}
+	if (!full_path)
+		return -ENOMEM;
 
 	if (tcon->unix_ext && cap_unix(tcon->ses) && !tcon->broken_posix_open &&
 	    (CIFS_UNIX_POSIX_PATH_OPS_CAP &
-- 
2.14.0

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

* [PATCH 7/8] CIFS: Delete an unnecessary variable initialisation in cifs_do_create()
  2017-08-20 16:32 [PATCH 0/8] CIFS: Adjustments for several function implementations SF Markus Elfring
                   ` (3 preceding siblings ...)
       [not found] ` <826310e5-e01c-38af-90df-c5630f761a4d-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
@ 2017-08-20 16:41 ` 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
  5 siblings, 0 replies; 10+ messages in thread
From: SF Markus Elfring @ 2017-08-20 16:41 UTC (permalink / raw)
  To: linux-cifs, samba-technical, Steve French; +Cc: LKML, kernel-janitors

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

The local variable "full_path" will be set to an appropriate pointer
a bit later. Thus omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 fs/cifs/dir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index 248aead1f3f4..69babcf4f653 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -227,7 +227,7 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
 	int desired_access;
 	struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
 	struct cifs_tcon *tcon = tlink_tcon(tlink);
-	char *full_path = NULL;
+	char *full_path;
 	FILE_ALL_INFO *buf = NULL;
 	struct inode *newinode = NULL;
 	int disposition;
-- 
2.14.0

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

* [PATCH 8/8] CIFS: One function call less in cifs_do_create() after error detection
  2017-08-20 16:32 [PATCH 0/8] CIFS: Adjustments for several function implementations SF Markus Elfring
                   ` (4 preceding siblings ...)
  2017-08-20 16:41 ` [PATCH 7/8] CIFS: Delete an unnecessary variable initialisation " SF Markus Elfring
@ 2017-08-20 16:42 ` SF Markus Elfring
  5 siblings, 0 replies; 10+ messages in thread
From: SF Markus Elfring @ 2017-08-20 16:42 UTC (permalink / raw)
  To: linux-cifs, samba-technical, Steve French; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 20 Aug 2017 17:47:44 +0200

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

Add a jump target according to the Linux coding style convention.

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

diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index 69babcf4f653..73e68aa5326e 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -258,7 +258,7 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
 				CIFSSMBClose(xid, tcon, fid->netfid);
 				iput(newinode);
 				rc = -EISDIR;
-				goto out;
+				goto free_path;
 			}
 
 			if (!S_ISREG(newinode->i_mode)) {
@@ -301,7 +301,7 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
 			break;
 
 		default:
-			goto out;
+			goto free_path;
 		}
 		/*
 		 * fallthrough to retry, using older open call, this is case
@@ -334,13 +334,13 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
 
 	if (!server->ops->open) {
 		rc = -ENOSYS;
-		goto out;
+		goto free_path;
 	}
 
 	buf = kmalloc(sizeof(*buf), GFP_KERNEL);
 	if (buf == NULL) {
 		rc = -ENOMEM;
-		goto out;
+		goto free_path;
 	}
 
 	/*
@@ -444,6 +444,7 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
 
 out:
 	kfree(buf);
+free_path:
 	kfree(full_path);
 	return rc;
 
-- 
2.14.0


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

* Re: [PATCH 6/8] CIFS: Return directly after a failed build_path_from_dentry() in cifs_do_create()
  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
  0 siblings, 0 replies; 10+ messages in thread
From: Steve French @ 2019-11-07  3:34 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: CIFS, samba-technical, Steve French, LKML, kernel-janitors

merged into cifs-2.6.git for-next

On Sun, Aug 20, 2017 at 11:40 AM SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
>
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 20 Aug 2017 17:17:30 +0200
>
> Return directly after a call of the function "build_path_from_dentry"
> failed at the beginning.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  fs/cifs/dir.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
> index 2c9cbd8393d6..248aead1f3f4 100644
> --- a/fs/cifs/dir.c
> +++ b/fs/cifs/dir.c
> @@ -239,10 +239,8 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
>                 *oplock = REQ_OPLOCK;
>
>         full_path = build_path_from_dentry(direntry);
> -       if (full_path == NULL) {
> -               rc = -ENOMEM;
> -               goto out;
> -       }
> +       if (!full_path)
> +               return -ENOMEM;
>
>         if (tcon->unix_ext && cap_unix(tcon->ses) && !tcon->broken_posix_open &&
>             (CIFS_UNIX_POSIX_PATH_OPS_CAP &
> --
> 2.14.0
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-cifs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Thanks,

Steve

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

end of thread, other threads:[~2019-11-07  3:34 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 5/8] CIFS: Less function calls in cifs_mknod() after error detection SF Markus Elfring
     [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

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).