提交 52c054ca 编写于 作者: C Christian König 提交者: Alex Deucher

drm/amdgpu: add proper error handling to amdgpu_bo_list_get

Otherwise we silently don't use a BO list when the handle is invalid.
Signed-off-by: NChristian König <christian.koenig@amd.com>
Reviewed-by: NChunming Zhou <david1.zhou@amd.com>
Reviewed-by: NHuang Rui <ray.huang@amd.com>
Reviewed-by: NMichel Dänzer <michel.daenzer@amd.com>
Signed-off-by: NAlex Deucher <alexander.deucher@amd.com>
上级 ccf9ef0b
...@@ -713,8 +713,8 @@ struct amdgpu_bo_list { ...@@ -713,8 +713,8 @@ struct amdgpu_bo_list {
struct amdgpu_bo_list_entry *array; struct amdgpu_bo_list_entry *array;
}; };
struct amdgpu_bo_list * int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
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, void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
struct list_head *validated); struct list_head *validated);
void amdgpu_bo_list_put(struct amdgpu_bo_list *list); void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
......
...@@ -180,27 +180,20 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev, ...@@ -180,27 +180,20 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,
return r; return r;
} }
struct amdgpu_bo_list * int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id) struct amdgpu_bo_list **result)
{ {
struct amdgpu_bo_list *result;
rcu_read_lock(); rcu_read_lock();
result = idr_find(&fpriv->bo_list_handles, id); *result = idr_find(&fpriv->bo_list_handles, id);
if (result) { if (*result && kref_get_unless_zero(&(*result)->refcount)) {
if (kref_get_unless_zero(&result->refcount)) {
rcu_read_unlock();
mutex_lock(&result->lock);
} else {
rcu_read_unlock();
result = NULL;
}
} else {
rcu_read_unlock(); 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, 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, ...@@ -335,9 +328,8 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
break; break;
case AMDGPU_BO_LIST_OP_UPDATE: case AMDGPU_BO_LIST_OP_UPDATE:
r = -ENOENT; r = amdgpu_bo_list_get(fpriv, handle, &list);
list = amdgpu_bo_list_get(fpriv, handle); if (r)
if (!list)
goto error_free; goto error_free;
r = amdgpu_bo_list_set(adev, filp, list, info, r = amdgpu_bo_list_set(adev, filp, list, info,
......
...@@ -572,11 +572,16 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, ...@@ -572,11 +572,16 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
INIT_LIST_HEAD(&p->validated); INIT_LIST_HEAD(&p->validated);
/* p->bo_list could already be assigned if AMDGPU_CHUNK_ID_BO_HANDLES is present */ /* p->bo_list could already be assigned if AMDGPU_CHUNK_ID_BO_HANDLES is present */
if (!p->bo_list) if (p->bo_list) {
p->bo_list = amdgpu_bo_list_get(fpriv, cs->in.bo_list_handle);
else
mutex_lock(&p->bo_list->lock); 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) { if (p->bo_list) {
amdgpu_bo_list_get_list(p->bo_list, &p->validated); amdgpu_bo_list_get_list(p->bo_list, &p->validated);
if (p->bo_list->first_userptr != p->bo_list->num_entries) if (p->bo_list->first_userptr != p->bo_list->num_entries)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册