summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/drm_gem_shmem_helper.c
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2020-05-11 12:35:53 +0300
committerDaniel Vetter <daniel.vetter@ffwll.ch>2020-06-08 18:03:41 +0300
commit5264083573184aba8a0e760f6ebb902326e40162 (patch)
treefdd2da7af9f724e464b9d6012f039955709bc497 /drivers/gpu/drm/drm_gem_shmem_helper.c
parent6e60d5ded06baa69cca0b6337053c99b54211624 (diff)
downloadlinux-5264083573184aba8a0e760f6ebb902326e40162.tar.xz
drm/shmem-helpers: Ensure get_pages is not called on imported dma-buf
Just a bit of light paranoia. Also sprinkle this check over drm_gem_shmem_get_sg_table, which should only be called when exporting, same for the pin/unpin functions, on which it relies to work correctly. Acked-by: Thomas Zimmermann <tzimmermann@suse.de> Tested-by: Boris Brezillon <boris.brezillon@collabora.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: Rob Herring <robh@kernel.org> Cc: Noralf Trønnes <noralf@tronnes.org> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20200511093554.211493-9-daniel.vetter@ffwll.ch
Diffstat (limited to 'drivers/gpu/drm/drm_gem_shmem_helper.c')
-rw-r--r--drivers/gpu/drm/drm_gem_shmem_helper.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
index afe9668f1750..06cee8e97d27 100644
--- a/drivers/gpu/drm/drm_gem_shmem_helper.c
+++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
@@ -170,6 +170,8 @@ int drm_gem_shmem_get_pages(struct drm_gem_shmem_object *shmem)
{
int ret;
+ WARN_ON(shmem->base.import_attach);
+
ret = mutex_lock_interruptible(&shmem->pages_lock);
if (ret)
return ret;
@@ -225,6 +227,8 @@ int drm_gem_shmem_pin(struct drm_gem_object *obj)
{
struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
+ WARN_ON(shmem->base.import_attach);
+
return drm_gem_shmem_get_pages(shmem);
}
EXPORT_SYMBOL(drm_gem_shmem_pin);
@@ -240,6 +244,8 @@ void drm_gem_shmem_unpin(struct drm_gem_object *obj)
{
struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
+ WARN_ON(shmem->base.import_attach);
+
drm_gem_shmem_put_pages(shmem);
}
EXPORT_SYMBOL(drm_gem_shmem_unpin);
@@ -510,6 +516,8 @@ static void drm_gem_shmem_vm_open(struct vm_area_struct *vma)
struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
int ret;
+ WARN_ON(shmem->base.import_attach);
+
ret = drm_gem_shmem_get_pages(shmem);
WARN_ON_ONCE(ret != 0);
@@ -611,6 +619,8 @@ struct sg_table *drm_gem_shmem_get_sg_table(struct drm_gem_object *obj)
{
struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
+ WARN_ON(shmem->base.import_attach);
+
return drm_prime_pages_to_sg(shmem->pages, obj->size >> PAGE_SHIFT);
}
EXPORT_SYMBOL_GPL(drm_gem_shmem_get_sg_table);