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

Matthew Auld matthew.william.auld at gmail.com
Fri Jul 1 16:56:25 UTC 2016


> +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;

But either way:
Reviewed-by: Matthew Auld <matthew.auld at intel.com>


More information about the Intel-gfx mailing list