> + if (ubuf->subpgoff) { > + pfn += ubuf->subpgoff[pgoff] >> PAGE_SHIFT; > + } No need for the braces here.. > @@ -253,16 +271,59 @@ static long udmabuf_create(struct miscdevice *device, > goto err; > pgoff = list[i].offset >> PAGE_SHIFT; > pgcnt = list[i].size >> PAGE_SHIFT; > + if (is_file_hugepages(memfd)) { > + if (!ubuf->subpgoff) { > + ubuf->subpgoff = kmalloc_array(ubuf->pagecount, > + sizeof(*ubuf->subpgoff), Overly long line here. Given how much code there is in the main loop here this almost screams for splitting that into a helper anyay. And then the body of the pgidx loop below which is compeltely different for hugetlb vs not ask for another helper each for the loop body variants.