@@ -637,6 +637,7 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
cifs_sb = CIFS_SB(parent_dir_inode->i_sb);
tlink = cifs_sb_tlink(cifs_sb);
if (IS_ERR(tlink)) {
+ rc = PTR_ERR(tlink);
free_xid(xid);
return ERR_CAST(tlink);
}
@@ -656,6 +657,7 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
full_path = build_path_from_dentry(direntry, page);
if (IS_ERR(full_path)) {
cifs_put_tlink(tlink);
+ rc = PTR_ERR(full_path);
free_xid(xid);
free_dentry_path(page);
return ERR_CAST(full_path);
@@ -560,7 +560,7 @@ void _cifsFileInfo_put(struct cifsFileInfo *cifs_file,
int cifs_open(struct inode *inode, struct file *file)
{
- int rc = -EACCES;
+ int rc;
unsigned int xid;
__u32 oplock;
struct cifs_sb_info *cifs_sb;
@@ -579,14 +579,16 @@ int cifs_open(struct inode *inode, struct file *file)
cifs_sb = CIFS_SB(inode->i_sb);
if (unlikely(cifs_forced_shutdown(cifs_sb))) {
+ rc = -EIO;
free_xid(xid);
- return -EIO;
+ return rc;
}
tlink = cifs_sb_tlink(cifs_sb);
if (IS_ERR(tlink)) {
+ rc = PTR_ERR(tlink);
free_xid(xid);
- return PTR_ERR(tlink);
+ return rc;
}
tcon = tlink_tcon(tlink);
server = tcon->ses->server;
@@ -759,7 +761,7 @@ cifs_relock_file(struct cifsFileInfo *cfile)
static int
cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)
{
- int rc = -EACCES;
+ int rc = 0;
unsigned int xid;
__u32 oplock;
struct cifs_sb_info *cifs_sb;
@@ -779,7 +781,7 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)
if (!cfile->invalidHandle) {
mutex_unlock(&cfile->fh_mutex);
free_xid(xid);
- return 0;
+ return rc;
}
inode = d_inode(cfile->dentry);
@@ -798,8 +800,9 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)
if (IS_ERR(full_path)) {
mutex_unlock(&cfile->fh_mutex);
free_dentry_path(page);
+ rc = PTR_ERR(full_path);
free_xid(xid);
- return PTR_ERR(full_path);
+ return rc;
}
cifs_dbg(FYI, "inode = 0x%p file flags 0x%x for %s\n",
@@ -1337,8 +1340,8 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile)
*/
max_buf = tcon->ses->server->maxBuf;
if (max_buf < (sizeof(struct smb_hdr) + sizeof(LOCKING_ANDX_RANGE))) {
- free_xid(xid);
- return -EINVAL;
+ rc = -EINVAL;
+ goto out;
}
BUILD_BUG_ON(sizeof(struct smb_hdr) + sizeof(LOCKING_ANDX_RANGE) >
@@ -1349,8 +1352,8 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile)
sizeof(LOCKING_ANDX_RANGE);
buf = kcalloc(max_num, sizeof(LOCKING_ANDX_RANGE), GFP_KERNEL);
if (!buf) {
- free_xid(xid);
- return -ENOMEM;
+ rc = -ENOMEM;
+ goto out;
}
for (i = 0; i < 2; i++) {
@@ -1386,6 +1389,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile)
}
kfree(buf);
+out:
free_xid(xid);
return rc;
}
@@ -1934,7 +1938,6 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *flock)
struct cifsFileInfo *cfile;
__u32 type;
- rc = -EACCES;
xid = get_xid();
cifs_dbg(FYI, "%s: %pD2 cmd=0x%x type=0x%x flags=0x%x r=%lld:%lld\n", __func__, file, cmd,
@@ -1959,8 +1962,7 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *flock)
*/
if (IS_GETLK(cmd)) {
rc = cifs_getlk(file, flock, type, wait_flag, posix_lck, xid);
- free_xid(xid);
- return rc;
+ goto out;
}
if (!lock && !unlock) {
@@ -1968,12 +1970,13 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *flock)
* if no lock or unlock then nothing to do since we do not
* know what it is
*/
- free_xid(xid);
- return -EOPNOTSUPP;
+ rc = -EOPNOTSUPP;
+ goto out;
}
rc = cifs_setlk(file, flock, type, wait_flag, posix_lck, lock, unlock,
xid);
+out:
free_xid(xid);
return rc;
}
@@ -4411,8 +4414,9 @@ cifs_read(struct file *file, char *read_data, size_t read_size, loff_t *offset)
server = cifs_pick_channel(tcon->ses);
if (!server->ops->sync_read) {
+ rc = -ENOSYS;
free_xid(xid);
- return -ENOSYS;
+ return rc;
}
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
@@ -346,8 +346,8 @@ smb2_push_mandatory_locks(struct cifsFileInfo *cfile)
*/
max_buf = tlink_tcon(cfile->tlink)->ses->server->maxBuf;
if (max_buf < sizeof(struct smb2_lock_element)) {
- free_xid(xid);
- return -EINVAL;
+ rc = -EINVAL;
+ goto out;
}
BUILD_BUG_ON(sizeof(struct smb2_lock_element) > PAGE_SIZE);
@@ -355,8 +355,8 @@ 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);
if (!buf) {
- free_xid(xid);
- return -ENOMEM;
+ rc = -ENOMEM;
+ goto out;
}
list_for_each_entry(fdlocks, &cinode->llist, llist) {
@@ -366,6 +366,7 @@ smb2_push_mandatory_locks(struct cifsFileInfo *cfile)
}
kfree(buf);
+out:
free_xid(xid);
return rc;
}
The variable 'rc' was implicitly used by free_xid(), should reset it to correct value before free xid. Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com> --- fs/cifs/dir.c | 2 ++ fs/cifs/file.c | 36 ++++++++++++++++++++---------------- fs/cifs/smb2file.c | 9 +++++---- 3 files changed, 27 insertions(+), 20 deletions(-)