pret = pin_user_pages(ubuf, nr_pages, FOLL_WRITE | FOLL_LONGTERM,
                              pages, vmas);
        if (pret == nr_pages) {
-               struct file *file = vmas[0]->vm_file;
-
                /* don't support file backed memory */
                for (i = 0; i < nr_pages; i++) {
-                       if (vmas[i]->vm_file != file) {
-                               ret = -EINVAL;
-                               break;
-                       }
-                       if (!file)
+                       struct vm_area_struct *vma = vmas[i];
+
+                       if (vma_is_shmem(vma))
                                continue;
-                       if (!vma_is_shmem(vmas[i]) && !is_file_hugepages(file)) {
+                       if (vma->vm_file &&
+                           !is_file_hugepages(vma->vm_file)) {
                                ret = -EOPNOTSUPP;
                                break;
                        }