@@ -2600,9 +2600,8 @@ static int ext4_xattr_move_to_block(handle_t *handle, struct inode *inode,
2600
2600
2601
2601
is = kzalloc (sizeof (struct ext4_xattr_ibody_find ), GFP_NOFS );
2602
2602
bs = kzalloc (sizeof (struct ext4_xattr_block_find ), GFP_NOFS );
2603
- buffer = kvmalloc (value_size , GFP_NOFS );
2604
2603
b_entry_name = kmalloc (entry -> e_name_len + 1 , GFP_NOFS );
2605
- if (!is || !bs || !buffer || ! b_entry_name ) {
2604
+ if (!is || !bs || !b_entry_name ) {
2606
2605
error = - ENOMEM ;
2607
2606
goto out ;
2608
2607
}
@@ -2614,12 +2613,18 @@ static int ext4_xattr_move_to_block(handle_t *handle, struct inode *inode,
2614
2613
2615
2614
/* Save the entry name and the entry value */
2616
2615
if (entry -> e_value_inum ) {
2616
+ buffer = kvmalloc (value_size , GFP_NOFS );
2617
+ if (!buffer ) {
2618
+ error = - ENOMEM ;
2619
+ goto out ;
2620
+ }
2621
+
2617
2622
error = ext4_xattr_inode_get (inode , entry , buffer , value_size );
2618
2623
if (error )
2619
2624
goto out ;
2620
2625
} else {
2621
2626
size_t value_offs = le16_to_cpu (entry -> e_value_offs );
2622
- memcpy ( buffer , (void * )IFIRST (header ) + value_offs , value_size ) ;
2627
+ buffer = (void * )IFIRST (header ) + value_offs ;
2623
2628
}
2624
2629
2625
2630
memcpy (b_entry_name , entry -> e_name , entry -> e_name_len );
@@ -2634,25 +2639,26 @@ static int ext4_xattr_move_to_block(handle_t *handle, struct inode *inode,
2634
2639
if (error )
2635
2640
goto out ;
2636
2641
2637
- /* Remove the chosen entry from the inode */
2638
- error = ext4_xattr_ibody_set (handle , inode , & i , is );
2639
- if (error )
2640
- goto out ;
2641
-
2642
2642
i .value = buffer ;
2643
2643
i .value_len = value_size ;
2644
2644
error = ext4_xattr_block_find (inode , & i , bs );
2645
2645
if (error )
2646
2646
goto out ;
2647
2647
2648
- /* Add entry which was removed from the inode into the block */
2648
+ /* Move ea entry from the inode into the block */
2649
2649
error = ext4_xattr_block_set (handle , inode , & i , bs );
2650
2650
if (error )
2651
2651
goto out ;
2652
- error = 0 ;
2652
+
2653
+ /* Remove the chosen entry from the inode */
2654
+ i .value = NULL ;
2655
+ i .value_len = 0 ;
2656
+ error = ext4_xattr_ibody_set (handle , inode , & i , is );
2657
+
2653
2658
out :
2654
2659
kfree (b_entry_name );
2655
- kvfree (buffer );
2660
+ if (entry -> e_value_inum && buffer )
2661
+ kvfree (buffer );
2656
2662
if (is )
2657
2663
brelse (is -> iloc .bh );
2658
2664
if (bs )
0 commit comments