diff --git a/mm/swapfile.c b/mm/swapfile.c index 2d2df53fc51a..c2af13eb15b3 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -635,6 +635,10 @@ static struct swap_cluster_info *isolate_lock_cluster( u8 flags = CLUSTER_FLAG_NONE; spin_lock(&si->lock); + + if (unlikely(!(si->flags & SWP_WRITEOK))) + goto out; + list_for_each_entry(ci, list, list) { if (!spin_trylock(&ci->lock)) continue; @@ -650,6 +654,7 @@ static struct swap_cluster_info *isolate_lock_cluster( found = ci; break; } +out: spin_unlock(&si->lock); /* Cluster's table is freed when and only when it's on the free list. */