drm/nouveau/nouveau_bo: fix potential memory leak in nouveau_bo_alloc()
authorJianglei Nie <niejianglei2021@163.com>
Tue, 5 Jul 2022 09:43:06 +0000 (17:43 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Oct 2022 10:35:38 +0000 (12:35 +0200)
commit5ab84b1596b26a6c789e3075252df720b15fd126
tree3efa1ba9b566b6bef4cf1ab00660204522f1efdf
parentb3179865cf7e892b26eedab3d6c54b4747c774a2
drm/nouveau/nouveau_bo: fix potential memory leak in nouveau_bo_alloc()

[ Upstream commit 6dc548745d5b5102e3c53dc5097296ac270b6c69 ]

nouveau_bo_alloc() allocates a memory chunk for "nvbo" with kzalloc().
When some error occurs, "nvbo" should be released. But when
WARN_ON(pi < 0)) equals true, the function return ERR_PTR without
releasing the "nvbo", which will lead to a memory leak.

We should release the "nvbo" with kfree() if WARN_ON(pi < 0)) equals true.

Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
Signed-off-by: Lyude Paul <lyude@redhat.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220705094306.2244103-1-niejianglei2021@163.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/nouveau/nouveau_bo.c