Linux Framebuffer Layer development
 help / color / mirror / Atom feed
* [PATCH] fbdev: xilinxfb: request memory region before mapping framebuffer
@ 2025-12-15 22:53 patdiviyam
  2025-12-30  9:57 ` Helge Deller
  0 siblings, 1 reply; 3+ messages in thread
From: patdiviyam @ 2025-12-15 22:53 UTC (permalink / raw)
  To: dri-devel; +Cc: tzimmermann, deller, linux-fbdev, DiviyamPathak

From: DiviyamPathak <patdiviyam@gmail.com>

The xilinxfb driver maps a physical framebuffer address with ioremap()
without first reserving the memory region. This can conflict with other
drivers accessing the same resource.

Request the memory region with devm_request_mem_region() before mapping
the framebuffer and use managed mappings for proper lifetime handling.

This addresses the fbdev TODO about requesting memory regions and avoids
potential resource conflicts.

Signed-off-by: DiviyamPathak <patdiviyam@gmail.com>
---
 drivers/video/fbdev/xilinxfb.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/drivers/video/fbdev/xilinxfb.c b/drivers/video/fbdev/xilinxfb.c
index 0a6e05cd155a..f18437490de8 100644
--- a/drivers/video/fbdev/xilinxfb.c
+++ b/drivers/video/fbdev/xilinxfb.c
@@ -280,19 +280,27 @@ static int xilinxfb_assign(struct platform_device *pdev,
 	/* Allocate the framebuffer memory */
 	if (pdata->fb_phys) {
 		drvdata->fb_phys = pdata->fb_phys;
-		drvdata->fb_virt = ioremap(pdata->fb_phys, fbsize);
+		/* Request the memory region before mapping */
+		if (!devm_request_mem_region(dev, pdata->fb_phys, fbsize,
+					DRIVER_NAME)) {
+			dev_err(dev, "Cannot request framebuffer memory region\n");
+			return -EBUSY;
+		}
+		drvdata->fb_virt = devm_ioremap(dev, pdata->fb_phys, fbsize);
+		if (!drvdata->fb_virt) {
+			dev_err(dev, "Could not map framebuffer memory\n");
+			return -ENOMEM;
+		}
 	} else {
 		drvdata->fb_alloced = 1;
 		drvdata->fb_virt = dma_alloc_coherent(dev, PAGE_ALIGN(fbsize),
-						      &drvdata->fb_phys,
-						      GFP_KERNEL);
-	}
-
-	if (!drvdata->fb_virt) {
-		dev_err(dev, "Could not allocate frame buffer memory\n");
-		return -ENOMEM;
+					&drvdata->fb_phys,
+					GFP_KERNEL);
+		if (!drvdata->fb_virt) {
+			dev_err(dev, "Could not allocate frame buffer memory\n");
+			return -ENOMEM;
+		}
 	}
-
 	/* Clear (turn to black) the framebuffer */
 	memset_io((void __iomem *)drvdata->fb_virt, 0, fbsize);
 
@@ -362,8 +370,6 @@ static int xilinxfb_assign(struct platform_device *pdev,
 	if (drvdata->fb_alloced)
 		dma_free_coherent(dev, PAGE_ALIGN(fbsize), drvdata->fb_virt,
 				  drvdata->fb_phys);
-	else
-		iounmap(drvdata->fb_virt);
 
 	/* Turn off the display */
 	xilinx_fb_out32(drvdata, REG_CTRL, 0);
@@ -386,8 +392,6 @@ static void xilinxfb_release(struct device *dev)
 	if (drvdata->fb_alloced)
 		dma_free_coherent(dev, PAGE_ALIGN(drvdata->info.fix.smem_len),
 				  drvdata->fb_virt, drvdata->fb_phys);
-	else
-		iounmap(drvdata->fb_virt);
 
 	/* Turn off the display */
 	xilinx_fb_out32(drvdata, REG_CTRL, 0);
-- 
2.43.0


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

end of thread, other threads:[~2025-12-31  1:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-15 22:53 [PATCH] fbdev: xilinxfb: request memory region before mapping framebuffer patdiviyam
2025-12-30  9:57 ` Helge Deller
     [not found]   ` <CAM19b+s73Fo6Ej85qk72UPn12VQ_iFAYpHv7K=wOapb0-+1XBA@mail.gmail.com>
2025-12-31  1:12     ` Diviyam Pat

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