In nouveau_channel_ctor(), nouveau_channel_prep() allocates the channel
structure. If nvif_mem_ctor() fails to allocate the userd memory, the
function returns without freeing the channel, resulting in a memory leak.

Add nouveau_channel_del() to the error path to ensure the allocated
channel is properly freed.

Compile tested only. Issue found using a prototype static analysis tool
and code review.

Fixes: 06db7fded6de ("drm/nouveau/fifo: add new channel classes")
Signed-off-by: Zilin Guan <[email protected]>
---
 drivers/gpu/drm/nouveau/nouveau_chan.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_chan.c 
b/drivers/gpu/drm/nouveau/nouveau_chan.c
index b1e92b1f7a26..a421c32fda02 100644
--- a/drivers/gpu/drm/nouveau/nouveau_chan.c
+++ b/drivers/gpu/drm/nouveau/nouveau_chan.c
@@ -322,8 +322,10 @@ nouveau_channel_ctor(struct nouveau_cli *cli, bool priv, 
u64 runm,
                ret = nvif_mem_ctor(&cli->mmu, "abi16ChanUSERD", 
NVIF_CLASS_MEM_GF100,
                                    NVIF_MEM_VRAM | NVIF_MEM_COHERENT | 
NVIF_MEM_MAPPABLE,
                                    0, PAGE_SIZE, NULL, 0, &chan->mem_userd);
-               if (ret)
+               if (ret) {
+                       nouveau_channel_del(pchan);
                        return ret;
+               }
 
                args->huserd = nvif_handle(&chan->mem_userd.object);
                args->ouserd = 0;
-- 
2.34.1

Reply via email to