mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 5.4 01/14] drm/nouveau/nouveau_bo: fix potential memory leak in nouveau_bo_alloc()
@ 2022-10-09 23:56 Sasha Levin
  2022-10-09 23:56 ` [PATCH AUTOSEL 5.4 02/14] drm: Use size_t type for len variable in drm_copy_field() Sasha Levin
                   ` (12 more replies)
  0 siblings, 13 replies; 15+ messages in thread
From: Sasha Levin @ 2022-10-09 23:56 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Jianglei Nie, Lyude Paul, Sasha Levin, bskeggs, kherbst, airlied,
	daniel, dri-devel, nouveau

From: Jianglei Nie <niejianglei2021@163.com>

[ 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 | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index f7603be569fc..9f9c70734180 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -276,8 +276,10 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size, int *align, u32 flags,
 			break;
 	}
 
-	if (WARN_ON(pi < 0))
+	if (WARN_ON(pi < 0)) {
+		kfree(nvbo);
 		return ERR_PTR(-EINVAL);
+	}
 
 	/* Disable compression if suitable settings couldn't be found. */
 	if (nvbo->comp && !vmm->page[pi].comp) {
-- 
2.35.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2022-10-10  7:42 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-09 23:56 [PATCH AUTOSEL 5.4 01/14] drm/nouveau/nouveau_bo: fix potential memory leak in nouveau_bo_alloc() Sasha Levin
2022-10-09 23:56 ` [PATCH AUTOSEL 5.4 02/14] drm: Use size_t type for len variable in drm_copy_field() Sasha Levin
2022-10-09 23:56 ` [PATCH AUTOSEL 5.4 03/14] drm: Prevent drm_copy_field() to attempt copying a NULL pointer Sasha Levin
2022-10-09 23:57 ` [PATCH AUTOSEL 5.4 04/14] drm/amd/display: fix overflow on MIN_I64 definition Sasha Levin
2022-10-09 23:57 ` [PATCH AUTOSEL 5.4 05/14] ALSA: usb-audio: Add quirk to enable Avid Mbox 3 support Sasha Levin
2022-10-09 23:57 ` [PATCH AUTOSEL 5.4 06/14] drm: hide unregistered connectors from GETCONNECTOR IOCTL Sasha Levin
2022-10-09 23:57 ` [PATCH AUTOSEL 5.4 07/14] drm/vc4: vec: Fix timings for VEC modes Sasha Levin
2022-10-09 23:57 ` [PATCH AUTOSEL 5.4 08/14] ACPI: video: Change disable_backlight_sysfs_if quirks to acpi_backlight=native Sasha Levin
2022-10-10  7:36   ` Hans de Goede
2022-10-09 23:57 ` [PATCH AUTOSEL 5.4 09/14] drm: panel-orientation-quirks: Add quirk for Anbernic Win600 Sasha Levin
2022-10-09 23:57 ` [PATCH AUTOSEL 5.4 10/14] platform/x86: msi-laptop: Change DMI match / alias strings to fix module autoloading Sasha Levin
2022-10-09 23:57 ` [PATCH AUTOSEL 5.4 11/14] drm/amdgpu: fix initial connector audio value Sasha Levin
2022-10-09 23:57 ` [PATCH AUTOSEL 5.4 12/14] drm/exynos: Fix return type for mixer_mode_valid and hdmi_mode_valid Sasha Levin
2022-10-09 23:57 ` [PATCH AUTOSEL 5.4 13/14] mmc: sdhci-msm: add compatible string check for sdm670 Sasha Levin
2022-10-09 23:57 ` [PATCH AUTOSEL 5.4 14/14] drm/amd/display: fix array-bounds error in dc_stream_remove_writeback() Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®