@@ -133,7 +133,8 @@ nfs_closedir(struct inode *inode, struct file *filp)
133133struct nfs_cache_array_entry {
134134 u64 cookie ;
135135 u64 ino ;
136- struct qstr string ;
136+ const char * name ;
137+ unsigned int name_len ;
137138 unsigned char d_type ;
138139};
139140
@@ -192,7 +193,7 @@ void nfs_readdir_clear_array(struct page *page)
192193
193194 array = kmap_atomic (page );
194195 for (i = 0 ; i < array -> size ; i ++ )
195- kfree (array -> array [i ].string . name );
196+ kfree (array -> array [i ].name );
196197 nfs_readdir_array_init (array );
197198 kunmap_atomic (array );
198199}
@@ -213,20 +214,17 @@ static bool nfs_readdir_array_is_full(struct nfs_cache_array *array)
213214 * when called by nfs_readdir_add_to_array, the strings will be freed in
214215 * nfs_clear_readdir_array()
215216 */
216- static
217- int nfs_readdir_make_qstr (struct qstr * string , const char * name , unsigned int len )
217+ static const char * nfs_readdir_copy_name (const char * name , unsigned int len )
218218{
219- string -> len = len ;
220- string -> name = kmemdup_nul (name , len , GFP_KERNEL );
221- if (string -> name == NULL )
222- return - ENOMEM ;
219+ const char * ret = kmemdup_nul (name , len , GFP_KERNEL );
220+
223221 /*
224222 * Avoid a kmemleak false positive. The pointer to the name is stored
225223 * in a page cache page which kmemleak does not scan.
226224 */
227- kmemleak_not_leak ( string -> name );
228- string -> hash = full_name_hash ( NULL , name , len );
229- return 0 ;
225+ if ( ret != NULL )
226+ kmemleak_not_leak ( ret );
227+ return ret ;
230228}
231229
232230/*
@@ -249,27 +247,34 @@ static int nfs_readdir_array_can_expand(struct nfs_cache_array *array)
249247static
250248int nfs_readdir_add_to_array (struct nfs_entry * entry , struct page * page )
251249{
252- struct nfs_cache_array * array = kmap ( page ) ;
250+ struct nfs_cache_array * array ;
253251 struct nfs_cache_array_entry * cache_entry ;
252+ const char * name ;
254253 int ret ;
255254
255+ name = nfs_readdir_copy_name (entry -> name , entry -> len );
256+ if (!name )
257+ return - ENOMEM ;
258+
259+ array = kmap_atomic (page );
256260 ret = nfs_readdir_array_can_expand (array );
257- if (ret )
261+ if (ret ) {
262+ kfree (name );
258263 goto out ;
264+ }
259265
260266 cache_entry = & array -> array [array -> size ];
261267 cache_entry -> cookie = entry -> prev_cookie ;
262268 cache_entry -> ino = entry -> ino ;
263269 cache_entry -> d_type = entry -> d_type ;
264- ret = nfs_readdir_make_qstr (& cache_entry -> string , entry -> name , entry -> len );
265- if (ret )
266- goto out ;
270+ cache_entry -> name_len = entry -> len ;
271+ cache_entry -> name = name ;
267272 array -> last_cookie = entry -> cookie ;
268273 array -> size ++ ;
269274 if (entry -> eof != 0 )
270275 nfs_readdir_array_set_eof (array );
271276out :
272- kunmap ( page );
277+ kunmap_atomic ( array );
273278 return ret ;
274279}
275280
@@ -413,9 +418,8 @@ int nfs_readdir_search_for_cookie(struct nfs_cache_array *array, nfs_readdir_des
413418 if (printk_ratelimit ()) {
414419 pr_notice ("NFS: directory %pD2 contains a readdir loop."
415420 "Please contact your server vendor. "
416- "The file: %.*s has duplicate cookie %llu\n" ,
417- desc -> file , array -> array [i ].string .len ,
418- array -> array [i ].string .name , desc -> dir_cookie );
421+ "The file: %s has duplicate cookie %llu\n" ,
422+ desc -> file , array -> array [i ].name , desc -> dir_cookie );
419423 }
420424 status = - ELOOP ;
421425 goto out ;
@@ -888,7 +892,7 @@ int nfs_do_filldir(nfs_readdir_descriptor_t *desc)
888892 struct nfs_cache_array_entry * ent ;
889893
890894 ent = & array -> array [i ];
891- if (!dir_emit (desc -> ctx , ent -> string . name , ent -> string . len ,
895+ if (!dir_emit (desc -> ctx , ent -> name , ent -> name_len ,
892896 nfs_compat_user_ino64 (ent -> ino ), ent -> d_type )) {
893897 desc -> eof = true;
894898 break ;
0 commit comments