aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd
diff options
context:
space:
mode:
authorChristian König <christian.koenig@amd.com>2018-07-27 09:32:04 -0400
committerAlex Deucher <alexander.deucher@amd.com>2018-07-31 17:58:16 -0400
commit52c054caf83012fe9fe858ee86d90b4ea2cc3cca (patch)
tree614a12fd37355647ceef8c1bcc3455c695a2641f /drivers/gpu/drm/amd
parentccf9ef0b0d10434dec5046bcfc4e834a7b1830fd (diff)
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: 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>
Diffstat (limited to 'drivers/gpu/drm/amd')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu.h4
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c28
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c11
3 files changed, 20 insertions, 23 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 1f6345dda6ea..4d4d6697fbce 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -713,8 +713,8 @@ struct amdgpu_bo_list {
713 struct amdgpu_bo_list_entry *array; 713 struct amdgpu_bo_list_entry *array;
714}; 714};
715 715
716struct amdgpu_bo_list * 716int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
717amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id); 717 struct amdgpu_bo_list **result);
718void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list, 718void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
719 struct list_head *validated); 719 struct list_head *validated);
720void amdgpu_bo_list_put(struct amdgpu_bo_list *list); 720void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
index 7679c068c89a..944868e47119 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
@@ -180,27 +180,20 @@ error_free:
180 return r; 180 return r;
181} 181}
182 182
183struct amdgpu_bo_list * 183int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
184amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id) 184 struct amdgpu_bo_list **result)
185{ 185{
186 struct amdgpu_bo_list *result;
187
188 rcu_read_lock(); 186 rcu_read_lock();
189 result = idr_find(&fpriv->bo_list_handles, id); 187 *result = idr_find(&fpriv->bo_list_handles, id);
190 188
191 if (result) { 189 if (*result && kref_get_unless_zero(&(*result)->refcount)) {
192 if (kref_get_unless_zero(&result->refcount)) {
193 rcu_read_unlock();
194 mutex_lock(&result->lock);
195 } else {
196 rcu_read_unlock();
197 result = NULL;
198 }
199 } else {
200 rcu_read_unlock(); 190 rcu_read_unlock();
191 mutex_lock(&(*result)->lock);
192 return 0;
201 } 193 }
202 194
203 return result; 195 rcu_read_unlock();
196 return -ENOENT;
204} 197}
205 198
206void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list, 199void 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 break; 328 break;
336 329
337 case AMDGPU_BO_LIST_OP_UPDATE: 330 case AMDGPU_BO_LIST_OP_UPDATE:
338 r = -ENOENT; 331 r = amdgpu_bo_list_get(fpriv, handle, &list);
339 list = amdgpu_bo_list_get(fpriv, handle); 332 if (r)
340 if (!list)
341 goto error_free; 333 goto error_free;
342 334
343 r = amdgpu_bo_list_set(adev, filp, list, info, 335 r = amdgpu_bo_list_set(adev, filp, list, info,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 533b2e7656c0..8a49c3b97bd4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -572,11 +572,16 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
572 INIT_LIST_HEAD(&p->validated); 572 INIT_LIST_HEAD(&p->validated);
573 573
574 /* p->bo_list could already be assigned if AMDGPU_CHUNK_ID_BO_HANDLES is present */ 574 /* p->bo_list could already be assigned if AMDGPU_CHUNK_ID_BO_HANDLES is present */
575 if (!p->bo_list) 575 if (p->bo_list) {
576 p->bo_list = amdgpu_bo_list_get(fpriv, cs->in.bo_list_handle);
577 else
578 mutex_lock(&p->bo_list->lock); 576 mutex_lock(&p->bo_list->lock);
579 577
578 } else if (cs->in.bo_list_handle) {
579 r = amdgpu_bo_list_get(fpriv, cs->in.bo_list_handle,
580 &p->bo_list);
581 if (r)
582 return r;
583 }
584
580 if (p->bo_list) { 585 if (p->bo_list) {
581 amdgpu_bo_list_get_list(p->bo_list, &p->validated); 586 amdgpu_bo_list_get_list(p->bo_list, &p->validated);
582 if (p->bo_list->first_userptr != p->bo_list->num_entries) 587 if (p->bo_list->first_userptr != p->bo_list->num_entries)