Cleanup on the etnaviv_open() failure path is incomplete in that the context id is left allocated. Fix it by adding proper onion unwind.
Failure mode is that when more than ETNAVIV_PTA_ENTRIES files are opened, subsequent open attempts leak kernel memory via dangling XArray entries. Signed-off-by: Tvrtko Ursulin <[email protected]> Fixes: d306788b6e1b ("drm/etnaviv: allocate unique ID per drm_file") Cc: Lucas Stach <[email protected]> Cc: Russell King <[email protected]> Cc: Christian Gmeiner <[email protected]> Cc: [email protected] Cc: <[email protected]> # v6.3+ --- Compile tested only. --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index ec1352c1b09f..7bd7aef723c3 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -79,7 +79,7 @@ static int etnaviv_open(struct drm_device *dev, struct drm_file *file) priv->cmdbuf_suballoc); if (!ctx->mmu) { ret = -ENOMEM; - goto out_free; + goto out_id; } for (i = 0; i < ETNA_MAX_PIPES; i++) { @@ -98,6 +98,8 @@ static int etnaviv_open(struct drm_device *dev, struct drm_file *file) return 0; +out_id: + xa_erase(&priv->active_contexts, ctx->id); out_free: kfree(ctx); return ret; -- 2.56.0
