Skip to content

Commit 74e0133

Browse files
Paulo AlcantaraSteve French
authored andcommitted
smb: client: reduce stack usage in smb2_query_reparse_point()
Clang warns about exceeded stack frame size fs/smb/client/smb2ops.c:2973:12: warning: stack frame size (1336) exceeds limit (1024) in 'smb2_query_reparse_point' [-Wframe-larger-than] Fix this by allocating a structure that will hold most of the large variables. Signed-off-by: Paulo Alcantara (SUSE) <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent b914875 commit 74e0133

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

fs/smb/client/smb2ops.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,19 +2965,17 @@ static int smb2_query_reparse_point(const unsigned int xid,
29652965
u32 *tag, struct kvec *rsp,
29662966
int *rsp_buftype)
29672967
{
2968+
struct smb2_compound_vars *vars;
29682969
int rc;
29692970
__le16 *utf16_path = NULL;
29702971
__u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
29712972
struct cifs_open_parms oparms;
29722973
struct cifs_fid fid;
29732974
struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
29742975
int flags = CIFS_CP_CREATE_CLOSE_OP;
2975-
struct smb_rqst rqst[3];
2976+
struct smb_rqst *rqst;
29762977
int resp_buftype[3];
2977-
struct kvec rsp_iov[3];
2978-
struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2979-
struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2980-
struct kvec close_iov[1];
2978+
struct kvec *rsp_iov;
29812979
struct smb2_ioctl_rsp *ioctl_rsp;
29822980
struct reparse_data_buffer *reparse_buf;
29832981
u32 plen;
@@ -2987,20 +2985,24 @@ static int smb2_query_reparse_point(const unsigned int xid,
29872985
if (smb3_encryption_required(tcon))
29882986
flags |= CIFS_TRANSFORM_REQ;
29892987

2990-
memset(rqst, 0, sizeof(rqst));
2991-
resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2992-
memset(rsp_iov, 0, sizeof(rsp_iov));
2993-
29942988
utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
29952989
if (!utf16_path)
29962990
return -ENOMEM;
29972991

2992+
resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2993+
vars = kzalloc(sizeof(*vars), GFP_KERNEL);
2994+
if (!vars) {
2995+
rc = -ENOMEM;
2996+
goto out_free_path;
2997+
}
2998+
rqst = vars->rqst;
2999+
rsp_iov = vars->rsp_iov;
3000+
29983001
/*
29993002
* setup smb2open - TODO add optimization to call cifs_get_readable_path
30003003
* to see if there is a handle already open that we can use
30013004
*/
3002-
memset(&open_iov, 0, sizeof(open_iov));
3003-
rqst[0].rq_iov = open_iov;
3005+
rqst[0].rq_iov = vars->open_iov;
30043006
rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
30053007

30063008
oparms = (struct cifs_open_parms) {
@@ -3020,8 +3022,7 @@ static int smb2_query_reparse_point(const unsigned int xid,
30203022

30213023

30223024
/* IOCTL */
3023-
memset(&io_iov, 0, sizeof(io_iov));
3024-
rqst[1].rq_iov = io_iov;
3025+
rqst[1].rq_iov = vars->io_iov;
30253026
rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
30263027

30273028
rc = SMB2_ioctl_init(tcon, server,
@@ -3036,10 +3037,8 @@ static int smb2_query_reparse_point(const unsigned int xid,
30363037
smb2_set_next_command(tcon, &rqst[1]);
30373038
smb2_set_related(&rqst[1]);
30383039

3039-
30403040
/* Close */
3041-
memset(&close_iov, 0, sizeof(close_iov));
3042-
rqst[2].rq_iov = close_iov;
3041+
rqst[2].rq_iov = &vars->close_iov;
30433042
rqst[2].rq_nvec = 1;
30443043

30453044
rc = SMB2_close_init(tcon, server,
@@ -3080,13 +3079,15 @@ static int smb2_query_reparse_point(const unsigned int xid,
30803079
}
30813080

30823081
query_rp_exit:
3083-
kfree(utf16_path);
30843082
SMB2_open_free(&rqst[0]);
30853083
SMB2_ioctl_free(&rqst[1]);
30863084
SMB2_close_free(&rqst[2]);
30873085
free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
30883086
free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
30893087
free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3088+
kfree(vars);
3089+
out_free_path:
3090+
kfree(utf16_path);
30903091
return rc;
30913092
}
30923093

0 commit comments

Comments
 (0)