OSDN Git Service

drm/amdgpu: add proper error handling to amdgpu_bo_list_get
authorChristian König <christian.koenig@amd.com>
Fri, 27 Jul 2018 13:32:04 +0000 (15:32 +0200)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 31 Jul 2018 21:58:16 +0000 (16:58 -0500)
Otherwise we silently don't use a BO list when the handle is invalid.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Chunming Zhou <david1.zhou@amd.com>
Reviewed-by: Huang Rui <ray.huang@amd.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu.h
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c

index 1f6345d..4d4d669 100644 (file)
@@ -713,8 +713,8 @@ struct amdgpu_bo_list {
        struct amdgpu_bo_list_entry *array;
 };
 
-struct amdgpu_bo_list *
-amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
+int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
+                      struct amdgpu_bo_list **result);
 void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
                             struct list_head *validated);
 void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
index 7679c06..944868e 100644 (file)
@@ -180,27 +180,20 @@ error_free:
        return r;
 }
 
-struct amdgpu_bo_list *
-amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id)
+int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
+                      struct amdgpu_bo_list **result)
 {
-       struct amdgpu_bo_list *result;
-
        rcu_read_lock();
-       result = idr_find(&fpriv->bo_list_handles, id);
+       *result = idr_find(&fpriv->bo_list_handles, id);
 
-       if (result) {
-               if (kref_get_unless_zero(&result->refcount)) {
-                       rcu_read_unlock();
-                       mutex_lock(&result->lock);
-               } else {
-                       rcu_read_unlock();
-                       result = NULL;
-               }
-       } else {
+       if (*result && kref_get_unless_zero(&(*result)->refcount)) {
                rcu_read_unlock();
+               mutex_lock(&(*result)->lock);
+               return 0;
        }
 
-       return result;
+       rcu_read_unlock();
+       return -ENOENT;
 }
 
 void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
@@ -335,9 +328,8 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
                break;
 
        case AMDGPU_BO_LIST_OP_UPDATE:
-               r = -ENOENT;
-               list = amdgpu_bo_list_get(fpriv, handle);
-               if (!list)
+               r = amdgpu_bo_list_get(fpriv, handle, &list);
+               if (r)
                        goto error_free;
 
                r = amdgpu_bo_list_set(adev, filp, list, info,
index 533b2e7..8a49c3b 100644 (file)
@@ -572,11 +572,16 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
        INIT_LIST_HEAD(&p->validated);
 
        /* p->bo_list could already be assigned if AMDGPU_CHUNK_ID_BO_HANDLES is present */
-       if (!p->bo_list)
-               p->bo_list = amdgpu_bo_list_get(fpriv, cs->in.bo_list_handle);
-       else
+       if (p->bo_list) {
                mutex_lock(&p->bo_list->lock);
 
+       } else if (cs->in.bo_list_handle) {
+               r = amdgpu_bo_list_get(fpriv, cs->in.bo_list_handle,
+                                      &p->bo_list);
+               if (r)
+                       return r;
+       }
+
        if (p->bo_list) {
                amdgpu_bo_list_get_list(p->bo_list, &p->validated);
                if (p->bo_list->first_userptr != p->bo_list->num_entries)