On 5/4/2023 10:34 AM, Jason Gunthorpe wrote:
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
On Fri, Apr 21, 2023 at 06:06:39PM -0700, Brett Creeley wrote:
+static struct pds_vfio_lm_file *
+pds_vfio_get_lm_file(const struct file_operations *fops, int flags, u64 size)
+{
+ struct pds_vfio_lm_file *lm_file = NULL;
+ unsigned long long npages;
+ struct page **pages;
+ int err = 0;
+
+ if (!size)
+ return NULL;
+
+ /* Alloc file structure */
+ lm_file = kzalloc(sizeof(*lm_file), GFP_KERNEL);
+ if (!lm_file)
+ return NULL;
+
+ /* Create file */
+ lm_file->filep = anon_inode_getfile("pds_vfio_lm", fops, lm_file, flags);
+ if (!lm_file->filep)
+ goto err_get_file;
+
+ stream_open(lm_file->filep->f_inode, lm_file->filep);
+ mutex_init(&lm_file->lock);
+
+ lm_file->size = size;
+
+ /* Allocate memory for file pages */
+ npages = DIV_ROUND_UP_ULL(lm_file->size, PAGE_SIZE);
+
+ pages = kcalloc(npages, sizeof(*pages), GFP_KERNEL);
+ if (!pages)
+ goto err_alloc_pages;
+
+ for (unsigned long long i = 0; i < npages; i++) {
+ pages[i] = alloc_page(GFP_KERNEL);
+ if (!pages[i])
+ goto err_alloc_page;
+ }
+
+ lm_file->pages = pages;
+ lm_file->npages = npages;
+ lm_file->alloc_size = npages * PAGE_SIZE;
+
+ /* Create scatterlist of file pages to use for DMA mapping later */
+ err = sg_alloc_table_from_pages(&lm_file->sg_table, pages, npages,
+ 0, size, GFP_KERNEL);
+ if (err)
+ goto err_alloc_sg_table;
+
+ /* prevent file from being released before we are done with it */
+ get_file(lm_file->filep);
+
+ return lm_file;
+
+err_alloc_sg_table:
+err_alloc_page:
What is with these double error out labels? I see it in a few places,
that is not the kernel style.
In VFIO we have been trying to label the err outs based on what they
free, it is not a 'call from' scheme.
Jason
Yeah this is kind of ugly. Thanks for pointing it out. I will fix it and
any other occurrences in the next revision.
Brett