cifs: copy_to_user and copy_from_user fixes
PATCH 1/6 cifs: copy_to_user and copy_from_user fixes
Check return value for copy_to_user() and copy_from_user().
---
cifssmb.c | 37 ++++++++++++++++++++++--------------- file.c | 6 +++++- 2 files changed, 27 insertions(+), 16 deletions(-)
fs/cifs/cifssmb.c +22 -15
@@ -886,25 +886,29 @@ pSMB->Reserved =0xFFFFFFFF ; pSMB->WriteMode =0 ; pSMB->Remaining =0 ; -/* BB can relax this if buffer is big enough in some cases - ie we can -send more if LARGE_WRITE_X capability returned by the server and if -our buffer is big enough or if we convert to iovecs on socket writes -and eliminate the copy to the CIFS buffer */ +/* +* BB can relax this if buffer is big enough in some cases - ie we can +* send more if LARGE_WRITE_X capability returned by the server and if +* our buffer is big enough or if we convert to iovecs on socket writes +* and eliminate the copy to the CIFS buffer +*/ bytes_sent = (tcon->ses->server->maxBuf -MAX_CIFS_HDR_SIZE ) & ~0xFF ;if (bytes_sent > count) bytes_sent = count; pSMB->DataLengthHigh =0 ; pSMB->DataOffset =cpu_to_le16 (offsetof(struct smb_com_write_req ,Data) -4 ); -if (buf) -memcpy (pSMB->Data,buf,bytes_sent); -else if (ubuf) -copy_from_user (pSMB->Data,ubuf,bytes_sent); -else { -/* No buffer */ -if (pSMB) -cifs_buf_release (pSMB); -return -EINVAL ; + +if (buf) +memcpy (pSMB->Data, buf, bytes_sent); +else if (ubuf) { +if (copy_from_user (pSMB->Data, ubuf, bytes_sent)) { + rc = -EFAULT ; + goto out_release; + } + }else { + rc = -EINVAL ; + goto out_release; } byte_count = bytes_sent +1 /* pad */ ;
@@ -921,11 +925,14 @@ }else *nbytes =le16_to_cpu (pSMBr->Count); + out_release:if (pSMB)cifs_buf_release (pSMB); -/* Note: On -EAGAIN error only caller can retry on handle based calls -since file handle passed in no longer valid */ +/* +* Note: On -EAGAIN error only caller can retry on handle based calls +* since file handle passed in no longer valid +*/ return rc; }
fs/cifs/file.c +5 -1
@@ -1165,8 +1165,12 @@ &bytes_read, &smb_read_data); pSMBr = (struct smb_com_read_rsp *)smb_read_data; -copy_to_user (current_offset,smb_read_data +4 /* RFC1001 hdr*/ + rc =copy_to_user (current_offset, smb_read_data +4 /* RFC1001 hdr */ +le16_to_cpu (pSMBr->DataOffset), bytes_read); +if (rc) { +FreeXid (xid); +return -EFAULT ; + }if (smb_read_data) {cifs_buf_release (smb_read_data); smb_read_data =NULL ;
PATCH 2/6 cifs: remove dead code
This patch removes commented out code.
---
asn1.c | 122 ---------------------------------------------------------- cifsencrypt.c | 5 -- cifsfs.c | 25 ----------- cifssmb.c | 48 +--------------------- connect.c | 25 ----------- dir.c | 18 -------- fcntl.c | 5 -- file.c | 105 ------------------------------------------------- inode.c | 27 ------------ link.c | 13 ------ misc.c | 6 -- readdir.c | 62 ----------------------------- transport.c | 2 13 files changed, 6 insertions(+), 457 deletions(-)
fs/cifs/asn1.c +0 -122
@@ -236,128 +236,6 @@ } } -/* static unsigned char asn1_null_decode(struct asn1_ctx *ctx, -unsigned char *eoc) -{ -ctx->pointer = eoc; -return 1; -} - -static unsigned char asn1_long_decode(struct asn1_ctx *ctx, -unsigned char *eoc, long *integer) -{ -unsigned char ch; -unsigned int len; - -if (!asn1_octet_decode(ctx, &ch)) -return 0; - -*integer = (signed char) ch; -len = 1; - -while (ctx->pointer < eoc) { -if (++len > sizeof(long)) { -ctx->error = ASN1_ERR_DEC_BADVALUE; -return 0; -} - -if (!asn1_octet_decode(ctx, &ch)) -return 0; - -*integer <<= 8; -*integer |= ch; -} -return 1; -} - -static unsigned char asn1_uint_decode(struct asn1_ctx *ctx, -unsigned char *eoc, -unsigned int *integer) -{ -unsigned char ch; -unsigned int len; - -if (!asn1_octet_decode(ctx, &ch)) -return 0; - -*integer = ch; -if (ch == 0) -len = 0; -else -len = 1; - -while (ctx->pointer < eoc) { -if (++len > sizeof(unsigned int)) { -ctx->error = ASN1_ERR_DEC_BADVALUE; -return 0; -} - -if (!asn1_octet_decode(ctx, &ch)) -return 0; - -*integer <<= 8; -*integer |= ch; -} -return 1; -} - -static unsigned char asn1_ulong_decode(struct asn1_ctx *ctx, -unsigned char *eoc, -unsigned long *integer) -{ -unsigned char ch; -unsigned int len; - -if (!asn1_octet_decode(ctx, &ch)) -return 0; - -*integer = ch; -if (ch == 0) -len = 0; -else -len = 1; - -while (ctx->pointer < eoc) { -if (++len > sizeof(unsigned long)) { -ctx->error = ASN1_ERR_DEC_BADVALUE; -return 0; -} - -if (!asn1_octet_decode(ctx, &ch)) -return 0; - -*integer <<= 8; -*integer |= ch; -} -return 1; -} - -static unsigned char -asn1_octets_decode(struct asn1_ctx *ctx, -unsigned char *eoc, -unsigned char **octets, unsigned int *len) -{ -unsigned char *ptr; - -*len = 0; - -*octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC); -if (*octets == NULL) { -return 0; -} - -ptr = *octets; -while (ctx->pointer < eoc) { -if (!asn1_octet_decode(ctx, (unsigned char *) ptr++)) { -kfree(*octets); -*octets = NULL; -return 0; -} -(*len)++; -} -return 1; -} */ -static unsigned char asn1_subid_decode (struct asn1_ctx *ctx,unsigned long *subid) {
fs/cifs/cifsencrypt.c +0 -5
@@ -120,9 +120,6 @@if (rc)return rc; - -/* cifs_dump_mem("what we think it should be: ",what_we_think_sig_should_be,16); */ -if (memcmp (server_response_sig, what_we_think_sig_should_be,8 ))return -EACCES ;else
@@ -198,11 +195,9 @@ {struct HMACMD5Context context;memcpy (v2_session_response +8 , ses->server->cryptKey,8 ); -/* gen_blob(v2_session_response + 16); */ hmac_md5_init_limK_to_64 (ses->mac_signing_key,16 , &context);hmac_md5_update (ses->server->cryptKey,8 ,&context); -/* hmac_md5_update(v2_session_response+16)client thing,8,&context); */ /* BB fix */ hmac_md5_final (v2_session_response,&context); }
fs/cifs/cifsfs.c +0 -25
@@ -109,8 +109,6 @@ sb->s_magic =CIFS_MAGIC_NUMBER ; sb->s_op = &cifs_super_ops; -/* if(cifs_sb->tcon->ses->server->maxBuf > MAX_CIFS_HDR_SIZE + 512) -sb->s_blocksize = cifs_sb->tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE; */ #ifdef CONFIG_CIFS_QUOTA sb->s_qcop = &cifs_quotactl_ops;#endif
@@ -191,10 +189,6 @@ rc =CIFSSMBQFSInfo (xid, pTcon, buf, cifs_sb->local_nls); -/* -int f_type; -__fsid_t f_fsid; -int f_namelen; */ /* BB get from info put in tcon struct at mount time with call to QFSAttrInfo */ FreeXid (xid);return 0 ;/* always return success? what if volume is no longer available? */
@@ -400,12 +394,7 @@ .statfs = cifs_statfs, .alloc_inode = cifs_alloc_inode, .destroy_inode = cifs_destroy_inode, -/* .drop_inode = generic_delete_inode, -.delete_inode = cifs_delete_inode, *//* Do not need the above two functions -unless later we add lazy close of inodes or unless the kernel forgets to call -us with the same number of releases (closes) as opens */ .show_options = cifs_show_options, -/* .umount_begin = cifs_umount_begin, *//* consider adding in the future */ .remount_fs = cifs_remount, };
@@ -463,11 +452,6 @@return generic_file_read (file,read_data,read_size,poffset); }else {/* BB do we need to lock inode from here until after invalidate? */ -/* if(file->f_dentry->d_inode->i_mapping) { -filemap_fdatawrite(file->f_dentry->d_inode->i_mapping); -filemap_fdatawait(file->f_dentry->d_inode->i_mapping); -}*/ -/* cifs_revalidate(file->f_dentry);*/ /* BB fixme */ /* BB we should make timer configurable - perhaps by simply calling cifs_revalidate here */
@@ -519,7 +503,6 @@ .name = "cifs", .get_sb = cifs_get_sb, .kill_sb = kill_anon_super, -/* .fs_flags */ };struct inode_operations cifs_dir_inode_ops = { .create = cifs_create,
@@ -531,7 +514,6 @@ .rmdir = cifs_rmdir, .rename = cifs_rename, .permission = cifs_permission, -/* revalidate:cifs_revalidate, */ .setattr = cifs_setattr, .symlink = cifs_symlink, .mknod = cifs_mknod,
@@ -544,7 +526,6 @@ };struct inode_operations cifs_file_inode_ops = { -/* revalidate:cifs_revalidate, */ .setattr = cifs_setattr, .getattr = cifs_getattr,/* do we need this anymore? */ .rename = cifs_rename,
@@ -562,9 +543,6 @@ .follow_link = cifs_follow_link, .put_link = cifs_put_link, .permission = cifs_permission, -/* BB add the following two eventually */ -/* revalidate: cifs_revalidate, -setattr: cifs_notify_change, *//* BB do we need notify change */ #ifdef CONFIG_CIFS_XATTR .setxattr = cifs_setxattr, .getxattr = cifs_getxattr,
@@ -641,7 +619,6 @@ }else { CIFSMaxBufSize &=0x1FE00 ;/* Round size to even 512 byte mult*/ } -/* cERROR(1,("CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize)); */ cifs_req_cachep = kmem_cache_create("cifs_request", CIFSMaxBufSize + MAX_CIFS_HDR_SIZE, 0,
@@ -794,7 +771,6 @@deadlock when oplock received on delete since vfs_unlink holds the i_sem across the call */ -/* down(&inode->i_sem);*/ if (S_ISREG (inode->i_mode)) { rc =filemap_fdatawrite (inode->i_mapping);if (CIFS_I (inode)->clientCanCacheRead ==0 ) {
@@ -803,7 +779,6 @@ } }else rc =0 ; -/* up(&inode->i_sem);*/ if (rc)CIFS_I (inode)->write_behind_rc = rc;cFYI (1 ,("Oplock flush inode %p rc %d" ,inode,rc));
fs/cifs/cifssmb.c +3 -45
138 lines not on this page · raw message
fs/cifs/connect.c +2 -23
@@ -184,7 +184,6 @@if (server->tcpStatus != CifsExiting) server->tcpStatus = CifsGood;spin_unlock (&GlobalMid_Lock); -/* atomic_set(&server->inFlight,0);*/ wake_up (&server->response_q); } }
@@ -1200,8 +1199,6 @@ xid =GetXid (); -/* cFYI(1, ("Entering cifs_mount. Xid: %d with: %s", xid, mount_data)); */ -memset (&volume_info,0 ,sizeof (struct smb_vol ));if (cifs_parse_mount_options (mount_data, devname, &volume_info)) {if (volume_info.UNC)
@@ -1518,7 +1515,6 @@ }else cFYI (1 , ("No session or bad tcon" ));sesInfoFree (pSesInfo); -/* pSesInfo = NULL; */ } } }else {
@@ -1928,7 +1924,6 @@ rc =SendReceive (xid, ses, smb_buffer, smb_buffer_response, &bytes_returned,1 );if (rc) { -/* rc = map_smb_to_linux_error(smb_buffer_response); *//* done in SendReceive now */ }else if ((smb_buffer_response->WordCount ==3 ) || (smb_buffer_response->WordCount ==4 )) {__u16 action =le16_to_cpu (pSMBr->resp.Action);
@@ -2137,7 +2132,7 @@ negotiate_flags =NTLMSSP_NEGOTIATE_UNICODE |NTLMSSP_NEGOTIATE_OEM |NTLMSSP_REQUEST_TARGET |NTLMSSP_NEGOTIATE_NTLM |0x80000000 | -/* NTLMSSP_NEGOTIATE_ALWAYS_SIGN | */ NTLMSSP_NEGOTIATE_128 ; +NTLMSSP_NEGOTIATE_128 ;if (sign_CIFS_PDUs) negotiate_flags |=NTLMSSP_NEGOTIATE_SIGN ;if (ntlmv2_support)
@@ -2218,7 +2213,6 @@ rc =0 ;if (rc) { -/* rc = map_smb_to_linux_error(smb_buffer_response); *//* done in SendReceive now */ }else if ((smb_buffer_response->WordCount ==3 ) || (smb_buffer_response->WordCount ==4 )) {__u16 action =le16_to_cpu (pSMBr->resp.Action);
@@ -2483,7 +2477,7 @@NTLMSSP_NEGOTIATE_NTLM |NTLMSSP_NEGOTIATE_TARGET_INFO |0x80000000 |NTLMSSP_NEGOTIATE_128 ;if (sign_CIFS_PDUs) - negotiate_flags |=/* NTLMSSP_NEGOTIATE_ALWAYS_SIGN |*/ NTLMSSP_NEGOTIATE_SIGN ; + negotiate_flags |=NTLMSSP_NEGOTIATE_SIGN ;if (ntlmv2_flag) negotiate_flags |=NTLMSSP_NEGOTIATE_NTLMV2 ;
@@ -2548,14 +2542,6 @@cpu_to_le16 (len); } -/* SecurityBlob->WorkstationName.Length = cifs_strtoUCS((wchar_t *) bcc_ptr, "AMACHINE",64, nls_codepage); -SecurityBlob->WorkstationName.Length *= 2; -SecurityBlob->WorkstationName.MaximumLength = cpu_to_le16(SecurityBlob->WorkstationName.Length); -SecurityBlob->WorkstationName.Buffer = cpu_to_le32(SecurityBlobLength); -bcc_ptr += SecurityBlob->WorkstationName.Length; -SecurityBlobLength += SecurityBlob->WorkstationName.Length; -SecurityBlob->WorkstationName.Length = cpu_to_le16(SecurityBlob->WorkstationName.Length); */ -if ((long ) bcc_ptr %2 ) { *bcc_ptr =0 ; bcc_ptr++;
@@ -2633,7 +2619,6 @@ rc =SendReceive (xid, ses, smb_buffer, smb_buffer_response, &bytes_returned,1 );if (rc) { -/* rc = map_smb_to_linux_error(smb_buffer_response); *//* done in SendReceive now */ }else if ((smb_buffer_response->WordCount ==3 ) || (smb_buffer_response->WordCount ==4 )) {__u16 action =le16_to_cpu (pSMBr->resp.Action);
@@ -2641,9 +2626,6 @@le16_to_cpu (pSMBr->resp.SecurityBlobLength);if (action &GUEST_LOGIN )cFYI (1 , (" Guest login" ));/* BB do we want to set anything in SesInfo struct ? */ -/* if(SecurityBlob2->MessageType != NtLm??){ -cFYI("Unexpected message type on auth response is %d ")); -} */ if (ses) { cFYI(1, ("Does UID on challenge %d match auth response UID %d ",
@@ -2856,8 +2838,6 @@ rc =SendReceive (xid, ses, smb_buffer, smb_buffer_response, &length,0 ); -/* if (rc) rc = map_smb_to_linux_error(smb_buffer_response); */ -/* above now done in SendReceive */ if ((rc ==0 ) && (tcon !=NULL )) { tcon->tidStatus = CifsGood; tcon->tid = smb_buffer_response->Tid;
@@ -3017,7 +2997,6 @@ v2_response =kmalloc (16 +64 /* blob */ ,GFP_KERNEL );if (v2_response) {CalcNTLMv2_response (pSesInfo,v2_response); -/* cifs_calculate_ntlmv2_mac_key(pSesInfo->mac_signing_key, response, ntlm_session_key, */ kfree (v2_response);/* BB Put dummy sig in SessSetup PDU? */ }else
fs/cifs/dir.c +0 -18
@@ -297,7 +297,6 @@ pCifsFile->closePend = FALSE;init_MUTEX (&pCifsFile->fh_sem);/* put the following in at open now */ -/* pCifsFile->pfile = file; */ write_lock (&GlobalSMBSeslock);list_add (&pCifsFile->tlist,&pTcon->openFileList); pCifsInode =CIFS_I (newinode);
@@ -489,11 +488,8 @@ {int isValid =1 ; -/* lock_kernel(); *//* surely we do not want to lock the kernel for a whole network round trip which could take seconds */ -if (direntry->d_inode) {if (cifs_revalidate (direntry)) { -/* unlock_kernel(); */ return 0 ; } }else {
@@ -501,23 +497,9 @@ ("In cifs_d_revalidate with no inode but name = %s and dentry 0x%p" , direntry->d_name.name, direntry)); } - -/* unlock_kernel(); */ -return isValid; } -/* static int cifs_d_delete(struct dentry *direntry) -{ -int rc = 0; - -cFYI(1, ("In cifs d_delete, name = %s", direntry->d_name.name)); - -return rc; -} */ -struct dentry_operations cifs_dentry_ops = { .d_revalidate = cifs_d_revalidate, -/* d_delete: cifs_d_delete, *//* not needed except for debugging */ -/* no need for d_hash, d_compare, d_release, d_iput ... yet. BB confirm this BB */ };
fs/cifs/fcntl.c +0 -5
@@ -58,11 +58,6 @@ cifs_ntfy_flags |=FILE_NOTIFY_CHANGE_SECURITY |FILE_NOTIFY_CHANGE_ATTRIBUTES ; } -/* if(fcntl_notify_flags & DN_MULTISHOT) { -cifs_ntfy_flags |= ; -} */ /* BB fixme - not sure how to handle this with CIFS yet */ - -return cifs_ntfy_flags; }
fs/cifs/file.c +0 -105
187 lines not on this page · raw message
fs/cifs/inode.c +0 -27
@@ -49,7 +49,6 @@/* we could have done a find first instead but this returns more info */ rc =CIFSSMBUnixQPathInfo (xid, pTcon, search_path, &findData, cifs_sb->local_nls); -/* dump_mem("\nUnixQPathInfo return data", &findData, sizeof(findData)); */ if (rc) {if (rc == -EREMOTE ) { tmp_path =
@@ -149,9 +148,6 @@size of 512 is required to be used for calculating num blocks */ -/* inode->i_blocks = -(inode->i_blksize - 1 + num_of_bytes) >> inode->i_blkbits;*/ -/* 512 bytes (2**9) is the fake blocksize that must be used */ /* for this calculation */ inode->i_blocks = (512 -1 + num_of_bytes) >>9 ;
@@ -174,7 +170,6 @@ }else if (S_ISLNK (inode->i_mode)) {cFYI (1 , (" Symbolic Link inode " )); inode->i_op = &cifs_symlink_inode_ops; -/* tmp_inode->i_fop = *//* do not need to set to anything */ }else {cFYI (1 , (" Init special inode " )); init_special_inode(inode, inode->i_mode,
@@ -215,7 +210,6 @@ rc =CIFSSMBQPathInfo (xid, pTcon, search_path, pfindData, cifs_sb->local_nls); } -/* dump_mem("\nQPathInfo return data",&findData, sizeof(findData)); */ if (rc) {if (rc == -EREMOTE ) { tmp_path =
@@ -261,11 +255,6 @@Are there Windows server or network appliances for which IndexNumber field is not guaranteed unique? */ -/* if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) { -(*pinode)->i_ino = -(unsigned long)pfindData->IndexNumber; -} */ /*NB: ino incremented to unique num in new_inode*/ -insert_inode_hash (*pinode); } inode = *pinode;
@@ -295,7 +284,6 @@/* new inode, can safely set these fields */ inode->i_mode = cifs_sb->mnt_file_mode; -/* if (attr & ATTR_REPARSE) */ /* We no longer handle these as symlinks because we could not */ /* follow them due to the absolute path with drive letter */ if (attr &ATTR_DIRECTORY ) {
@@ -391,9 +379,7 @@/* Unlink can be called from rename so we can not grab the sem here since we deadlock otherwise */ -/* down(&direntry->d_sb->s_vfs_rename_sem);*/ full_path =build_path_from_dentry (direntry); -/* up(&direntry->d_sb->s_vfs_rename_sem);*/ if (full_path ==NULL ) {FreeXid (xid);return -ENOMEM ;
@@ -730,16 +716,12 @@ direntry->d_sb,xid);if (rc) {cFYI (1 ,("error on getting revalidate info %d" ,rc)); -/* if(rc != -ENOENT) -rc = 0; */ /* BB should we cache info on certain errors? */ } }else { rc =cifs_get_inode_info (&direntry->d_inode, full_path,NULL , direntry->d_sb,xid);if (rc) {cFYI (1 ,("error on getting revalidate info %d" ,rc)); -/* if(rc != -ENOENT) -rc = 0; */ /* BB should we cache info on certain errors? */ } }/* should we remap certain errors, access denied?, to zero */
@@ -765,7 +747,6 @@documentation indicates i_sem may be taken by the kernel on lookup and rename which could deadlock if we grab the i_sem here as well */ -/* down(&direntry->d_inode->i_sem);*/ /* need to write out dirty pages here */ if (direntry->d_inode->i_mapping) {/* do we need to lock inode until after invalidate completes below? */
@@ -780,7 +761,6 @@invalidate_remote_inode (direntry->d_inode); } } -/* up(&direntry->d_inode->i_sem);*/ if (full_path)kfree (full_path);
@@ -907,7 +887,6 @@ }/* Server is ok setting allocation size implicitly - no need to call: */ -/*CIFSSMBSetEOF(xid, pTcon, full_path, attrs->ia_size, TRUE, cifs_sb->local_nls);*/ if (rc ==0 ) { rc =vmtruncate (direntry->d_inode, attrs->ia_size);
@@ -917,19 +896,16 @@if (attrs->ia_valid &ATTR_UID ) {cFYI (1 , (" CIFS - UID changed to %d" , attrs->ia_uid)); uid = attrs->ia_uid; -/* entry->uid = cpu_to_le16(attr->ia_uid); */ }if (attrs->ia_valid &ATTR_GID ) {cFYI (1 , (" CIFS - GID changed to %d" , attrs->ia_gid)); gid = attrs->ia_gid; -/* entry->gid = cpu_to_le16(attr->ia_gid); */ } time_buf.Attributes =0 ;if (attrs->ia_valid &ATTR_MODE ) {cFYI (1 , (" CIFS - Mode changed to 0x%x" , attrs->ia_mode)); mode = attrs->ia_mode; -/* entry->mode = cpu_to_le16(attr->ia_mode); */ } if ((cifs_sb->tcon->ses->capabilities & CAP_UNIX)
@@ -947,7 +923,6 @@cpu_to_le32 (cifsInode->cifsAttrs & (~ATTR_READONLY )); }/* BB to be implemented - via Windows security descriptors or streams */ -/* CIFSSMBWinSetPerms(xid,pTcon,full_path,mode,uid,gid,cifs_sb->local_nls);*/ }if (attrs->ia_valid &ATTR_ATIME ) {
@@ -987,8 +962,6 @@below rather than here */ /* Better to return EOPNOTSUPP until function below is ready */ -/* CIFSSMBSetTimesLegacy(xid, pTcon, full_path, -FILE_INFO_STANDARD * data, cifs_sb->local_nls); */ } }
fs/cifs/link.c +0 -13
@@ -67,14 +67,6 @@ rc = -EOPNOTSUPP ; } -/* if (!rc) */ - { -/* renew_parental_timestamps(old_file); -inode->i_nlink++; -mark_inode_dirty(inode); -d_instantiate(direntry, inode); */ -/* BB add call to either mark inode dirty or refresh its data and timestamp to current time */ - }d_drop (direntry);/* force new lookup from server */ cifsInode =CIFS_I (old_file->d_inode); cifsInode->time =0 ;/* will force revalidate to go get info when needed */
@@ -124,7 +116,6 @@PATH_MAX -1 , cifs_sb->local_nls); else { -/* rc = CIFSSMBQueryReparseLinkInfo */ /* BB Add code to Query ReparsePoint info */ /* BB Add MAC style xsymlink check here if enabled */ }
@@ -178,8 +169,6 @@if (cifs_sb->tcon->ses->capabilities &CAP_UNIX ) rc =CIFSUnixCreateSymLink (xid, pTcon, full_path, symname, cifs_sb->local_nls); -/* else -rc = CIFSCreateReparseSymLink(xid, pTcon, fromName, toName,cifs_sb_target->local_nls); */ if (rc ==0 ) {if (pTcon->ses->capabilities &CAP_UNIX )
@@ -228,9 +217,7 @@/* BB would it be safe against deadlock to grab this sem even though rename itself grabs the sem and calls lookup? */ -/* down(&inode->i_sb->s_vfs_rename_sem);*/ full_path =build_path_from_dentry (direntry); -/* up(&inode->i_sb->s_vfs_rename_sem);*/ if (full_path ==NULL ) {FreeXid (xid);
fs/cifs/misc.c +0 -6
@@ -59,8 +59,6 @@ _FreeXid(unsigned int xid) {spin_lock (&GlobalMid_Lock); -/* if(GlobalTotalActiveXid == 0) -BUG(); */ GlobalTotalActiveXid--;spin_unlock (&GlobalMid_Lock); }
@@ -175,13 +173,11 @@ {if (buf_to_free ==NULL ) { -/* cFYI(1, ("Null buffer passed to cifs_buf_release"));*/ return ; }mempool_free (buf_to_free,cifs_req_poolp);atomic_dec (&bufAllocCount); -return ; } struct smb_hdr *
@@ -197,7 +193,6 @@ (struct smb_hdr *)mempool_alloc (cifs_sm_req_poolp,SLAB_KERNEL |SLAB_NOFS );if (ret_buf) {/* No need to clear memory here, cleared in header assemble */ -/* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/ atomic_inc (&smBufAllocCount); }return ret_buf;
@@ -404,7 +399,6 @@ + data_offset);cFYI (1 ,("dnotify on %s with action: 0x%x" ,pnotify->FileName, pnotify->Action));/* BB removeme BB */ -/* cifs_dump_mem("Received notify Data is: ",buf,sizeof(struct smb_hdr)+60); */ return TRUE; }if (pSMBr->hdr.Status.CifsError) {
fs/cifs/readdir.c +1 -61
125 lines not on this page · raw message
fs/cifs/transport.c +0 -2
@@ -285,8 +285,6 @@ rc =cifs_sign_smb (in_buf, ses, &midQ->sequence_number); midQ->midState =MID_REQUEST_SUBMITTED ; -/* rc = smb_send2(ses->server->ssocket, in_buf, in_buf->smb_buf_length, piovec, -(struct sockaddr *) &(ses->server->addr.sockAddr));*/ if (rc <0 ) {DeleteMidQEntry (midQ);up (&ses->server->tcpSem);
PATCH 3/6 cifs: enum conversion
Convert #defines to proper enums and remove duplicate symbols.
---
asn1.c | 72 +++-- cifspdu.h | 798 ++++++++++++++++++++++++++++++++------------------------------ 2 files changed, 464 insertions(+), 406 deletions(-)
fs/cifs/asn1.c +40 -32
@@ -34,46 +34,54 @@*****************************************************************************/ /* Class */ -#define ASN1_UNI 0/* Universal */ -#define ASN1_APL 1/* Application */ -#define ASN1_CTX 2/* Context */ -#define ASN1_PRV 3/* Private */ +enum { +ASN1_UNI =0 ,/* Universal */ +ASN1_APL =1 ,/* Application */ +ASN1_CTX =2 ,/* Context */ +ASN1_PRV =3 /* Private */ +};/* Tag */ -#define ASN1_EOC 0/* End Of Contents or N/A */ -#define ASN1_BOL 1/* Boolean */ -#define ASN1_INT 2/* Integer */ -#define ASN1_BTS 3/* Bit String */ -#define ASN1_OTS 4/* Octet String */ -#define ASN1_NUL 5/* Null */ -#define ASN1_OJI 6/* Object Identifier */ -#define ASN1_OJD 7/* Object Description */ -#define ASN1_EXT 8/* External */ -#define ASN1_SEQ 16/* Sequence */ -#define ASN1_SET 17/* Set */ -#define ASN1_NUMSTR 18/* Numerical String */ -#define ASN1_PRNSTR 19/* Printable String */ -#define ASN1_TEXSTR 20/* Teletext String */ -#define ASN1_VIDSTR 21/* Video String */ -#define ASN1_IA5STR 22/* IA5 String */ -#define ASN1_UNITIM 23/* Universal Time */ -#define ASN1_GENTIM 24/* General Time */ -#define ASN1_GRASTR 25/* Graphical String */ -#define ASN1_VISSTR 26/* Visible String */ -#define ASN1_GENSTR 27/* General String */ +enum { +ASN1_EOC =0 ,/* End Of Contents or N/A */ +ASN1_BOL =1 ,/* Boolean */ +ASN1_INT =2 ,/* Integer */ +ASN1_BTS =3 ,/* Bit String */ +ASN1_OTS =4 ,/* Octet String */ +ASN1_NUL =5 ,/* Null */ +ASN1_OJI =6 ,/* Object Identifier */ +ASN1_OJD =7 ,/* Object Description */ +ASN1_EXT =8 ,/* External */ +ASN1_SEQ =16 ,/* Sequence */ +ASN1_SET =17 ,/* Set */ +ASN1_NUMSTR =18 ,/* Numerical String */ +ASN1_PRNSTR =19 ,/* Printable String */ +ASN1_TEXSTR =20 ,/* Teletext String */ +ASN1_VIDSTR =21 ,/* Video String */ +ASN1_IA5STR =22 ,/* IA5 String */ +ASN1_UNITIM =23 ,/* Universal Time */ +ASN1_GENTIM =24 ,/* General Time */ +ASN1_GRASTR =25 ,/* Graphical String */ +ASN1_VISSTR =26 ,/* Visible String */ +ASN1_GENSTR =27 /* General String */ +};/* Primitive / Constructed methods*/ -#define ASN1_PRI 0/* Primitive */ -#define ASN1_CON 1/* Constructed */ +enum { +ASN1_PRI =0 ,/* Primitive */ +ASN1_CON =1 /* Constructed */ +};/* * Error codes. */ -#define ASN1_ERR_NOERROR 0 -#define ASN1_ERR_DEC_EMPTY 2 -#define ASN1_ERR_DEC_EOC_MISMATCH 3 -#define ASN1_ERR_DEC_LENGTH_MISMATCH 4 -#define ASN1_ERR_DEC_BADVALUE 5 +enum { +ASN1_ERR_NOERROR =0 , +ASN1_ERR_DEC_EMPTY =2 , +ASN1_ERR_DEC_EOC_MISMATCH =3 , +ASN1_ERR_DEC_LENGTH_MISMATCH =4 , +ASN1_ERR_DEC_BADVALUE =5 +};#define SPNEGO_OID_LEN 7#define NTLMSSP_OID_LEN 10
fs/cifs/cifspdu.h +424 -374
978 lines not on this page · raw message
PATCH 4/6 cifs: remove spurious casts
Remove spurious void pointer casts.
---
cifsfs.c | 9 ++++----- dir.c | 6 ++---- file.c | 32 +++++++++++++------------------- misc.c | 17 ++++------------- readdir.c | 6 +++--- transport.c | 5 ++--- 6 files changed, 28 insertions(+), 47 deletions(-)
fs/cifs/cifsfs.c +4 -5
@@ -221,10 +221,9 @@static struct inode *cifs_alloc_inode (struct super_block *sb) { -struct cifsInodeInfo *cifs_inode; - cifs_inode = - (struct cifsInodeInfo *)kmem_cache_alloc (cifs_inode_cachep, -SLAB_KERNEL ); +struct cifsInodeInfo *cifs_inode = +kmem_cache_alloc (cifs_inode_cachep,SLAB_KERNEL ); +if (!cifs_inode)return NULL ; cifs_inode->cifsAttrs =0x20 ;/* default */
@@ -578,7 +577,7 @@static void cifs_init_once (void *inode,kmem_cache_t * cachep,unsigned long flags) { -struct cifsInodeInfo *cifsi = (struct cifsInodeInfo *) inode; +struct cifsInodeInfo *cifsi = inode;if ((flags & (SLAB_CTOR_VERIFY |SLAB_CTOR_CONSTRUCTOR )) ==SLAB_CTOR_CONSTRUCTOR ) {
fs/cifs/dir.c +2 -4
@@ -284,12 +284,10 @@/* mknod case - do not leave file open */ CIFSSMBClose (xid, pTcon, fileHandle); }else if (newinode) { - pCifsFile = (struct cifsFileInfo *) -kmalloc (sizeof (struct cifsFileInfo ),GFP_KERNEL ); + pCifsFile =kmalloc (sizeof (struct cifsFileInfo ),GFP_KERNEL );if (pCifsFile) { -memset ((char *)pCifsFile,0 , -sizeof (struct cifsFileInfo )); +memset (pCifsFile,0 ,sizeof (struct cifsFileInfo )); pCifsFile->netfid = fileHandle; pCifsFile->pid = current->tgid; pCifsFile->pInode = newinode;
fs/cifs/file.c +13 -19
@@ -166,7 +166,7 @@kmalloc (sizeof (struct cifsFileInfo ),GFP_KERNEL );if (file->private_data) {memset (file->private_data,0 ,sizeof (struct cifsFileInfo )); - pCifsFile = (struct cifsFileInfo *) file->private_data; + pCifsFile = file->private_data; pCifsFile->netfid = netfid; pCifsFile->pid = current->tgid;init_MUTEX (&pCifsFile->fh_sem);
@@ -285,7 +285,7 @@if (inode ==NULL )return -EBADF ;if (file->private_data) { - pCifsFile = (struct cifsFileInfo *) file->private_data; + pCifsFile = file->private_data; }else return -EBADF ;
@@ -399,8 +399,7 @@int xid;struct cifs_sb_info *cifs_sb;struct cifsTconInfo *pTcon; -struct cifsFileInfo *pSMBFile = - (struct cifsFileInfo *) file->private_data; +struct cifsFileInfo *pSMBFile = file->private_data; xid =GetXid ();
@@ -446,8 +445,7 @@ {int rc =0 ;int xid; -struct cifsFileInfo *pCFileStruct = - (struct cifsFileInfo *) file->private_data; +struct cifsFileInfo *pCFileStruct = file->private_data;char * ptmp;cFYI (1 , ("Closedir inode = 0x%p with " , inode));
@@ -618,7 +616,7 @@if (file->private_data ==NULL ) {return -EBADF ; }else { - open_file = (struct cifsFileInfo *) file->private_data; + open_file = file->private_data; } xid =GetXid ();
@@ -734,7 +732,7 @@if (file->private_data ==NULL ) {return -EBADF ; }else { - open_file = (struct cifsFileInfo *) file->private_data; + open_file = file->private_data; } xid =GetXid ();
@@ -1057,7 +1055,7 @@FreeXid (xid);return -EBADF ; } - open_file = (struct cifsFileInfo *)file->private_data; + open_file = file->private_data;if ((file->f_flags &O_ACCMODE ) ==O_WRONLY ) {cFYI (1 ,("attempting read on write only file instance" ));
@@ -1136,7 +1134,7 @@FreeXid (xid);return -EBADF ; } - open_file = (struct cifsFileInfo *)file->private_data; + open_file = file->private_data;if ((file->f_flags &O_ACCMODE ) ==O_WRONLY ) {cFYI (1 ,("attempting read on write only file instance" ));
@@ -1274,7 +1272,7 @@FreeXid (xid);return -EBADF ; } - open_file = (struct cifsFileInfo *)file->private_data; + open_file = file->private_data; cifs_sb =CIFS_SB (file->f_dentry->d_sb); pTcon = cifs_sb->tcon;
@@ -1712,9 +1710,7 @@static void reset_resume_key (struct file * dir_file,unsigned char * filename,unsigned int len,int Unicode,struct nls_table * nls_tab) { -struct cifsFileInfo *cifsFile; - - cifsFile = (struct cifsFileInfo *)dir_file->private_data; +struct cifsFileInfo *cifsFile = dir_file->private_data;if (cifsFile ==NULL )return ;if (cifsFile->search_resume_name) {
@@ -1897,8 +1893,7 @@/* fallthrough */ case 2 :if (file->private_data !=NULL ) { - cifsFile = - (struct cifsFileInfo *) file->private_data; + cifsFile = file->private_data;if (cifsFile->srch_inf.endOfSearch) {if (cifsFile->srch_inf.emptyDir) {cFYI (1 , ("End of search, empty dir" ));
@@ -1930,8 +1925,7 @@if (file->private_data) {memset (file->private_data,0 ,sizeof (struct cifsFileInfo )); - cifsFile = - (struct cifsFileInfo *) file->private_data; + cifsFile = file->private_data; cifsFile->netfid = searchHandle; cifsFile->invalidHandle = FALSE;init_MUTEX (&cifsFile->fh_sem);
@@ -2104,7 +2098,7 @@ ("Readdir on closed srch, pos = %lld" , file->f_pos)); }else { - cifsFile = (struct cifsFileInfo *) file->private_data; + cifsFile = file->private_data;if (cifsFile->srch_inf.endOfSearch) { rc =0 ;cFYI (1 , ("End of search " ));
fs/cifs/misc.c +4 -13
@@ -66,11 +66,7 @@struct cifsSesInfo *sesInfoAlloc (void ) { -struct cifsSesInfo *ret_buf; - - ret_buf = - (struct cifsSesInfo *)kmalloc (sizeof (struct cifsSesInfo ), -GFP_KERNEL ); +struct cifsSesInfo *ret_buf =kmalloc (sizeof (*ret_buf),GFP_KERNEL );if (ret_buf) {memset (ret_buf,0 ,sizeof (struct cifsSesInfo ));write_lock (&GlobalSMBSeslock);
@@ -109,10 +105,7 @@struct cifsTconInfo *tconInfoAlloc (void ) { -struct cifsTconInfo *ret_buf; - ret_buf = - (struct cifsTconInfo *)kmalloc (sizeof (struct cifsTconInfo ), -GFP_KERNEL ); +struct cifsTconInfo *ret_buf =kmalloc (sizeof (*ret_buf),GFP_KERNEL );if (ret_buf) {memset (ret_buf,0 ,sizeof (struct cifsTconInfo ));write_lock (&GlobalSMBSeslock);
@@ -155,8 +148,7 @@but it may be more efficient to always alloc same size albeit slightly larger than necessary and maxbuffersize defaults to this and can not be bigger */ - ret_buf = - (struct smb_hdr *)mempool_alloc (cifs_req_poolp,SLAB_KERNEL |SLAB_NOFS ); + ret_buf =mempool_alloc (cifs_req_poolp,SLAB_KERNEL |SLAB_NOFS );/* clear the first few header bytes */ /* for most paths, more is cleared in header_assemble */
@@ -189,8 +181,7 @@but it may be more efficient to always alloc same size albeit slightly larger than necessary and maxbuffersize defaults to this and can not be bigger */ - ret_buf = - (struct smb_hdr *)mempool_alloc (cifs_sm_req_poolp,SLAB_KERNEL |SLAB_NOFS ); + ret_buf =mempool_alloc (cifs_sm_req_poolp,SLAB_KERNEL |SLAB_NOFS );if (ret_buf) {/* No need to clear memory here, cleared in header assemble */ atomic_inc (&smBufAllocCount);
fs/cifs/readdir.c +3 -3
@@ -65,7 +65,7 @@ }else {memset (file->private_data,0 ,sizeof (struct cifsFileInfo )); } - cifsFile = (struct cifsFileInfo *)file->private_data; + cifsFile = file->private_data; cifsFile->invalidHandle = TRUE; cifsFile->srch_inf.endOfSearch = FALSE;
@@ -221,7 +221,7 @@int pos_in_buf =0 ;loff_t first_entry_in_buffer;loff_t index_to_find = file->f_pos; -struct cifsFileInfo * cifsFile = (struct cifsFileInfo *)file->private_data; +struct cifsFileInfo * cifsFile = file->private_data;/* check if index in the buffer */ if ((cifsFile ==NULL ) || (ppCurrentEntry ==NULL ) || (num_to_ret ==NULL ))
@@ -534,7 +534,7 @@FreeXid (xid);return rc; } - cifsFile = (struct cifsFileInfo *) file->private_data; + cifsFile = file->private_data;if (cifsFile->srch_inf.endOfSearch) {if (cifsFile->srch_inf.emptyDir) {cFYI (1 , ("End of search, empty dir" ));
fs/cifs/transport.c +2 -3
@@ -48,7 +48,7 @@return NULL ; } - temp = (struct mid_q_entry *)mempool_alloc (cifs_mid_poolp,SLAB_KERNEL |SLAB_NOFS ); + temp =mempool_alloc (cifs_mid_poolp,SLAB_KERNEL |SLAB_NOFS );if (temp ==NULL )return temp;else {
@@ -90,8 +90,7 @@cERROR (1 , ("Null parms passed to AllocOplockQEntry" ));return NULL ; } - temp = (struct oplock_q_entry *)kmem_cache_alloc (cifs_oplock_cachep, -SLAB_KERNEL ); + temp =kmem_cache_alloc (cifs_oplock_cachep,SLAB_KERNEL );if (temp ==NULL )return temp;else {
PATCH 6/6 cifs: convert schedule_timeout to msleep and ssleep
In reply to Pekka EnbergThis patch converts cifs code to use msleep() and ssleep() instead of schedule_timeout().
---
cifsfs.c | 9 ++++----- connect.c | 25 +++++++++---------------- 2 files changed, 13 insertions(+), 21 deletions(-)
fs/cifs/cifsfs.c +4 -5
@@ -32,6 +32,7 @@#include <linux/seq_file.h> #include <linux/vfs.h> #include <linux/mempool.h> +#include <linux/delay.h> #include "cifsfs.h" #include "cifspdu.h" #define DECLARE_GLOBALS_HERE
@@ -748,14 +749,12 @@ oplockThread = current; do { - set_current_state(TASK_INTERRUPTIBLE); - - schedule_timeout(1*HZ); + ssleep(1); + spin_lock(&GlobalMid_Lock); if(list_empty(&GlobalOplock_Q)) { spin_unlock(&GlobalMid_Lock); - set_current_state(TASK_INTERRUPTIBLE); - schedule_timeout(39*HZ); + ssleep(39); } else { oplock_item = list_entry(GlobalOplock_Q.next, struct oplock_q_entry, qhead);
fs/cifs/connect.c +9 -16
@@ -29,6 +29,7 @@#include <linux/ctype.h> #include <linux/utsname.h> #include <linux/mempool.h> +#include <linux/delay.h> #include <asm/uaccess.h> #include <asm/processor.h> #include "cifspdu.h"
@@ -174,8 +175,7 @@ server->workstation_RFC1001_name); }if (rc) { -set_current_state (TASK_INTERRUPTIBLE ); -schedule_timeout (3 *HZ ); +ssleep (3 ); }else {atomic_inc (&tcpSesReconnectCount);spin_lock (&GlobalMid_Lock);
@@ -226,8 +226,7 @@if (smb_buffer ==NULL ) {cERROR (1 ,("Can not get memory for SMB response" )); -set_current_state (TASK_INTERRUPTIBLE ); -schedule_timeout (HZ *3 );/* give system time to free memory */ +ssleep (3 );continue ; } iov.iov_base = smb_buffer;
@@ -308,8 +307,7 @@ }else {/* give server a second to clean up before reconnect attempt */ -set_current_state (TASK_INTERRUPTIBLE ); -schedule_timeout (HZ ); +ssleep (1 );/* always try 445 first on reconnect since we get NACK on some if we ever connected to port 139 (the NACK is
@@ -433,8 +431,7 @@and get out of SendReceive. */ wake_up_all (&server->request_q);/* give those requests time to exit */ -set_current_state (TASK_INTERRUPTIBLE ); -schedule_timeout (HZ /8 ); +msleep (125 );if (server->ssocket) {sock_release (csocket);
@@ -471,17 +468,15 @@ }spin_unlock (&GlobalMid_Lock);read_unlock (&GlobalSMBSeslock); -set_current_state (TASK_INTERRUPTIBLE );/* 1/8th of sec is more than enough time for them to exit */ -schedule_timeout (HZ /8 ); +msleep (125 ); }if (list_empty (&server->pending_mid_q)) {/* mpx threads have not exited yet give them at least the smb send timeout time for long ops */ cFYI (1 , ("Wait for exit from demultiplex thread" )); -set_current_state (TASK_INTERRUPTIBLE ); -schedule_timeout (46 *HZ ); +ssleep (46 );/* if threads still have not exited they are probably never coming home not much else we can do but free the memory */ }
@@ -497,8 +492,7 @@ GFP_KERNEL); } -set_current_state (TASK_INTERRUPTIBLE ); -schedule_timeout (HZ /4 ); +msleep (250 );return 0 ; }
@@ -2924,8 +2918,7 @@ cifs_sb->tcon =NULL ;if (ses) { -set_current_state (TASK_INTERRUPTIBLE ); -schedule_timeout (HZ /2 ); +msleep (500 ); }if (ses)sesInfoFree (ses);
PATCH 5/6 cifs: reduce deep nesting
In reply to Pekka EnbergThis patch converts deep if statement nesting to use gotos in few places.
---
cifsfs.c | 51 +++++++++++++++++++++++++++++++-------------------- connect.c | 44 ++++++++++++++++++++------------------------ 2 files changed, 51 insertions(+), 44 deletions(-)
fs/cifs/cifsfs.c +31 -20
@@ -839,26 +839,37 @@ } rc =cifs_init_inodecache (); -if (!rc) { - rc =cifs_init_mids (); -if (!rc) { - rc =cifs_init_request_bufs (); -if (!rc) { - rc =register_filesystem (&cifs_fs_type); -if (!rc) { - rc = (int )kernel_thread (cifs_oplock_thread,NULL , -CLONE_FS |CLONE_FILES |CLONE_VM ); -if (rc >0 ) -return 0 ; -else -cERROR (1 ,("error %d create oplock thread" ,rc)); - } -cifs_destroy_request_bufs (); - } -cifs_destroy_mids (); - } -cifs_destroy_inodecache (); - } +if (rc) + goto failed_init_inodecache; + + rc =cifs_init_mids (); +if (rc) + goto failed_init_mids; + + rc =cifs_init_request_bufs (); +if (rc) + goto failed_init_request_bufs; + + rc =register_filesystem (&cifs_fs_type); +if (rc) + goto failed_register_filesystem; + + rc =kernel_thread (cifs_oplock_thread,NULL , +CLONE_FS |CLONE_FILES |CLONE_VM ); +if (rc <=0 ) + goto failed_kernel_thread; + +return 0 ; + + failed_kernel_thread: +cERROR (1 ,("error %d create oplock thread" ,rc)); + failed_register_filesystem: +cifs_destroy_request_bufs (); + failed_init_request_bufs: +cifs_destroy_mids (); + failed_init_mids: +cifs_destroy_inodecache (); + failed_init_inodecache: #ifdef CONFIG_PROC_FScifs_proc_clean ();#endif
fs/cifs/connect.c +20 -24
64 lines not on this page · raw message