Otherwise creating a _NO_SHARE BO before any BOs are mapped could cause
a NPE.

Reported-by: Sashiko <[email protected]>
Fixes: b58e12a66e47 ("drm/msm: Add _NO_SHARE flag")
Signed-off-by: Rob Clark <[email protected]>
---
 drivers/gpu/drm/msm/msm_gem.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
index efd3d3c9a449..3ff0399c020e 100644
--- a/drivers/gpu/drm/msm/msm_gem.c
+++ b/drivers/gpu/drm/msm/msm_gem.c
@@ -1147,7 +1147,14 @@ int msm_gem_new_handle(struct drm_device *dev, struct 
drm_file *file,
 
        if (flags & MSM_BO_NO_SHARE) {
                struct msm_context *ctx = file->driver_priv;
-               struct drm_gem_object *r_obj = drm_gpuvm_resv_obj(ctx->vm);
+               struct drm_gpuvm *vm = msm_context_vm(dev, ctx);
+
+               if (!vm) {
+                       ret = UERR(EINVAL, dev, "not supported with shared VM");
+                       goto out_put;
+               }
+
+               struct drm_gem_object *r_obj = drm_gpuvm_resv_obj(vm);
 
                drm_gem_object_get(r_obj);
 
@@ -1157,6 +1164,7 @@ int msm_gem_new_handle(struct drm_device *dev, struct 
drm_file *file,
        ret = drm_gem_handle_create(file, obj, handle);
 
        /* drop reference from allocate - handle holds it now */
+out_put:
        drm_gem_object_put(obj);
 
        return ret;
-- 
2.54.0

Reply via email to