* [PATCH v2] fbdev: platinumfb: add error checking for ioremap calls
@ 2026-08-17 6:39 yuebingkun
2026-08-17 6:49 ` sashiko-bot
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: yuebingkun @ 2026-08-17 6:39 UTC (permalink / raw)
To: Helge Deller; +Cc: linux-fbdev, dri-devel, linux-kernel, yuebingkun
The ioremap() and ioremap_wt() calls in platinumfb_probe() were not
checked for failure. If any of these mappings fail, the driver would
dereference NULL pointers, leading to a kernel panic.
Add proper error checking and use goto-based cleanup to avoid code
duplication across the error paths.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: yuebingkun <yuebingkun@kylinos.cn>
---
drivers/video/fbdev/platinumfb.c | 36 ++++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 6 deletions(-)
diff --git a/drivers/video/fbdev/platinumfb.c b/drivers/video/fbdev/platinumfb.c
index fa27a3a4f05b..fdffadcc3e73 100644
--- a/drivers/video/fbdev/platinumfb.c
+++ b/drivers/video/fbdev/platinumfb.c
@@ -567,15 +567,30 @@ static int platinumfb_probe(struct platform_device* odev)
/* frame buffer - map only 4MB */
pinfo->frame_buffer_phys = pinfo->rsrc_fb.start;
pinfo->frame_buffer = ioremap_wt(pinfo->rsrc_fb.start, 0x400000);
+ if (!pinfo->frame_buffer) {
+ dev_err(&odev->dev, "failed to ioremap frame buffer\n");
+ rc = -ENOMEM;
+ goto err_release_fb;
+ }
pinfo->base_frame_buffer = pinfo->frame_buffer;
/* registers */
pinfo->platinum_regs_phys = pinfo->rsrc_reg.start;
pinfo->platinum_regs = ioremap(pinfo->rsrc_reg.start, 0x1000);
+ if (!pinfo->platinum_regs) {
+ dev_err(&odev->dev, "failed to ioremap registers\n");
+ rc = -ENOMEM;
+ goto err_unmap_fb;
+ }
pinfo->cmap_regs_phys = 0xf301b000; /* XXX not in prom? */
request_mem_region(pinfo->cmap_regs_phys, 0x1000, "platinumfb cmap");
pinfo->cmap_regs = ioremap(pinfo->cmap_regs_phys, 0x1000);
+ if (!pinfo->cmap_regs) {
+ dev_err(&odev->dev, "failed to ioremap cmap registers\n");
+ rc = -ENOMEM;
+ goto err_release_cmap;
+ }
/* Grok total video ram */
out_be32(&pinfo->platinum_regs->reg[16].r, (unsigned)pinfo->frame_buffer_phys);
@@ -623,13 +638,22 @@ static int platinumfb_probe(struct platform_device* odev)
dev_set_drvdata(&odev->dev, info);
rc = platinum_init_fb(info);
- if (rc != 0) {
- iounmap(pinfo->frame_buffer);
- iounmap(pinfo->platinum_regs);
- iounmap(pinfo->cmap_regs);
- framebuffer_release(info);
- }
+ if (rc != 0)
+ goto err_unmap_cmap;
+
+ return 0;
+err_unmap_cmap:
+ iounmap(pinfo->cmap_regs);
+err_release_cmap:
+ release_mem_region(pinfo->cmap_regs_phys, 0x1000);
+err_unmap_regs:
+ iounmap(pinfo->platinum_regs);
+err_unmap_fb:
+ iounmap(pinfo->frame_buffer);
+err_release_fb:
+ release_mem_region(pinfo->rsrc_fb.start, resource_size(&pinfo->rsrc_fb));
+ framebuffer_release(info);
return rc;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] fbdev: platinumfb: add error checking for ioremap calls
2026-08-17 6:39 [PATCH v2] fbdev: platinumfb: add error checking for ioremap calls yuebingkun
@ 2026-08-17 6:49 ` sashiko-bot
2026-08-17 7:00 ` Markus Elfring
2026-08-18 9:03 ` Helge Deller
2 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-08-17 6:49 UTC (permalink / raw)
To: yuebingkun; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Unchecked request_mem_region combined with unconditional release_mem_region causes resource corruption and Use-After-Free.
--
--- Patch [1]: [PATCH v2] fbdev: platinumfb: add error checking for ioremap calls ---
commit a9dd2a2a25aeae119ea17d0f40c6cbdddde67dfd
Author: yuebingkun <yuebingkun@kylinos.cn>
fbdev: platinumfb: add error checking for ioremap calls
This commit adds error checking for ioremap() and ioremap_wt() calls in
platinumfb_probe(), avoiding NULL pointer dereferences by introducing
goto-based cleanup paths on failure.
> diff --git a/drivers/video/fbdev/platinumfb.c b/drivers/video/fbdev/platinumfb.c
> index a08d955d9b439..f74c937c839f8 100644
> --- a/drivers/video/fbdev/platinumfb.c
> +++ b/drivers/video/fbdev/platinumfb.c
[ ... ]
> @@ -567,15 +567,30 @@ static int platinumfb_probe(struct platform_device* odev)
[ ... ]
> pinfo->cmap_regs_phys = 0xf301b000; /* XXX not in prom? */
> request_mem_region(pinfo->cmap_regs_phys, 0x1000, "platinumfb cmap");
> pinfo->cmap_regs = ioremap(pinfo->cmap_regs_phys, 0x1000);
> + if (!pinfo->cmap_regs) {
> + dev_err(&odev->dev, "failed to ioremap cmap registers\n");
> + rc = -ENOMEM;
> + goto err_release_cmap;
> + }
[ ... ]
> +err_unmap_cmap:
> + iounmap(pinfo->cmap_regs);
> +err_release_cmap:
> + release_mem_region(pinfo->cmap_regs_phys, 0x1000);
[Severity: High]
This is a pre-existing issue, but I noticed the return value of
request_mem_region() is ignored just before the ioremap() call.
If request_mem_region() fails because the physical resource is already
claimed by platform code or another driver, probe continues. If a subsequent
step then fails, such as ioremap() returning NULL or platinum_init_fb()
failing, this newly added error path branches to err_release_cmap.
Since err_release_cmap unconditionally calls release_mem_region(), does this
risk freeing a resource that wasn't actually acquired? If the region size
and start address exactly match an existing claim, this could unlink and
free a resource owned by another driver, potentially causing a
use-after-free later.
Could we add a check for the return value of request_mem_region() so we
only release it if the driver successfully claimed it?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260817063942.308926-1-yuebingkun@kylinos.cn?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] fbdev: platinumfb: add error checking for ioremap calls
2026-08-17 6:39 [PATCH v2] fbdev: platinumfb: add error checking for ioremap calls yuebingkun
2026-08-17 6:49 ` sashiko-bot
@ 2026-08-17 7:00 ` Markus Elfring
2026-08-18 9:03 ` Helge Deller
2 siblings, 0 replies; 5+ messages in thread
From: Markus Elfring @ 2026-08-17 7:00 UTC (permalink / raw)
To: yuebingkun, linux-fbdev, dri-devel, Helge Deller; +Cc: LKML, kernel-janitors
…
> Add proper error checking and use goto-based cleanup to avoid code
> duplication across the error paths.
* Please avoid duplicate source code also in the implementation of the function “platinumfb_probe”
a bit more.
https://elixir.bootlin.com/linux/v7.2-rc7/source/drivers/video/fbdev/platinumfb.c#L527-L634
* Under which circumstances will development interests grow for the application of scope-based resource management?
…
> ---
> drivers/video/fbdev/platinumfb.c | 36 ++++++++++++++++++++++++++------
…
Some contributors would appreciate patch version descriptions.
https://lore.kernel.org/all/?q=%22This+looks+like+a+new+version+of+a+previously+submitted+patch%22
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v7.2-rc7#n310
Regards,
Markus
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] fbdev: platinumfb: add error checking for ioremap calls
2026-08-17 6:39 [PATCH v2] fbdev: platinumfb: add error checking for ioremap calls yuebingkun
2026-08-17 6:49 ` sashiko-bot
2026-08-17 7:00 ` Markus Elfring
@ 2026-08-18 9:03 ` Helge Deller
2026-08-19 23:59 ` Nathan Chancellor
2 siblings, 1 reply; 5+ messages in thread
From: Helge Deller @ 2026-08-18 9:03 UTC (permalink / raw)
To: yuebingkun; +Cc: linux-fbdev, dri-devel, linux-kernel
On 8/17/26 08:39, yuebingkun wrote:
> The ioremap() and ioremap_wt() calls in platinumfb_probe() were not
> checked for failure. If any of these mappings fail, the driver would
> dereference NULL pointers, leading to a kernel panic.
>
> Add proper error checking and use goto-based cleanup to avoid code
> duplication across the error paths.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
That Fixes line ^^^ has no value, so I dropped it.
> Signed-off-by: yuebingkun <yuebingkun@kylinos.cn>
Would be nice to have your Name written out here, e.g. Yue Bing Kun (or something),
but I've left it as-is for now. In case you resend with full name, I can replace it
in the git tree.
> drivers/video/fbdev/platinumfb.c | 36 ++++++++++++++++++++++++++------
> 1 file changed, 30 insertions(+), 6 deletions(-)
Patch applied (with the Fixes line dropped).
Thanks!
Helge
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] fbdev: platinumfb: add error checking for ioremap calls
2026-08-18 9:03 ` Helge Deller
@ 2026-08-19 23:59 ` Nathan Chancellor
0 siblings, 0 replies; 5+ messages in thread
From: Nathan Chancellor @ 2026-08-19 23:59 UTC (permalink / raw)
To: Helge Deller; +Cc: yuebingkun, linux-fbdev, dri-devel, linux-kernel
On Tue, Aug 18, 2026 at 11:03:07AM +0200, Helge Deller wrote:
> On 8/17/26 08:39, yuebingkun wrote:
> > The ioremap() and ioremap_wt() calls in platinumfb_probe() were not
> > checked for failure. If any of these mappings fail, the driver would
> > dereference NULL pointers, leading to a kernel panic.
> >
> > Add proper error checking and use goto-based cleanup to avoid code
> > duplication across the error paths.
> >
> > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
>
> That Fixes line ^^^ has no value, so I dropped it.
>
> > Signed-off-by: yuebingkun <yuebingkun@kylinos.cn>
>
> Would be nice to have your Name written out here, e.g. Yue Bing Kun (or something),
> but I've left it as-is for now. In case you resend with full name, I can replace it
> in the git tree.
>
> > drivers/video/fbdev/platinumfb.c | 36 ++++++++++++++++++++++++++------
> > 1 file changed, 30 insertions(+), 6 deletions(-)
> Patch applied (with the Fixes line dropped).
This patch introduces a compiler warning for me:
drivers/video/fbdev/platinumfb.c: In function 'platinumfb_probe':
drivers/video/fbdev/platinumfb.c:650:1: warning: label 'err_unmap_regs' defined but not used [-Wunused-label]
650 | err_unmap_regs:
| ^~~~~~~~~~~~~~
As far as I can tell, it is unnecessary, so maybe this could be folded
in? Otherwise, I can send a formal patch.
diff --git a/drivers/video/fbdev/platinumfb.c b/drivers/video/fbdev/platinumfb.c
index f74c937c839f..81fdaa3541db 100644
--- a/drivers/video/fbdev/platinumfb.c
+++ b/drivers/video/fbdev/platinumfb.c
@@ -647,7 +647,6 @@ static int platinumfb_probe(struct platform_device* odev)
iounmap(pinfo->cmap_regs);
err_release_cmap:
release_mem_region(pinfo->cmap_regs_phys, 0x1000);
-err_unmap_regs:
iounmap(pinfo->platinum_regs);
err_unmap_fb:
iounmap(pinfo->frame_buffer);
--
Cheers,
Nathan
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-08-19 23:59 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-17 6:39 [PATCH v2] fbdev: platinumfb: add error checking for ioremap calls yuebingkun
2026-08-17 6:49 ` sashiko-bot
2026-08-17 7:00 ` Markus Elfring
2026-08-18 9:03 ` Helge Deller
2026-08-19 23:59 ` Nathan Chancellor
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.