CIFS: Adjustments for several function implementations
Subsystems (3)
cover CIFS: Adjustments for several function implementations
From: Markus Elfring <[email protected]>
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(-)
Signature · 1 line
2.14.0
PATCH 1/8 CIFS: Delete 11 error messages for a failed memory allocation
From: Markus Elfring <[email protected]>
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.
--- 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(-)
fs/cifs/connect.c +4 -13
@@ -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 ;
fs/cifs/sess.c +2 -5
@@ -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; }
fs/cifs/smb2ops.c +0 -1
@@ -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; }
fs/cifs/smb2pdu.c +0 -6
@@ -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; }
fs/cifs/smb2transport.c +0 -1
@@ -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);
Signature · 1 line
2.14.0
PATCH 2/8 CIFS: Improve 27 size determinations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- 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(-)
fs/cifs/cifsacl.c +4 -4
@@ -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);
fs/cifs/cifsfs.c +1 -1
@@ -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;
fs/cifs/cifssmb.c +1 -3
@@ -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;
fs/cifs/dir.c +2 -2
@@ -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 ;
fs/cifs/ioctl.c +1 -1
@@ -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 ;
fs/cifs/readdir.c +1 -1
@@ -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;
fs/cifs/sess.c +1 -1
@@ -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 ;
fs/cifs/smb1ops.c +1 -1
@@ -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 ;
fs/cifs/smb2file.c +2 -2
@@ -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 ;
fs/cifs/smb2misc.c +1 -1
@@ -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;
fs/cifs/smb2ops.c +9 -11
@@ -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;
fs/cifs/smb2pdu.c +5 -6
@@ -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 ;
Signature · 1 line
2.14.0
PATCH 3/8 CIFS: One function call less in cifs_lookup() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- fs/cifs/dir.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/cifs/dir.c +4 -4
@@ -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);
Signature · 1 line
2.14.0
PATCH 4/8 CIFS: Use common error handling code in cifs_mknod()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- fs/cifs/dir.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/cifs/dir.c +3 -3
@@ -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; }
Signature · 1 line
2.14.0
PATCH 5/8 CIFS: Less function calls in cifs_mknod() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- fs/cifs/dir.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
fs/cifs/dir.c +11 -9
@@ -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);
Signature · 1 line
2.14.0
PATCH 6/8 CIFS: Return directly after a failed build_path_from_dentry() in cifs_do_create()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- fs/cifs/dir.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/cifs/dir.c +2 -4
@@ -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 &
Signature · 1 line
2.14.0
Steve French
AppliedRe: [PATCH 6/8] CIFS: Return directly after a failed build_path_from_dentry() in cifs_do_create()
merged into cifs-2.6.git for-next
Quoted 36 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 20 Aug 2017 17:17:30 +0200Return directly after a call of the function "
build_path_from_dentry" failed at the beginning.Signed-off-by Markus Elfring <[email protected]>--- fs/cifs/dir.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)fs/cifs/dir.c +2
-5@@ -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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 3 lines
Thanks, Steve
PATCH 7/8 CIFS: Delete an unnecessary variable initialisation in cifs_do_create()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- fs/cifs/dir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/dir.c +1 -1
@@ -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;
Signature · 1 line
2.14.0
PATCH 8/8 CIFS: One function call less in cifs_do_create() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- fs/cifs/dir.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/cifs/dir.c +5 -4
@@ -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;
Signature · 1 line
2.14.0