[Intel-gfx] [PATCH 2/3] drm/vgem: Enable dmabuf interface for export

Chris Wilson chris at chris-wilson.co.uk
Fri Jul 1 20:13:42 UTC 2016


On Fri, Jul 01, 2016 at 05:56:25PM +0100, Matthew Auld wrote:
> > +static struct sg_table *vgem_prime_get_sg_table(struct drm_gem_object *obj)
> > +{
> > +       long n_pages = obj->size >> PAGE_SHIFT;
> > +       struct sg_table *st;
> > +       struct page **pages;
> > +       int ret;
> > +
> > +       st = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
> > +       if (st == NULL)
> > +               return ERR_PTR(-ENOMEM);
> > +
> > +       pages = drm_gem_get_pages(obj);
> > +       if (IS_ERR(pages)) {
> > +               ret = PTR_ERR(pages);
> > +               goto err;
> > +       }
> > +
> > +       ret = sg_alloc_table_from_pages(st, pages, n_pages,
> > +                                       0, obj->size, GFP_KERNEL);
> > +       drm_gem_put_pages(obj, pages, false, false);
> > +       if (ret)
> > +               goto err;
> > +
> > +       return st;
> > +
> > +err:
> > +       kfree(st);
> > +       return ERR_PTR(ret);
> > +}
> > +
> Couldn't this be written more simply as:
> 
> pages = drm_gem_get_pages(obj);
> if (IS_ERR(pages))
>         return ERR_CAST(pages);
> 
> st = drm_prime_pages_to_sg(pages, n_pages);
> drm_gem_put_pages(obj, pages, false, false);
> 
> return st;

That looks better, thanks.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre


More information about the dri-devel mailing list