fbdev: s3c-fb: Fix potential registration corruption on probe failure
Subsystems (3)
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.
--- drivers/video/fbdev/s3c-fb.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/video/fbdev/s3c-fb.c +6 -2
@@ -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
Helge Deller
maintainerQuoted 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
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
Helge Deller
maintainerQuoted 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 iffb_alloc_cmap()fails. I think it should unwind the current window on failure and set *res only afterregister_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