Skip to contentSkip to conversation

fbdev/hga: Request memory region before ioremap

PATCH Superseded Hardik Phalet 2 participants 2 messages Mar 10 Framebuffer layer

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 fbdev/hga: Request memory region before ioremap

The driver calls ioremap() on the HGA video memory at 0xb0000 without first reserving the physical address range. This leaves the kernel resource tree incomplete and can cause silent conflicts with other drivers claiming the same range.

Add a devm_request_mem_region() call before ioremap() in hga_card_detect() to reserve the memory region.

---
Changes in v2:
- Used devm_request_mem_region instead of request_mem_region, based on a review comment by Thomas [1].

v1: https://lore.kernel.org/all/[email protected]/
[1]: https://lore.kernel.org/all/[email protected]/

 drivers/video/fbdev/hgafb.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/video/fbdev/hgafb.c +7 -2
index 14418aa3791a..fffd34141f8d 100644
@@ -276,7 +276,7 @@ static void hga_blank(int blank_mode)
 	spin_unlock_irqrestore(&hga_reg_lock, flags);
 }
 
-static int hga_card_detect(void)
+static int hga_card_detect(struct platform_device *pdev)
 {
 	int count = 0;
 	void __iomem *p, *q;
@@ -284,6 +284,11 @@ static int hga_card_detect(void)
 
 	hga_vram_len  = 0x08000;
 
+	if (!devm_request_mem_region(&pdev->dev, 0xb0000, hga_vram_len, "hgafb")) {
+		pr_err("hgafb: cannot reserve video memory at 0xb0000\n");
+		return -EBUSY;
+	}
+
 	hga_vram = ioremap(0xb0000, hga_vram_len);
 	if (!hga_vram)
 		return -ENOMEM;
@@ -568,7 +573,7 @@ static int hgafb_probe(struct platform_device *pdev)
 	struct fb_info *info;
 	int ret;
 
-	ret = hga_card_detect();
+	ret = hga_card_detect(pdev);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.53.0
#1 lore raw

Hi

Am 10.03.26 um 12:38 schrieb Hardik Phalet:

Quoted 34 lines

The driver calls ioremap() on the HGA video memory at 0xb0000 without first reserving the physical address range. This leaves the kernel resource tree incomplete and can cause silent conflicts with other drivers claiming the same range.

Add a devm_request_mem_region() call before ioremap() in hga_card_detect() to reserve the memory region.

---
Changes in v2:
- Used devm_request_mem_region instead of request_mem_region, based on a review comment by Thomas [1].

v1: https://lore.kernel.org/all/[email protected]/
[1]: https://lore.kernel.org/all/[email protected]/

  drivers/video/fbdev/hgafb.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
drivers/video/fbdev/hgafb.c +1 -1
index 14418aa3791a..fffd34141f8d 100644
@@ -276,7 +276,7 @@ static void hga_blank(int blank_mode)
  	spin_unlock_irqrestore(&hga_reg_lock, flags);
  }
 
-static int hga_card_detect(void)
+static int hga_card_detect(struct platform_device *pdev)
  {
  	int count = 0;
  	void __iomem *p, *q;

drivers/video/fbdev/hgafb.c static int hga_card_detect(void) · line 288

Quoted 5 lines
drivers/video/fbdev/hgafb.c +2 -0
@@ -284,6 +284,11 @@ static int hga_card_detect(void)
 
  	hga_vram_len  = 0x08000;
 
+	if (!devm_request_mem_region(&pdev->dev, 0xb0000, hga_vram_len, "hgafb")) {
+		pr_err("hgafb: cannot reserve video memory at 0xb0000\n");

dev_err() with pdev->dev please.

The rest looks good.

Best regards
Thomas

Quoted 15 lines
drivers/video/fbdev/hgafb.c +4 -1
+		return -EBUSY;
+	}
+
  	hga_vram = ioremap(0xb0000, hga_vram_len);
  	if (!hga_vram)
  		return -ENOMEM;
@@ -568,7 +573,7 @@ static int hgafb_probe(struct platform_device *pdev)
  	struct fb_info *info;
  	int ret;
 
-	ret = hga_card_detect();
+	ret = hga_card_detect(pdev);
  	if (ret)
  		return ret;
 
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)