drm/amdgpu: clean up the amdgpu_cs_parser_bos
Subsystems (2)
PATCH 1/1 drm/amdgpu: clean up the amdgpu_cs_parser_bos
In low memory conditions when kmalloc can fail and hence we need to clean up the memory and unlock the mutex for clean exit.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +4 -1
@@ -892,8 +892,11 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,struct amdgpu_bo *bo = e->bo; e->range =amdgpu_hmm_range_alloc (NULL ); -if (unlikely (!e->range)) +if (unlikely (!e->range)) { +mutex_unlock (&p->bo_list->bo_list_mutex); +amdgpu_bo_list_put (p->bo_list) return -ENOMEM; + } r =amdgpu_ttm_tt_get_user_pages (bo, e->range);if (r)
Signature · 1 line
2.34.1
Quoted 19 lines · Sunil Khatri
In low memory conditions when kmalloc can fail and hence we need to clean up the memory and unlock the mutex for clean exit.
Fixes 737da5363cc0 ("drm/amdgpu: update the functions to use amdgpu version of hmm")Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Signed-off-by Sunil Khatri <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, · line 898
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3
-1@@ -892,8 +892,11 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,struct amdgpu_bo *bo = e->bo; e->range =amdgpu_hmm_range_alloc (NULL ); -if (unlikely (!e->range)) +if (unlikely (!e->range)) { +mutex_unlock (&p->bo_list->bo_list_mutex); +amdgpu_bo_list_put (p->bo_list) return -ENOMEM;
I think this should probably be:
r = -ENOMEM;
goto out_free_user_pages;
Also, does that error path need amdgpu_bo_list_put()?
Alex
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1
-1+ } r =amdgpu_ttm_tt_get_user_pages (bo, e->range);if (r) --2.34.1
Quoted 21 lines · Alex Deucher
Quoted 20 lines · Sunil Khatri
In low memory conditions when kmalloc can fail and hence we need to clean up the memory and unlock the mutex for clean exit.
Fixes 737da5363cc0 ("drm/amdgpu: update the functions to use amdgpu version of hmm")Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Signed-off-by Sunil Khatri <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0
-0@@ -892,8 +892,11 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,struct amdgpu_bo *bo = e->bo;
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, · line 898
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3
-1e->range =amdgpu_hmm_range_alloc (NULL ); -if (unlikely (!e->range)) +if (unlikely (!e->range)) { +mutex_unlock (&p->bo_list->bo_list_mutex); +amdgpu_bo_list_put (p->bo_list) return -ENOMEM;I think this should probably be:
r =-ENOMEM;
gotoout_free_user_pages;
Agree, that's cleaner.
Quoted 2 lines
Also, does that error path need
amdgpu_bo_list_put()?
Yes we do need that i guess.
we are doing amdgpu_bo_list_get or amdgpu_bo_list_create which needs to be cleaned if we failed here. Let me push a new patch based on those changes.
Regards
Sunil Khatri
Quoted 10 lines
Alex
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1
-1+ } r =amdgpu_ttm_tt_get_user_pages (bo, e->range);if (r) --2.34.1
Christian König
maintainerQuoted 18 lines · Sunil Khatri
In low memory conditions when kmalloc can fail and hence we need to clean up the memory and unlock the mutex for clean exit.
Fixes 737da5363cc0 ("drm/amdgpu: update the functions to use amdgpu version of hmm")Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Signed-off-by Sunil Khatri <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, · line 898
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3
-1@@ -892,8 +892,11 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,struct amdgpu_bo *bo = e->bo; e->range =amdgpu_hmm_range_alloc (NULL ); -if (unlikely (!e->range)) +if (unlikely (!e->range)) { +mutex_unlock (&p->bo_list->bo_list_mutex); +amdgpu_bo_list_put (p->bo_list)
The call to amdgpu_bo_list_put() is always done by amdgpu_cs_parser_fini(), so that here would drop the reference twice.
Apart from that looks correct to me.
Regards,
Christian.
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1
-0return -ENOMEM ; + } r =amdgpu_ttm_tt_get_user_pages (bo, e->range);if (r)
Quoted 21 lines · Christian König
Quoted 20 lines · Sunil Khatri
In low memory conditions when kmalloc can fail and hence we need to clean up the memory and unlock the mutex for clean exit.
Fixes 737da5363cc0 ("drm/amdgpu: update the functions to use amdgpu version of hmm")Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Signed-off-by Sunil Khatri <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0
-0@@ -892,8 +892,11 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,struct amdgpu_bo *bo = e->bo;
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, · line 897
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3
-1e->range =amdgpu_hmm_range_alloc (NULL ); -if (unlikely (!e->range)) +if (unlikely (!e->range)) { +mutex_unlock (&p->bo_list->bo_list_mutex); +amdgpu_bo_list_put (p->bo_list)The call to
amdgpu_bo_list_put()is always done byamdgpu_cs_parser_fini(), so that here would drop the reference twice.
Ah yes, i dint realise it is freed in the parent function. Pushed V5 with final change as expected. Thanks
Sunil
Quoted 11 lines
Apart from that looks correct to me.
Regards,
Christian.Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1
-0return -ENOMEM ; + } r =amdgpu_ttm_tt_get_user_pages (bo, e->range);if (r)