Linux Framebuffer Layer development
 help / color / mirror / Atom feed
* [PATCH v2] fbdev: s3c-fb: Fix potential registration corruption on probe failure
@ 2026-11-24 13:58 Guangshuo Li
  2026-11-24 21:55 ` Helge Deller
  0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-11-24 13:58 UTC (permalink / raw)
  To: Jingoo Han, Helge Deller; +Cc: linux-fbdev, dri-devel, linux-kernel, stable

s3c_fb_probe_win() publishes its window before registration succeeds.
On failure, the caller unregisters that unregistered framebuffer, whose
zero-initialized node can remove another framebuffer from registered_fb[0].
Colour-map allocation failure is also ignored.

Unwind failed windows inside s3c_fb_probe_win() and publish them only
after successful registration. Stop the window before freeing its display
memory if registration fails, and skip empty slots in the caller's cleanup.

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

Fixes: ec549a0fdc32 ("fb: add s3c-fb driver for newer Samsung SoC framebuffer devices")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
Changes in v2:
  - Unwind failed windows in s3c_fb_probe_win() and publish the window
    only after registration succeeds, without a registration flag.
  - Stop on colour-map allocation failure and skip empty cleanup slots.
  - Blank the enabled window before freeing memory if registration fails.

 drivers/video/fbdev/s3c-fb.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/s3c-fb.c b/drivers/video/fbdev/s3c-fb.c
index fde78707d313..8fae4d909bb7 100644
--- a/drivers/video/fbdev/s3c-fb.c
+++ b/drivers/video/fbdev/s3c-fb.c
@@ -1197,7 +1197,6 @@ static int s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
 	WARN_ON(windata->yres == 0);
 
 	win = fbinfo->par;
-	*res = win;
 	win->variant = *variant;
 	win->fbinfo = fbinfo;
 	win->parent = sfb;
@@ -1208,7 +1207,7 @@ static int s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
 	ret = s3c_fb_alloc_memory(sfb, win);
 	if (ret) {
 		dev_err(sfb->dev, "failed to allocate display memory\n");
-		return ret;
+		goto err_release_fb;
 	}
 
 	/* setup the r/b/g positions for the window's palette */
@@ -1249,16 +1248,17 @@ static int s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
 	ret = s3c_fb_check_var(&fbinfo->var, fbinfo);
 	if (ret < 0) {
 		dev_err(sfb->dev, "check_var failed on initial video params\n");
-		return ret;
+		goto err_free_memory;
 	}
 
 	/* create initial colour map */
 
 	ret = fb_alloc_cmap(&fbinfo->cmap, win->variant.palette_sz, 1);
-	if (ret == 0)
-		fb_set_cmap(&fbinfo->cmap, fbinfo);
-	else
+	if (ret) {
 		dev_err(sfb->dev, "failed to allocate fb cmap\n");
+		goto err_free_memory;
+	}
+	fb_set_cmap(&fbinfo->cmap, fbinfo);
 
 	s3c_fb_set_par(fbinfo);
 
@@ -1269,12 +1269,22 @@ static int s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
 	ret = register_framebuffer(fbinfo);
 	if (ret < 0) {
 		dev_err(sfb->dev, "failed to register framebuffer\n");
-		return ret;
+		goto err_blank;
 	}
 
+	*res = win;
 	dev_info(sfb->dev, "window %d: fb %s\n", win_no, fbinfo->fix.id);
 
 	return 0;
+
+err_blank:
+	s3c_fb_blank(FB_BLANK_POWERDOWN, fbinfo);
+	fb_dealloc_cmap(&fbinfo->cmap);
+err_free_memory:
+	s3c_fb_free_memory(sfb, win);
+err_release_fb:
+	framebuffer_release(fbinfo);
+	return ret;
 }
 
 /**
@@ -1470,7 +1480,8 @@ static int s3c_fb_probe(struct platform_device *pdev)
 		if (ret < 0) {
 			dev_err(dev, "failed to create window %d\n", win);
 			for (; win >= 0; win--)
-				s3c_fb_release_win(sfb, sfb->windows[win]);
+				if (sfb->windows[win])
+					s3c_fb_release_win(sfb, sfb->windows[win]);
 			goto err_pm_runtime;
 		}
 	}

base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
-- 
2.43.0


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

end of thread, other threads:[~2026-11-24 21:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 13:58 [PATCH v2] fbdev: s3c-fb: Fix potential registration corruption on probe failure Guangshuo Li
2026-11-24 21:55 ` Helge Deller

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