@@ -242,19 +242,17 @@ static int shmem_radix_tree_replace(struct address_space *mapping,
242
242
pgoff_t index , void * expected , void * replacement )
243
243
{
244
244
void * * pslot ;
245
- void * item = NULL ;
245
+ void * item ;
246
246
247
247
VM_BUG_ON (!expected );
248
+ VM_BUG_ON (!replacement );
248
249
pslot = radix_tree_lookup_slot (& mapping -> page_tree , index );
249
- if (pslot )
250
- item = radix_tree_deref_slot_protected ( pslot ,
251
- & mapping -> tree_lock );
250
+ if (! pslot )
251
+ return - ENOENT ;
252
+ item = radix_tree_deref_slot_protected ( pslot , & mapping -> tree_lock );
252
253
if (item != expected )
253
254
return - ENOENT ;
254
- if (replacement )
255
- radix_tree_replace_slot (pslot , replacement );
256
- else
257
- radix_tree_delete (& mapping -> page_tree , index );
255
+ radix_tree_replace_slot (pslot , replacement );
258
256
return 0 ;
259
257
}
260
258
@@ -386,14 +384,15 @@ static unsigned shmem_find_get_pages_and_swap(struct address_space *mapping,
386
384
static int shmem_free_swap (struct address_space * mapping ,
387
385
pgoff_t index , void * radswap )
388
386
{
389
- int error ;
387
+ void * old ;
390
388
391
389
spin_lock_irq (& mapping -> tree_lock );
392
- error = shmem_radix_tree_replace ( mapping , index , radswap , NULL );
390
+ old = radix_tree_delete_item ( & mapping -> page_tree , index , radswap );
393
391
spin_unlock_irq (& mapping -> tree_lock );
394
- if (!error )
395
- free_swap_and_cache (radix_to_swp_entry (radswap ));
396
- return error ;
392
+ if (old != radswap )
393
+ return - ENOENT ;
394
+ free_swap_and_cache (radix_to_swp_entry (radswap ));
395
+ return 0 ;
397
396
}
398
397
399
398
/*
0 commit comments