accel/amdxdna: fix open_ref leak and stale client pointer on dma map failure
Lizhi Hou
maintainerPATCH 1/1 accel/amdxdna: fix open_ref leak and stale client pointer on dma map failure
amdxdna_gem_obj_open() increments open_ref before attempting to set up the DMA address mapping. When amdxdna_dma_map_bo() fails, the function returned immediately without rolling back either change made on the first open (open_ref == 1 path).
Fix it by decrementing open_ref and clearing abo->client on the error path.
--- drivers/accel/amdxdna/amdxdna_gem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/accel/amdxdna/amdxdna_gem.c +4 -1
@@ -663,8 +663,11 @@ static int amdxdna_gem_obj_open(struct drm_gem_object *gobj, struct drm_file *fi/* No need to set up dma addr mapping in PASID mode. */ if (!amdxdna_pasid_on (abo->client)) { ret =amdxdna_dma_map_bo (xdna, abo); -if (ret) +if (ret) { + abo->open_ref--; + abo->client =NULL ;return ret; + } }amdxdna_gem_add_bo_usage (abo);
Signature · 1 line
2.34.1
Quoted 9 lines · Lizhi Hou
amdxdna_gem_obj_open()incrementsopen_refbefore attempting to set up the DMA address mapping. Whenamdxdna_dma_map_bo()fails, the function returned immediately without rolling back either change made on the first open (open_ref== 1 path).Fix it by decrementing
open_refand clearingabo->clienton the error path.Fixes ece3e8980907 ("accel/amdxdna: Allow forcing IOVA-based DMA via module parameter")Signed-off-by Lizhi Hou <[email protected]>
Quoted 21 lines
--- drivers/accel/amdxdna/amdxdna_gem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/accel/amdxdna/amdxdna_gem.c +4
-1@@ -663,8 +663,11 @@ static int amdxdna_gem_obj_open(struct drm_gem_object *gobj, struct drm_file *fi/* No need to set up dma addr mapping in PASID mode. */ if (!amdxdna_pasid_on (abo->client)) { ret =amdxdna_dma_map_bo (xdna, abo); -if (ret) +if (ret) { + abo->open_ref--; + abo->client =NULL ;return ret; + } }amdxdna_gem_add_bo_usage (abo);
Applied to drm-misc-fixes
Quoted 35 lines · Max Zhen
Quoted 9 lines · Lizhi Hou
amdxdna_gem_obj_open()incrementsopen_refbefore attempting to set up the DMA address mapping. Whenamdxdna_dma_map_bo()fails, the function returned immediately without rolling back either change made on the first open (open_ref== 1 path).Fix it by decrementing
open_refand clearingabo->clienton the error path.Fixes ece3e8980907 ("accel/amdxdna: Allow forcing IOVA-based DMA via module parameter")Signed-off-by Lizhi Hou <[email protected]>Reviewed-by Max Zhen <[email protected]>Quoted 21 lines
---
drivers/accel/amdxdna/amdxdna_gem.c| 5 ++++-1 file changed, 4 insertions(+), 1 deletion(-)drivers/accel/amdxdna/amdxdna_gem.c +0
-0@@ -663,8 +663,11 @@ static int amdxdna_gem_obj_open(struct
drm_gem_object*gobj, structdrm_file*fi
/* No need to set up dma addr mapping in PASID mode. */ if (!amdxdna_pasid_on(abo->client)) {
ret =amdxdna_dma_map_bo(xdna, abo);
- if (ret)
+ if (ret) {
+ abo->open_ref--;
+abo->client= NULL;
return ret;
+ }
}
amdxdna_gem_add_bo_usage(abo);