@@ -226,15 +226,18 @@ static inline const struct xattr_handler *f2fs_xattr_handler(int index)
226226}
227227
228228static struct f2fs_xattr_entry * __find_xattr (void * base_addr ,
229- void * last_base_addr , int index ,
230- size_t len , const char * name )
229+ void * last_base_addr , void * * last_addr ,
230+ int index , size_t len , const char * name )
231231{
232232 struct f2fs_xattr_entry * entry ;
233233
234234 list_for_each_xattr (entry , base_addr ) {
235235 if ((void * )(entry ) + sizeof (__u32 ) > last_base_addr ||
236- (void * )XATTR_NEXT_ENTRY (entry ) > last_base_addr )
236+ (void * )XATTR_NEXT_ENTRY (entry ) > last_base_addr ) {
237+ if (last_addr )
238+ * last_addr = entry ;
237239 return NULL ;
240+ }
238241
239242 if (entry -> e_name_index != index )
240243 continue ;
@@ -254,19 +257,9 @@ static struct f2fs_xattr_entry *__find_inline_xattr(struct inode *inode,
254257 unsigned int inline_size = inline_xattr_size (inode );
255258 void * max_addr = base_addr + inline_size ;
256259
257- list_for_each_xattr (entry , base_addr ) {
258- if ((void * )entry + sizeof (__u32 ) > max_addr ||
259- (void * )XATTR_NEXT_ENTRY (entry ) > max_addr ) {
260- * last_addr = entry ;
261- return NULL ;
262- }
263- if (entry -> e_name_index != index )
264- continue ;
265- if (entry -> e_name_len != len )
266- continue ;
267- if (!memcmp (entry -> e_name , name , len ))
268- break ;
269- }
260+ entry = __find_xattr (base_addr , max_addr , last_addr , index , len , name );
261+ if (!entry )
262+ return NULL ;
270263
271264 /* inline xattr header or entry across max inline xattr size */
272265 if (IS_XATTR_LAST_ENTRY (entry ) &&
@@ -368,7 +361,7 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage,
368361 else
369362 cur_addr = txattr_addr ;
370363
371- * xe = __find_xattr (cur_addr , last_txattr_addr , index , len , name );
364+ * xe = __find_xattr (cur_addr , last_txattr_addr , NULL , index , len , name );
372365 if (!* xe ) {
373366 f2fs_err (F2FS_I_SB (inode ), "inode (%lu) has corrupted xattr" ,
374367 inode -> i_ino );
@@ -659,7 +652,7 @@ static int __f2fs_setxattr(struct inode *inode, int index,
659652 last_base_addr = (void * )base_addr + XATTR_SIZE (inode );
660653
661654 /* find entry with wanted name. */
662- here = __find_xattr (base_addr , last_base_addr , index , len , name );
655+ here = __find_xattr (base_addr , last_base_addr , NULL , index , len , name );
663656 if (!here ) {
664657 f2fs_err (F2FS_I_SB (inode ), "inode (%lu) has corrupted xattr" ,
665658 inode -> i_ino );
0 commit comments