Skip to contentSkip to conversation

sound: pci: asihpi: use pcim_iomap for managed PCI memory mapping

PATCH Applied Rosen Penev 2 participants 2 messages Aug 11 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sound: pci: asihpi: use pcim_iomap for managed PCI memory mapping

Replace manual ioremap() calls with pcim_iomap() which uses devres for automatic cleanup. This eliminates the need for manual iounmap() in both the error path of asihpi_adapter_probe() and the asihpi_adapter_remove() function.

The pcim_iomap() helper is cleaner and less error-prone since it handles unmapping automatically when the PCI device is released.

Assisted-by opencode/big-pickle
---
 sound/pci/asihpi/hpioctl.c | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)
sound/pci/asihpi/hpioctl.c +1 -16
index 9de9ae7032b8..ec2da792e1c8 100644
@@ -385,8 +385,7 @@ int asihpi_adapter_probe(struct pci_dev *pci_dev,
 		if (pci_resource_flags(pci_dev, idx) & IORESOURCE_MEM) {
 			memlen = pci_resource_len(pci_dev, idx);
 			pci.ap_mem_base[idx] =
-				ioremap(pci_resource_start(pci_dev, idx),
-				memlen);
+				pcim_iomap(pci_dev, idx, memlen);
 			if (!pci.ap_mem_base[idx]) {
 				HPI_DEBUG_LOG(ERROR,
 					"ioremap failed, aborting\n");
@@ -509,13 +508,6 @@ int asihpi_adapter_probe(struct pci_dev *pci_dev,
 	return 0;
 
 err:
-	while (--idx >= 0) {
-		if (pci.ap_mem_base[idx]) {
-			iounmap(pci.ap_mem_base[idx]);
-			pci.ap_mem_base[idx] = NULL;
-		}
-	}
-
 	if (adapter.p_buffer) {
 		adapter.buffer_size = 0;
 		vfree(adapter.p_buffer);
@@ -527,14 +519,11 @@ int asihpi_adapter_probe(struct pci_dev *pci_dev,
 
 void asihpi_adapter_remove(struct pci_dev *pci_dev)
 {
-	int idx;
 	struct hpi_message hm;
 	struct hpi_response hr;
 	struct hpi_adapter *pa;
-	struct hpi_pci pci;
 
 	pa = pci_get_drvdata(pci_dev);
-	pci = pa->adapter->pci;
 
 	/* Disable IRQ generation on DSP side */
 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
@@ -550,10 +539,6 @@ void asihpi_adapter_remove(struct pci_dev *pci_dev)
 	hm.adapter_index = pa->adapter->index;
 	hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL);
 
-	/* unmap PCI memory space, mapped during device init. */
-	for (idx = 0; idx < HPI_MAX_ADAPTER_MEM_SPACES; ++idx)
-		iounmap(pci.ap_mem_base[idx]);
-
 	if (pa->irq)
 		free_irq(pa->irq, pa);
 
Signature · 1 line
2.55.0
Applied
#1 lore raw
Quoted 11 lines · Rosen Penev

Replace manual ioremap() calls with pcim_iomap() which uses devres for automatic cleanup. This eliminates the need for manual iounmap() in both the error path of asihpi_adapter_probe() and the asihpi_adapter_remove() function.

The pcim_iomap() helper is cleaner and less error-prone since it handles unmapping automatically when the PCI device is released.

Assisted-by opencode/big-pickle

Applied to for-next branch. Thanks.

Takashi