Skip to contentSkip to conversation

gpio: bt8xx: use devm_ioremap_resource()

PATCH Applied Rosen Penev 2 participants 2 messages Jul 13 – Jul 17

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

PATCH 1/1 gpio: bt8xx: use devm_ioremap_resource()

Replace the open-coded devm_request_mem_region() plus devm_ioremap() sequence with a single devm_ioremap_resource() call on the BAR0 resource. This reserves the region and maps it in one step, and maps the full BAR length instead of a hardcoded 0x1000 (BAR0 on the bt848/878 is a 4KB register block, so the mapped size is unchanged).

devm_ioremap_resource() returns an ERR_PTR on failure, so check with IS_ERR() and propagate PTR_ERR(). Drop the now-redundant error message, as devm_ioremap_resource() already logs on every failure path. Since it can return -EPROBE_DEFER, place it early.

Built for ARM (defconfig + CONFIG_GPIO_BT8XX) with LLVM=1; drivers/gpio/gpio-bt8xx.o compiles cleanly.

Assisted-by opencode:hy3-free
---
 drivers/gpio/gpio-bt8xx.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)
drivers/gpio/gpio-bt8xx.c +6 -15
index 324eeb77dbd5..f3a2321bc388 100644
@@ -154,12 +154,18 @@ static int bt8xxgpio_probe(struct pci_dev *dev,
 			const struct pci_device_id *pci_id)
 {
 	struct bt8xxgpio *bg;
+	void __iomem *mmio;
 	int err;
 
+	mmio = devm_ioremap_resource(&dev->dev, pci_resource_n(dev, 0));
+	if (IS_ERR(mmio))
+		return PTR_ERR(mmio);
+
 	bg = devm_kzalloc(&dev->dev, sizeof(struct bt8xxgpio), GFP_KERNEL);
 	if (!bg)
 		return -ENOMEM;
 
+	bg->mmio = mmio;
 	bg->pdev = dev;
 	spin_lock_init(&bg->lock);
 
@@ -168,24 +174,9 @@ static int bt8xxgpio_probe(struct pci_dev *dev,
 		dev_err(&dev->dev, "can't enable device.\n");
 		return err;
 	}
-	if (!devm_request_mem_region(&dev->dev, pci_resource_start(dev, 0),
-				pci_resource_len(dev, 0),
-				"bt8xxgpio")) {
-		dev_warn(&dev->dev, "can't request iomem (0x%llx).\n",
-		       (unsigned long long)pci_resource_start(dev, 0));
-		err = -EBUSY;
-		goto err_disable;
-	}
 	pci_set_master(dev);
 	pci_set_drvdata(dev, bg);
 
-	bg->mmio = devm_ioremap(&dev->dev, pci_resource_start(dev, 0), 0x1000);
-	if (!bg->mmio) {
-		dev_err(&dev->dev, "ioremap() failed\n");
-		err = -EIO;
-		goto err_disable;
-	}
-
 	/* Disable interrupts */
 	bgwrite(0, BT848_INT_MASK);
 
Signature · 1 line
2.55.0
#1 lore raw
Quoted 6 lines · Rosen Penev

Replace the open-coded devm_request_mem_region() plus devm_ioremap() sequence with a single devm_ioremap_resource() call on the BAR0 resource. This reserves the region and maps it in one step, and maps the full BAR length instead of a hardcoded 0x1000 (BAR0 on the bt848/878 is a 4KB register block, so the mapped size is unchanged).

Quoted 6 lines

devm_ioremap_resource() returns an ERR_PTR on failure, so check with IS_ERR() and propagate PTR_ERR(). Drop the now-redundant error message, as devm_ioremap_resource() already logs on every failure path. Since it can return -EPROBE_DEFER, place it early.

[...]

Applied, thanks!

[1/1] gpio: bt8xx: use devm_ioremap_resource()

      https://git.kernel.org/brgl/c/bbd8254da11c189072349003006091e8327e8d36

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>