mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] fbdev: s3c-fb: Fix potential registration corruption on probe failure
@ 2026-11-18 14:22 Guangshuo Li
  2026-11-18 18:17 ` Helge Deller
  0 siblings, 1 reply; 4+ messages in thread
From: Guangshuo Li @ 2026-11-18 14:22 UTC (permalink / raw)
  To: Jingoo Han, Helge Deller; +Cc: linux-fbdev, dri-devel, linux-kernel, stable

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")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
 drivers/video/fbdev/s3c-fb.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/s3c-fb.c b/drivers/video/fbdev/s3c-fb.c
index 82a3bc9de433..c67ad47a49f0 100644
--- a/drivers/video/fbdev/s3c-fb.c
+++ b/drivers/video/fbdev/s3c-fb.c
@@ -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
-- 
2.43.0


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

* Re: [PATCH] fbdev: s3c-fb: Fix potential registration corruption on probe failure
  2026-11-18 14:22 [PATCH] fbdev: s3c-fb: Fix potential registration corruption on probe failure Guangshuo Li
@ 2026-11-18 18:17 ` Helge Deller
  2026-11-19 12:46   ` 李广硕
  0 siblings, 1 reply; 4+ messages in thread
From: Helge Deller @ 2026-11-18 18:17 UTC (permalink / raw)
  To: Guangshuo Li, Jingoo Han; +Cc: linux-fbdev, dri-devel, linux-kernel, stable

On 11/18/26 15:22, Guangshuo Li wrote:
> 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

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

* Re:Re: [PATCH] fbdev: s3c-fb: Fix potential registration corruption on probe failure
  2026-11-18 18:17 ` Helge Deller
@ 2026-11-19 12:46   ` 李广硕
  2026-11-19 17:07     ` Helge Deller
  0 siblings, 1 reply; 4+ messages in thread
From: 李广硕 @ 2026-11-19 12:46 UTC (permalink / raw)
  To: Helge Deller; +Cc: Jingoo Han, linux-fbdev, dri-devel, linux-kernel, stable



Hi Helge,

Thanks for the review.

From: Helge Deller <deller@gmx.de>
Date: 2026-11-19 02:17:08
To:  Guangshuo Li <liguangshuo@mail.sdu.edu.cn>,Jingoo Han <jingoohan1@gmail.com>
Cc:  linux-fbdev@vger.kernel.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,stable@vger.kernel.org
Subject: Re: [PATCH] fbdev: s3c-fb: Fix potential registration corruption on probe failure>On 11/18/26 15:22, Guangshuo Li wrote:
>> 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
>

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

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

* Re: [PATCH] fbdev: s3c-fb: Fix potential registration corruption on probe failure
  2026-11-19 12:46   ` 李广硕
@ 2026-11-19 17:07     ` Helge Deller
  0 siblings, 0 replies; 4+ messages in thread
From: Helge Deller @ 2026-11-19 17:07 UTC (permalink / raw)
  To: 李广硕
  Cc: Jingoo Han, linux-fbdev, dri-devel, linux-kernel, stable

On 11/19/26 13:46, 李广硕 wrote:
> 
> 
> Hi Helge,
> 
> Thanks for the review.
> 
> From: Helge Deller <deller@gmx.de>
> Date: 2026-11-19 02:17:08
> To:  Guangshuo Li <liguangshuo@mail.sdu.edu.cn>,Jingoo Han <jingoohan1@gmail.com>
> Cc:  linux-fbdev@vger.kernel.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,stable@vger.kernel.org
> Subject: Re: [PATCH] fbdev: s3c-fb: Fix potential registration corruption on probe failure>On 11/18/26 15:22, Guangshuo Li wrote:
>>> 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
>>
> 
> 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.

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

Helge

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

end of thread, other threads:[~2026-11-19 17:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 14:22 [PATCH] fbdev: s3c-fb: Fix potential registration corruption on probe failure Guangshuo Li
2026-11-18 18:17 ` Helge Deller
2026-11-19 12:46   ` 李广硕
2026-11-19 17:07     ` Helge Deller

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®