Skip to contentSkip to conversation

fbdev: s3c-fb: Fix potential registration corruption on probe failure

PATCH In review Guangshuo Li 2 participants 4 messages Nov 18 – Nov 19

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fbdev: s3c-fb: Fix potential registration corruption on probe failure

Probe failure cleanup calls unregister_framebuffer() even when the window has not been registered. Its zero-initialized node can then remove another framebuffer from registered_fb[0].

Track successful registration and only unregister those framebuffers. Also skip empty window slots while unwinding a failed probe.

This issue was found by our static analysis tool under development.

Fixes ec549a0fdc32 ("fb: add s3c-fb driver for newer Samsung SoC framebuffer devices")
---
 drivers/video/fbdev/s3c-fb.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/video/fbdev/s3c-fb.c +6 -2
index 82a3bc9de433..c67ad47a49f0 100644
@@ -161,6 +161,7 @@ struct s3c_fb_palette {
  * @pseudo_palette: For use in TRUECOLOUR modes for entries 0..15/
  * @index: The window number of this window.
  * @palette: The bitfields for changing r/g/b into a hardware palette entry.
+ * @registered: Whether the framebuffer was successfully registered.
  */
 struct s3c_fb_win {
 	struct s3c_fb_pd_win	*windata;
@@ -172,6 +173,7 @@ struct s3c_fb_win {
 	u32			*palette_buffer;
 	u32			 pseudo_palette[16];
 	unsigned int		 index;
+	bool			 registered;
 };
 
 /**
@@ -1142,14 +1144,15 @@ static void s3c_fb_release_win(struct s3c_fb *sfb, struct s3c_fb_win *win)
 {
 	u32 data;
 
-	if (win->fbinfo) {
+	if (win && win->fbinfo) {
 		if (sfb->variant.has_shadowcon) {
 			data = readl(sfb->regs + SHADOWCON);
 			data &= ~SHADOWCON_CHx_ENABLE(win->index);
 			data &= ~SHADOWCON_CHx_LOCAL_ENABLE(win->index);
 			writel(data, sfb->regs + SHADOWCON);
 		}
-		unregister_framebuffer(win->fbinfo);
+		if (win->registered)
+			unregister_framebuffer(win->fbinfo);
 		if (win->fbinfo->cmap.len)
 			fb_dealloc_cmap(&win->fbinfo->cmap);
 		s3c_fb_free_memory(sfb, win);
@@ -1272,6 +1275,7 @@ static int s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
 		return ret;
 	}
 
+	win->registered = true;
 	dev_info(sfb->dev, "window %d: fb %s\n", win_no, fbinfo->fix.id);
 
 	return 0;

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 8 lines · Guangshuo Li

Probe failure cleanup calls unregister_framebuffer() even when the window has not been registered. Its zero-initialized node can then remove another framebuffer from registered_fb[0].

Track successful registration and only unregister those framebuffers. Also skip empty window slots while unwinding a failed probe.

This issue was found by our static analysis tool under development.

I think s3c_fb_probe_win() needs to clean up when some things like cmap fail to be allocated.
Your patch seems to just work around one of the possible pitfalls.

Helge

author
#2 lore raw

Hi Helge,

Thanks for the review.

From: Helge Deller <[email protected]>
Date: 2026-11-19 02:17:08
To: Guangshuo Li <[email protected]>,Jingoo Han <[email protected]>
Cc: [email protected],[email protected],[email protected],[email protected]

Quoted 7 lines · Guangshuo Li
Quoted 7 lines

Probe failure cleanup calls unregister_framebuffer() even when the window has not been registered. Its zero-initialized node can then remove another framebuffer from registered_fb[0].

Track successful registration and only unregister those framebuffers. Also skip empty window slots while unwinding a failed probe.

Quoted 8 lines
Quoted 1 line

This issue was found by our static analysis tool under development.

I think s3c_fb_probe_win() needs to clean up when some things like cmap fail to be allocated.
Your patch seems to just work around one of the possible pitfalls.

Helge

s3c_fb_probe_win() sets *res early and carries on if fb_alloc_cmap() fails. I think it should unwind the current window on failure and set *res only after register_framebuffer() succeeds. That would leave the caller with just the registered windows to clean up.

Is that where you'd put the cleanup? If so, I'll send a v2 without the extra registration flag.

Thanks,
Guangshuo

maintainer
#3 lore raw
Quoted 27 lines · 李广硕

Hi Helge,

Thanks for the review.

From: Helge Deller <[email protected]>
Date: 2026-11-19 02:17:08
To: Guangshuo Li <[email protected]>,Jingoo Han <[email protected]>
Cc: [email protected],[email protected],[email protected],[email protected]

Quoted 7 lines · Guangshuo Li
Quoted 7 lines

Probe failure cleanup calls unregister_framebuffer() even when the window has not been registered. Its zero-initialized node can then remove another framebuffer from registered_fb[0].

Track successful registration and only unregister those framebuffers. Also skip empty window slots while unwinding a failed probe.

Quoted 8 lines
Quoted 1 line

This issue was found by our static analysis tool under development.

I think s3c_fb_probe_win() needs to clean up when some things like cmap fail to be allocated.
Your patch seems to just work around one of the possible pitfalls.

Helge

Quoted 6 lines

s3c_fb_probe_win() sets *res early and carries on if fb_alloc_cmap() fails. I think it should unwind the current window on failure and set *res only after register_framebuffer() succeeds. That would leave the caller with just the registered windows to clean up.

Is that where you'd put the cleanup?

Yes, I think s3c_fb_probe_win() should be able to handle every possible error inside this function and do nice cleanups if it fails.

Quoted 1 line

If so, I'll send a v2 without the extra registration flag.

Thanks!

Helge