Skip to contentSkip to conversation

fbdev: xilinxfb: request memory region before mapping framebuffer

PATCH In review [email protected] 2 participants 4 messages Dec 15, 2025 – Dec 31, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fbdev: xilinxfb: request memory region before mapping framebuffer

From: DiviyamPathak <[email protected]>

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.

---
 drivers/video/fbdev/xilinxfb.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)
drivers/video/fbdev/xilinxfb.c +17 -13
index 0a6e05cd155a..f18437490de8 100644
@@ -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);
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 6 lines · On 12/15/25 23:53, [email protected] wrote:

From: DiviyamPathak <[email protected]>

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.

Quoted 7 lines

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.

Was it tested it on physical hardware?
If not, could someone test?

Helge

Quoted 63 lines
---
  drivers/video/fbdev/xilinxfb.c | 30 +++++++++++++++++-------------
  1 file changed, 17 insertions(+), 13 deletions(-)
drivers/video/fbdev/xilinxfb.c +17 -13
index 0a6e05cd155a..f18437490de8 100644
@@ -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 lore raw

Hi
No, this wasn't tested on actual hardware. I don't have access to it. If someone is able to it that would be great.

Thanks
Diviyam

Quoted 95 lines · Helge Deller,
Quoted 6 lines · On 12/15/25 23:53, [email protected] wrote:

From: DiviyamPathak <[email protected]>

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.

Quoted 7 lines

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.

Was it tested it on physical hardware?
If not, could someone test?

Helge

Review

Quoted 5 lines
---
  drivers/video/fbdev/xilinxfb.c | 30 +++++++++++++++++-------------
  1 file changed, 17 insertions(+), 13 deletions(-)
(quoted diff) +0 -0

b/drivers/video/fbdev/xilinxfb.c

drivers/video/fbdev/xilinxfb.c static int xilinxfb_assign(struct platform_device

Quoted 4 lines

index 0a6e05cd155a..f18437490de8 100644

drivers/video/fbdev/xilinxfb.c +0 -0
@@ -280,19 +280,27 @@ static int xilinxfb_assign(struct platform_device

*pdev,

drivers/video/fbdev/xilinxfb.c static int xilinxfb_assign(struct platform_device *pdev,

Quoted 8 lines
drivers/video/fbdev/xilinxfb.c +4 -1
      /* 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");

drivers/video/fbdev/xilinxfb.c static int xilinxfb_assign(struct platform_device *pdev,

Quoted 3 lines
drivers/video/fbdev/xilinxfb.c +3 -0
+                     return -EBUSY;
+             }
+             drvdata->fb_virt = devm_ioremap(dev, pdata->fb_phys,

fbsize);

drivers/video/fbdev/xilinxfb.c static int xilinxfb_assign(struct platform_device *pdev,

Quoted 7 lines
drivers/video/fbdev/xilinxfb.c +4 -0
+             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),

drivers/video/fbdev/xilinxfb.c static int xilinxfb_assign(struct platform_device *pdev,

Quoted 11 lines
drivers/video/fbdev/xilinxfb.c +4 -7
-                                                   &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");

drivers/video/fbdev/xilinxfb.c static int xilinxfb_assign(struct platform_device

Quoted 8 lines
drivers/video/fbdev/xilinxfb.c +2 -1
+                     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,

drivers/video/fbdev/xilinxfb.c static int xilinxfb_assign(struct platform_device · line 371

Quoted 2 lines
drivers/video/fbdev/xilinxfb.c +0 -0
      if (drvdata->fb_alloced)
              dma_free_coherent(dev, PAGE_ALIGN(fbsize),

drvdata->fb_virt,

drivers/video/fbdev/xilinxfb.c static void xilinxfb_release(struct device *dev) · line 393

Quoted 9 lines
drivers/video/fbdev/xilinxfb.c +0 -2
                                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),

Quoted 6 lines
drivers/video/fbdev/xilinxfb.c +0 -2
                                drvdata->fb_virt, drvdata->fb_phys);
-     else
-             iounmap(drvdata->fb_virt);
 
      /* Turn off the display */
      xilinx_fb_out32(drvdata, REG_CTRL, 0);
#3 lore raw

Hi
No, this wasn't tested on actual hardware. I don't have access to it. If someone is able to do it, that would be great.

Thanks
Diviyam

Quoted 94 lines · Diviyam Pat

Hi
No, this wasn't tested on actual hardware. I don't have access to it. If someone is able to it that would be great.

Thanks
Diviyam

Quoted 86 lines · Helge Deller,
Quoted 6 lines · On 12/15/25 23:53, [email protected] wrote:

From: DiviyamPathak <[email protected]>

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.

Quoted 7 lines

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.

Was it tested it on physical hardware?
If not, could someone test?

Helge

Quoted 63 lines
---
  drivers/video/fbdev/xilinxfb.c | 30 +++++++++++++++++-------------
  1 file changed, 17 insertions(+), 13 deletions(-)
drivers/video/fbdev/xilinxfb.c +17 -13
index 0a6e05cd155a..f18437490de8 100644
@@ -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);