[PATCH RFC] fs/smb : fix build warning in cifs_open()

Abinash Singh posted 1 patch 3 months ago
fs/smb/client/file.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
[PATCH RFC] fs/smb : fix build warning in cifs_open()
Posted by Abinash Singh 3 months ago
The function `cifs_open()` triggers
a large stack frame warning:
ld.lld: warning:
	fs/smb/client/file.c:949:0: stack frame size (1032) exceeds limit (1024) in function 'cifs_open'

Fix excess stack usgae by dynamically allocating `cifs_pending_open` struct.

Signed-off-by: Abinash Singh <abinashsinghlalotra@gmail.com>
---
It only reduces only 40 bytes.But we can reduce it more
by allocating other structs on heap.
This is fine if this function is not performance critical,
Is it ?

Thank You
---
 fs/smb/client/file.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
index e9212da32f01..818a3c1e6c72 100644
--- a/fs/smb/client/file.c
+++ b/fs/smb/client/file.c
@@ -959,9 +959,13 @@ int cifs_open(struct inode *inode, struct file *file)
 	const char *full_path;
 	bool posix_open_ok = false;
 	struct cifs_fid fid = {};
-	struct cifs_pending_open open;
+	struct cifs_pending_open *open __free(kfree) = NULL;
 	struct cifs_open_info_data data = {};
 
+	open = kmalloc(sizeof(*open),GFP_KERNEL);
+	if (!open)
+		return -ENOMEM;
+
 	xid = get_xid();
 
 	cifs_sb = CIFS_SB(inode->i_sb);
@@ -1057,7 +1061,7 @@ int cifs_open(struct inode *inode, struct file *file)
 	if (server->ops->get_lease_key)
 		server->ops->get_lease_key(inode, &fid);
 
-	cifs_add_pending_open(&fid, tlink, &open);
+	cifs_add_pending_open(&fid, tlink, open);
 
 	if (!posix_open_ok) {
 		if (server->ops->get_lease_key)
@@ -1066,7 +1070,7 @@ int cifs_open(struct inode *inode, struct file *file)
 		rc = cifs_nt_open(full_path, inode, cifs_sb, tcon, file->f_flags, &oplock, &fid,
 				  xid, &data);
 		if (rc) {
-			cifs_del_pending_open(&open);
+			cifs_del_pending_open(open);
 			goto out;
 		}
 	}
@@ -1075,7 +1079,7 @@ int cifs_open(struct inode *inode, struct file *file)
 	if (cfile == NULL) {
 		if (server->ops->close)
 			server->ops->close(xid, tcon, &fid);
-		cifs_del_pending_open(&open);
+		cifs_del_pending_open(open);
 		rc = -ENOMEM;
 		goto out;
 	}
-- 
2.43.0