fbdev: Request memory regions in platform drivers
cover fbdev: Request memory regions in platform drivers
Several fbdev platform drivers call ioremap() on their hardware MMIO without first claiming the range via request_mem_region(). This leaves the kernel resource tree (/proc/iomem) with no record of the mapping, allowing another driver to silently map the same registers.
This series fixes three platform_device drivers by switching to helpers that combine resource claiming and ioremap in a single managed call. cobalt_lcdfb and clps711x-fb are converted to devm_platform_get_and_ioremap_resource(); goldfishfb is converted to devm_ioremap_resource(), which also lets us drop the manual iounmap() calls from the error path and remove function.
For clps711x-fb, resource 1 (the framebuffer range) already used devm_platform_get_and_ioremap_resource() correctly; this series makes resource 0 (the MMIO control registers) consistent with it.
This is part of the ongoing effort described in Documentation/drm/todo.rst ("Request memory regions in all fbdev drivers").
Amit Barzilai (3):
fbdev: cobalt_lcdfb: Request memory region
fbdev: clps711x-fb: Request memory region for MMIO
fbdev: goldfishfb: Request memory region
drivers/video/fbdev/clps711x-fb.c | 9 +++------ drivers/video/fbdev/cobalt_lcdfb.c | 12 +++--------- drivers/video/fbdev/goldfishfb.c | 8 +++----- 3 files changed, 9 insertions(+), 20 deletions(-)
base-commit: 3f9357c30a44734d45e3093c521d52b2aefb09f5
Signature · 1 line
2.53.0
PATCH 1/3 fbdev: cobalt_lcdfb: Request memory region
Use devm_platform_get_and_ioremap_resource() instead of open-coding platform_get_resource() and devm_ioremap() separately. The helper requests the memory region before mapping it, which registers the range in /proc/iomem and prevents another driver from mapping the same registers.
--- drivers/video/fbdev/cobalt_lcdfb.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/video/fbdev/cobalt_lcdfb.c +3 -9
@@ -295,19 +295,13 @@ static int cobalt_lcdfb_probe(struct platform_device *dev)if (!info)return -ENOMEM ; - res =platform_get_resource (dev,IORESOURCE_MEM ,0 ); -if (!res) { + info->screen_base =devm_platform_get_and_ioremap_resource (dev,0 , &res); +if (IS_ERR (info->screen_base)) {framebuffer_release (info); -return -EBUSY ; +return PTR_ERR (info->screen_base); } info->screen_size =resource_size (res); - info->screen_base =devm_ioremap (&dev->dev, res->start, - info->screen_size); -if (!info->screen_base) { -framebuffer_release (info); -return -ENOMEM ; - } info->fbops = &cobalt_lcd_fbops; info->fix = cobalt_lcdfb_fix;
Signature · 1 line
2.53.0
Helge Deller
maintainerRe: [PATCH 1/3] fbdev: cobalt_lcdfb: Request memory region
Hi Amit,
Quoted 7 lines · Amit Barzilai
Use
devm_platform_get_and_ioremap_resource()instead of open-codingplatform_get_resource()anddevm_ioremap()separately. The helper requests the memory region before mapping it, which registers the range in/proc/iomemand prevents another driver from mapping the same registers.Assisted-by Claude:claude-sonnet-4-6
You missed your signed-off line, which I added while applying patches #1 and #2:
Amit, please confirm that you wrote patches #2 and #3 and that you are OK with the added Signed-off-by line, otherwise I need to drop the patches.
Helge
Quoted 3 lines
--- drivers/video/fbdev/cobalt_lcdfb.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
Re: [PATCH 1/3] fbdev: cobalt_lcdfb: Request memory region
Hi Helge,
Yes, I wrote all three patches and I am OK with the added Signed-off-by line. Sorry for the oversight, I'll make sure to include it in future submissions.
Thanks,
Amit
Re: [PATCH 1/3] fbdev: cobalt_lcdfb: Request memory region
In reply to Helge DellerHi Helge,
Yes, I wrote all three patches and I am OK with the added Signed-off-by line.
Sorry for the oversight, I'll make sure to include it in future submissions.
Thanks,
Amit
Quoted 26 lines · Helge Deller
Hi Amit,
Quoted 7 lines · Amit Barzilai
Use
devm_platform_get_and_ioremap_resource()instead of open-codingplatform_get_resource()anddevm_ioremap()separately. The helper requests the memory region before mapping it, which registers the range in/proc/iomemand prevents another driver from mapping the same registers.Assisted-by Claude:claude-sonnet-4-6You missed your signed-off line, which I added while applying patches #1 and #2:
Signed-off-by Amit Barzilai <[email protected]>Amit, please confirm that you wrote patches #2 and #3 and that you are OK with the added Signed-off-by line, otherwise I need to drop the patches.
Helge
Quoted 3 lines
--- drivers/video/fbdev/cobalt_lcdfb.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
PATCH 2/3 fbdev: clps711x-fb: Request memory region for MMIO
In reply to Amit BarzilaiUse devm_platform_get_and_ioremap_resource() for resource 0 (the MMIO control register range) instead of open-coding platform_get_resource() and devm_ioremap() separately. The helper requests the memory region before mapping it, which registers the range in /proc/iomem and prevents another driver from mapping the same registers.
This makes resource 0 consistent with resource 1 (the framebuffer), which already uses devm_platform_get_and_ioremap_resource().
--- drivers/video/fbdev/clps711x-fb.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/video/fbdev/clps711x-fb.c +3 -6
@@ -216,12 +216,9 @@ static int clps711x_fb_probe(struct platform_device *pdev) cfb = info->par;platform_set_drvdata (pdev, info); - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); -if (!res) - goto out_fb_release; - cfb->base =devm_ioremap (dev, res->start,resource_size (res)); -if (!cfb->base) { - ret = -ENOMEM ; + cfb->base =devm_platform_get_and_ioremap_resource (pdev,0 , &res); +if (IS_ERR (cfb->base)) { + ret =PTR_ERR (cfb->base); goto out_fb_release; }
Signature · 1 line
2.53.0
PATCH 3/3 fbdev: goldfishfb: Request memory region
In reply to Amit BarzilaiUse devm_ioremap_resource() instead of plain ioremap(). The helper requests the memory region before mapping it, which registers the range in /proc/iomem and prevents another driver from mapping the same registers. As it is device-managed, remove the corresponding iounmap() calls from the error unwind path and the remove function.
--- drivers/video/fbdev/goldfishfb.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/video/fbdev/goldfishfb.c +3 -5
@@ -194,9 +194,9 @@ static int goldfish_fb_probe(struct platform_device *pdev) ret = -ENODEV ; goto err_no_io_base; } - fb->reg_base =ioremap (r->start,PAGE_SIZE ); -if (fb->reg_base ==NULL ) { - ret = -ENOMEM ; + fb->reg_base =devm_ioremap_resource (&pdev->dev, r); +if (IS_ERR (fb->reg_base)) { + ret =PTR_ERR (fb->reg_base); goto err_no_io_base; }
@@ -273,7 +273,6 @@ static int goldfish_fb_probe(struct platform_device *pdev) fb->fb.fix.smem_start); err_alloc_screen_base_failed: err_no_irq: -iounmap (fb->reg_base); err_no_io_base:kfree (fb); err_fb_alloc_failed:
@@ -291,7 +290,6 @@ static void goldfish_fb_remove(struct platform_device *pdev)dma_free_coherent (&pdev->dev, framesize, (void *)fb->fb.screen_base, fb->fb.fix.smem_start); -iounmap (fb->reg_base);kfree (fb); }
Signature · 1 line
2.53.0
Helge Deller
maintainerRe: [PATCH 3/3] fbdev: goldfishfb: Request memory region
Quoted 10 lines · Amit Barzilai
Use
devm_ioremap_resource()instead of plainioremap(). The helper requests the memory region before mapping it, which registers the range in/proc/iomemand prevents another driver from mapping the same registers. As it is device-managed, remove the correspondingiounmap()calls from the error unwind path and the remove function.Assisted-by Claude:claude-sonnet-4-6--- drivers/video/fbdev/goldfishfb.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
It was alreads fixed by another patch upstream...
Helge
Hi Amit,
Quoted 12 lines · Amit Barzilai
Several fbdev platform drivers call
ioremap()on their hardware MMIO without first claiming the range viarequest_mem_region(). This leaves the kernel resource tree (/proc/iomem) with no record of the mapping, allowing another driver to silently map the same registers.This series fixes three
platform_devicedrivers by switching to helpers that combine resource claiming and ioremap in a single managed call.cobalt_lcdfband clps711x-fb are converted todevm_platform_get_and_ioremap_resource(); goldfishfb is converted todevm_ioremap_resource(), which also lets us drop the manualiounmap()calls from the error path and remove function.
Quoted 7 lines
For clps711x-fb, resource 1 (the framebuffer range) already used
devm_platform_get_and_ioremap_resource()correctly; this series makes resource 0 (the MMIO control registers) consistent with it.This is part of the ongoing effort described in
Documentation/drm/todo.rst("Request memory regions in all fbdev drivers").
This file does not seem to exist?
Was it hallucinated by Claude:claude-sonnet-4-6?
Quoted 4 lines
Amit Barzilai (3):
fbdev:cobalt_lcdfb: Request memory region
fbdev: clps711x-fb: Request memory region for MMIO
fbdev: goldfishfb: Request memory region
Thanks for your series, which is now commit d2386d9e3eb4c12f ("fbdev:cobalt_lcdfb: Request memory region") and a40c0e815962b1f6 ("fbdev:
clps711x-fb: Request memory region for MMIO") in fbdev/for-next.
Have you tested this series? I have to ask, because adding seemingly-innocent request_mem_region() calls without testing the result is a recurring source of broken drivers.
Thanks!
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Hi Geert,
Quoted 2 lines
This file does not seem to exist?
Was it hallucinated by Claude:claude-sonnet-4-6?
You are right, I apologize. The correct path is Documentation/gpu/todo.rst. I will double-check all references before submitting next time.
Quoted 3 lines
Have you tested this series? I have to ask, because adding seemingly-innocent
request_mem_region()calls without testing the result is a recurring source of broken drivers.
I cross-compiled cobalt_lcdfb against cobalt_defconfig (MIPS) and clps711x-fb against clps711x_defconfig (ARM). Neither platform has a QEMU machine available, so I was not able to do runtime testing.
I understand that is not ideal. The changes replace ioremap() with devm_platform_get_and_ioremap_resource(), which is already widely used across the tree and handles failure cleanly, but I can understand that compile-only testing is not a substitute for hardware validation on resource-sensitive paths.
I have not been able to find a suitable runtime environment for either platform. If you know of one, I have no problem validating these changes properly before they go further.
Thanks,
Amit