clear_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags);
 }
 
+static void pnfs_clear_layoutreturn_waitbit(struct pnfs_layout_hdr *lo)
+{
+       clear_bit_unlock(NFS_LAYOUT_RETURN, &lo->plh_flags);
+       clear_bit(NFS_LAYOUT_RETURN_LOCK, &lo->plh_flags);
+       smp_mb__after_atomic();
+       wake_up_bit(&lo->plh_flags, NFS_LAYOUT_RETURN);
+       rpc_wake_up(&NFS_SERVER(lo->plh_inode)->roc_rpcwaitq);
+}
+
 static void
 pnfs_clear_lseg_state(struct pnfs_layout_segment *lseg,
                struct list_head *free_me)
        list_for_each_entry_safe(lseg, next, &lo->plh_segs, pls_list)
                pnfs_clear_lseg_state(lseg, lseg_list);
        pnfs_free_returned_lsegs(lo, lseg_list, &range, 0);
+       if (test_bit(NFS_LAYOUT_RETURN, &lo->plh_flags) &&
+           !test_and_set_bit(NFS_LAYOUT_RETURN_LOCK, &lo->plh_flags))
+               pnfs_clear_layoutreturn_waitbit(lo);
        return !list_empty(&lo->plh_segs);
 }
 
        }
 }
 
-static void pnfs_clear_layoutreturn_waitbit(struct pnfs_layout_hdr *lo)
-{
-       clear_bit_unlock(NFS_LAYOUT_RETURN, &lo->plh_flags);
-       clear_bit(NFS_LAYOUT_RETURN_LOCK, &lo->plh_flags);
-       smp_mb__after_atomic();
-       wake_up_bit(&lo->plh_flags, NFS_LAYOUT_RETURN);
-       rpc_wake_up(&NFS_SERVER(lo->plh_inode)->roc_rpcwaitq);
-}
-
 void pnfs_layoutreturn_free_lsegs(struct pnfs_layout_hdr *lo,
                const nfs4_stateid *arg_stateid,
                const struct pnfs_layout_range *range,