Fix three refcount inconsistency issues related to `cifs_sb_tlink`.
Comments for `cifs_sb_tlink` state that `cifs_put_tlink()` needs to be
called after successful calls to `cifs_sb_tlink()`. Three calls fail to
update refcount accordingly, leading to possible resource leaks.
Fixes: 8ceb98437946 ("CIFS: Move rename to ops struct")
Fixes: 2f1afe25997f ("cifs: Use smb 2 - 3 and cifsacl mount options getacl functions")
Fixes: 366ed846df60 ("cifs: Use smb 2 - 3 and cifsacl mount options setacl function")
Cc: stable@vger.kernel.org
Signed-off-by: Shuhao Fu <sfual@cse.ust.hk>
Signed-off-by: Steve French <stfrench@microsoft.com>
        tcon = tlink_tcon(tlink);
        server = tcon->ses->server;
 
-       if (!server->ops->rename)
-               return -ENOSYS;
+       if (!server->ops->rename) {
+               rc = -ENOSYS;
+               goto do_rename_exit;
+       }
 
        /* try path-based rename first */
        rc = server->ops->rename(xid, tcon, from_dentry,
 
        utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
        if (!utf16_path) {
                rc = -ENOMEM;
-               free_xid(xid);
-               return ERR_PTR(rc);
+               goto put_tlink;
        }
 
        oparms = (struct cifs_open_parms) {
                SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
        }
 
+put_tlink:
        cifs_put_tlink(tlink);
        free_xid(xid);
 
        utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
        if (!utf16_path) {
                rc = -ENOMEM;
-               free_xid(xid);
-               return rc;
+               goto put_tlink;
        }
 
        oparms = (struct cifs_open_parms) {
                SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
        }
 
+put_tlink:
        cifs_put_tlink(tlink);
        free_xid(xid);
        return rc;