Skip to contentSkip to conversation

drm/gem-atomic-helper: fix fence leak on dma_fence_chain_alloc() failure

PATCH Superseded Chengyu Liu 3 participants 5 messages Nov 9 – Nov 13

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/gem-atomic-helper: fix fence leak on dma_fence_chain_alloc() failure

In drm_gem_plane_helper_prepare_fb(), when both "new" (the plane's GEM singleton fence) and "fence" (explicit or previous plane's) exist, they are wrapped in a freshly allocated chain. If dma_fence_chain_alloc() fails, the error path runs before dma_fence_chain_init() adopts "new", and error: only puts "fence" - leaking one fence reference per failure.

Put "new" in the allocation-failure branch.

Found by static analysis.

---
 drivers/gpu/drm/drm_gem_atomic_helper.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/drm_gem_atomic_helper.c +1 -0
index abef865c5f2c..1e484f26ab31 100644
@@ -153,6 +153,7 @@
 		if (new && fence) {
 			struct dma_fence_chain *chain = dma_fence_chain_alloc();
 
 			if (!chain) {
+				dma_fence_put(new);
 				ret = -ENOMEM;
 				goto error;

}

Signature · 1 line
2.25.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] drm/gem-atomic-helper: missing Fixes trailer for commit 1ea28bc5542d --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] drm/gem-atomic-helper: missing Fixes trailer for commit 1ea28bc5542d
--

commit b6d9ff23bfcc702d784107d5026972257646c1fc
Author: Chengyu Liu <[email protected]>

Quoted 8 lines

drm/gem-atomic-helper: fix fence leak on dma_fence_chain_alloc() failure

In drm_gem_plane_helper_prepare_fb(), when both "new" (the plane's GEM singleton fence) and "fence" (explicit or previous plane's) exist, they are wrapped in a freshly allocated chain. If dma_fence_chain_alloc() fails, the error path runs before dma_fence_chain_init() adopts "new", and error: only puts "fence" - leaking one fence reference per failure.

Quoted 5 lines

Put "new" in the allocation-failure branch.

Found by static analysis.

[Severity: Low]
Should this commit include a Fixes: tag for the commit that introduced the leak:

Fixes 1ea28bc5542d ("drm: handle kernel fences in drm_gem_plane_helper_prepare_fb v2")
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
Quoted 5 lines · On Mon, Nov 9, 2026 at 5:50 PM <[email protected]> wrote:

[Severity: Low]
Should this commit include a Fixes: tag for the commit that introduced the leak:

Fixes 1ea28bc5542d ("drm: handle kernel fences in drm_gem_plane_helper_prepare_fb v2")

Thanks, v2 will include the fix tag.

Quoted 32 lines · On Mon, Nov 9, 2026 at 5:50 PM <[email protected]> wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] drm/gem-atomic-helper: missing Fixes trailer for commit 1ea28bc5542d
--

commit b6d9ff23bfcc702d784107d5026972257646c1fc
Author: Chengyu Liu <[email protected]>

Quoted 8 lines

drm/gem-atomic-helper: fix fence leak on dma_fence_chain_alloc() failure

In drm_gem_plane_helper_prepare_fb(), when both "new" (the plane's GEM singleton fence) and "fence" (explicit or previous plane's) exist, they are wrapped in a freshly allocated chain. If dma_fence_chain_alloc() fails, the error path runs before dma_fence_chain_init() adopts "new", and error: only puts "fence" - leaking one fence reference per failure.

Quoted 5 lines

Put "new" in the allocation-failure branch.

Found by static analysis.

[Severity: Low]
Should this commit include a Fixes: tag for the commit that introduced the leak:

Fixes 1ea28bc5542d ("drm: handle kernel fences in drm_gem_plane_helper_prepare_fb v2")

--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1

#3 lore raw
In reply to Chengyu Liu

drivers/gpu/drm/drm_gem_atomic_helper.c

Quoted 20 lines · Chengyu Liu

In drm_gem_plane_helper_prepare_fb(), when both "new" (the plane's GEM singleton fence) and "fence" (explicit or previous plane's) exist, they are wrapped in a freshly allocated chain. If dma_fence_chain_alloc() fails, the error path runs before dma_fence_chain_init() adopts "new", and error: only puts "fence" - leaking one fence reference per failure.

Put "new" in the allocation-failure branch.

Found by static analysis.

---
 drivers/gpu/drm/drm_gem_atomic_helper.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/drm_gem_atomic_helper.c +0 -0
index abef865c5f2c..1e484f26ab31 100644
@@ -153,6 +153,7 @@ 
                      ^

Why are we missing the context here? Is this some git misconfiguration or bug?

Quoted 10 lines
drivers/gpu/drm/drm_gem_atomic_helper.c +1 -0
 		if (new && fence) {
 			struct dma_fence_chain *chain = dma_fence_chain_alloc();
 
 			if (!chain) {
+				dma_fence_put(new);
 				ret = -ENOMEM;
 				goto error;

}

Signature · 1 line
2.25.1
Signature · 2 lines
Ville Syrjälä
Intel
#4 lore raw
Quoted 9 lines · Ville Syrjälä

drivers/gpu/drm/drm_gem_atomic_helper.c

Quoted 5 lines
drivers/gpu/drm/drm_gem_atomic_helper.c +0 -0
index abef865c5f2c..1e484f26ab31 100644
@@ -153,6 +153,7 @@
                      ^

Why are we missing the context here? Is this some git misconfiguration or bug?

My mistake, not a Git problem.

I assembled the patch outside the kernel Git tree instead of generating it from a commit with git format-patch, so the hunk headers were missing the function context. Since v2 was based on v1, it inherited the same issue.

git apply and checkpatch.pl accept the patch without this context, which is how I missed it.

v3 contains the same fix, regenerated from a commit in the kernel tree using git format-patch. The hunk headers now include the proper function context.

Sorry for the noise.