Skip to contentSkip to conversation

video: fbdev: Request IO ports

PATCH New Daniel Matyas 2 participants 2 messages Nov 11

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

PATCH 1/1 video: fbdev: Request IO ports

Some fbdev drivers do not request their memory correctly. Request the IO ports' memory so no other driver may access them. Only request 1 byte, because the inb() and out() are used for reading and writing.

Did not test on hardware.

---
 drivers/video/fbdev/arcfb.c | 8 ++++++++
 drivers/video/fbdev/n411.c  | 5 +++++
 2 files changed, 13 insertions(+)
drivers/video/fbdev/arcfb.c +8 -0
index b807cf07522d..6771a7409cde 100644
@@ -481,6 +481,14 @@ static int arcfb_probe(struct platform_device *dev)
 		printk(KERN_WARNING "no IO addresses supplied\n");
 		goto err_addr;
 	}
+
+	if (!devm_request_region(&dev->dev, dio_addr, 1, "arcfb") ||
+		!devm_request_region(&dev->dev, cio_addr, 1, "arcfb") ||
+		!devm_request_region(&dev->dev, c2io_addr, 1, "arcfb")) {
+		retval = -EBUSY;
+		goto err_addr;
+	}
+
 	par->dio_addr = dio_addr;
 	par->cio_addr = cio_addr;
 	par->c2io_addr = c2io_addr;
drivers/video/fbdev/n411.c +5 -0
index a3677313396e..ed0281939d37 100644
@@ -165,6 +165,11 @@ static int __init n411_init(void)
 	if (!n411_device)
 		return -ENOMEM;
 
+	if (!devm_request_region(&n411_device->dev, dio_addr, 1, "n411") ||
+		!devm_request_region(&n411_device->dev, cio_addr, 1, "n411") ||
+		!devm_request_region(&n411_device->dev, c2io_addr, 1, "n411"))
+		return -EBUSY;
+
 	ret = platform_device_add_data(n411_device, &n411_board,
 				       sizeof(n411_board));
 	if (ret)
Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] fbdev: n411: devm_request_region() in n411_init() breaks hecubafb probing - [Medium] fbdev: n411…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] fbdev: n411: devm_request_region() in n411_init() breaks hecubafb probing
- [Medium] fbdev: n411: leak of n411_device and I/O regions in n411_init() on error
--

commit 233a6d07f214976aca6e2d815559082f7aaf9dc7
Author: Daniel Matyas <[email protected]>

video: fbdev: Request IO ports

This commit requests the I/O port regions used by the arcfb and n411 framebuffer drivers via devm_request_region().

drivers/video/fbdev/n411.c static int __init n411_init(void) · line 170

Quoted 11 lines
drivers/video/fbdev/n411.c +3 -0
index a3677313396e2..ed0281939d37d 100644
@@ -165,6 +165,11 @@ static int __init n411_init(void)
 	if (!n411_device)
 		return -ENOMEM;
 
+	if (!devm_request_region(&n411_device->dev, dio_addr, 1, "n411") ||
+		!devm_request_region(&n411_device->dev, cio_addr, 1, "n411") ||
+		!devm_request_region(&n411_device->dev, c2io_addr, 1, "n411"))

[Severity: High]
Does calling devm_request_region() on &n411_device->dev before platform_device_add() prevent the hecubafb driver from binding to n411_device?

Each devm_request_region() call adds an entry to n411_device->dev.devres_head. When platform_device_add(n411_device) later attempts to bind the driver, really_probe() rejects any device that already has devres entries:

drivers/base/dd.c:really_probe() {
	...
	if (!list_empty(&dev->devres_head)) {
		dev_crit(dev, "Resources present before probing\n");
		ret = -EBUSY;
		goto done;
	}
	...
}

As a result, probing always fails with -EBUSY and the display device remains unbound.

drivers/video/fbdev/n411.c static int __init n411_init(void) · line 171

Quoted 1 line
drivers/video/fbdev/n411.c +1 -0
+		return -EBUSY;

[Severity: Medium]
Does returning -EBUSY directly here leak n411_device and any I/O port regions already claimed by the preceding devm_request_region() calls? Jumping to put_plat_device instead would call platform_device_put() and release the allocated device and its managed resources.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1