[PATCH 4/5] cifs: Make cifs_readdir use the helpers

Suresh Jayaraman <[email protected]>
Newsgroups gmane.linux.file-systems.cifs
Message-ID <[email protected]>
We need to get the string from current_entry before calling
UniStrnlenBytes()

Signed-off-by: Suresh Jayaraman <[email protected]>
---
 fs/cifs/readdir.c |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)

Index: cifs-2.6.git/fs/cifs/readdir.c
===================================================================
--- cifs-2.6.git.orig/fs/cifs/readdir.c
+++ cifs-2.6.git/fs/cifs/readdir.c
@@ -995,8 +995,10 @@ int cifs_readdir(struct file *file, void
 	char *current_entry;
 	int num_to_fill = 0;
 	char *tmp_buf = NULL;
-	char *end_of_smb;
-	int max_len;
+	char *end_of_smb, *filename;
+	int max_len, nchars;
+	size_t nbytes;
+	FILE_UNIX_INFO *punix_info;
 
 	xid = GetXid();
 
@@ -1070,11 +1072,12 @@ int cifs_readdir(struct file *file, void
 				cifsFile->srch_inf.ntwrk_buf_start);
 		end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + max_len;
 
-		/* To be safe - for UCS to UTF-8 with strings loaded
-		with the rare long characters alloc more to account for
-		such multibyte target UTF-8 characters. cifs_unicode.c,
-		which actually does the conversion, has the same limit */
-		tmp_buf = kmalloc((2 * NAME_MAX) + 4, GFP_KERNEL);
+		/* compute the actual length in bytes required and use it */
+		punix_info = (FILE_UNIX_INFO *)current_entry;
+		filename = &punix_info->FileName[0];
+		nbytes = UniStrnlenBytes((wchar_t *)filename, 2*NAME_MAX,
+				&nchars, cifs_sb->local_nls);
+		tmp_buf = kmalloc(nbytes + 2, GFP_KERNEL);
 		for (i = 0; (i < num_to_fill) && (rc == 0); i++) {
 			if (current_entry == NULL) {
 				/* evaluate whether this case is an error */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.