struct cma_heap_buffer *buffer = dmabuf->priv;
        struct dma_heap_attachment *a;
 
+       mutex_lock(&buffer->lock);
+
        if (buffer->vmap_cnt)
                invalidate_kernel_vmap_range(buffer->vaddr, buffer->len);
 
-       mutex_lock(&buffer->lock);
        list_for_each_entry(a, &buffer->attachments, list) {
                if (!a->mapped)
                        continue;
        struct cma_heap_buffer *buffer = dmabuf->priv;
        struct dma_heap_attachment *a;
 
+       mutex_lock(&buffer->lock);
+
        if (buffer->vmap_cnt)
                flush_kernel_vmap_range(buffer->vaddr, buffer->len);
 
-       mutex_lock(&buffer->lock);
        list_for_each_entry(a, &buffer->attachments, list) {
                if (!a->mapped)
                        continue;