From 740312ea2635910e9f3e0816e59ca1570c363359 Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Fri, 21 Jan 2011 05:30:55 +0000 Subject: [PATCH] wctdm24xxp, wcte12xp: Close a few potential resource assignment leaks. There were some routes through the failure paths in __voicebus_init() where a registered memory region was not subsequently released. This change closes those paths. The result would be on subsequent loads of the driver after hitting the failure condition you would see "IO Registers are in use by another module." in dmesg. request_mem_region/release_mem_region should most likely be converted to devm_request_region and devm_release_region introduced in 2.6.20 (commit 9ac7849e35f705830f7b016ff272b0ff1f7ff759) which was introduced for reasons just such as this. Signed-off-by: Shaun Ruffell Origin: http://svnview.digium.com/svn/dahdi?view=rev&rev=9503 git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/branches/2.4@9678 a0bf4364-ded3-4de4-8d8a-66a801d63aff --- drivers/dahdi/voicebus/voicebus.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/dahdi/voicebus/voicebus.c b/drivers/dahdi/voicebus/voicebus.c index 702f565..d996356 100644 --- a/drivers/dahdi/voicebus/voicebus.c +++ b/drivers/dahdi/voicebus/voicebus.c @@ -1182,7 +1182,7 @@ voicebus_release(struct voicebus *vb) } release_mem_region(pci_resource_start(vb->pdev, 1), - pci_resource_len(vb->pdev, 1)); + pci_resource_len(vb->pdev, 1)); pci_iounmap(vb->pdev, vb->iobase); pci_clear_mwi(vb->pdev); @@ -1717,6 +1717,7 @@ __voicebus_init(struct voicebus *vb, const char *board_name, enum voicebus_mode mode) { int retval = 0; + int reserved_iomem = 0; BUG_ON(NULL == vb); BUG_ON(NULL == board_name); @@ -1776,12 +1777,17 @@ __voicebus_init(struct voicebus *vb, const char *board_name, goto cleanup; } vb->iobase = pci_iomap(vb->pdev, 1, 0); - if (!request_mem_region(pci_resource_start(vb->pdev, 1), - pci_resource_len(vb->pdev, 1), board_name)) { + if (request_mem_region(pci_resource_start(vb->pdev, 1), + pci_resource_len(vb->pdev, 1), + board_name)) { + reserved_iomem = 1; + } else { dev_err(&vb->pdev->dev, "IO Registers are in use by another " "module.\n"); - retval = -EIO; - goto cleanup; + if (!(*vb->debug)) { + retval = -EIO; + goto cleanup; + } } vb->idle_vbb = dma_alloc_coherent(&vb->pdev->dev, VOICEBUS_SFRAME_SIZE, @@ -1791,8 +1797,6 @@ __voicebus_init(struct voicebus *vb, const char *board_name, Configure the hardware interface. ---------------------------------------------------------------- */ if (pci_set_dma_mask(vb->pdev, DMA_BIT_MASK(32))) { - release_mem_region(pci_resource_start(vb->pdev, 1), - pci_resource_len(vb->pdev, 1)); dev_warn(&vb->pdev->dev, "No suitable DMA available.\n"); goto cleanup; } @@ -1852,6 +1856,11 @@ cleanup: if (vb->pdev) pci_disable_device(vb->pdev); + if (reserved_iomem) { + release_mem_region(pci_resource_start(vb->pdev, 1), + pci_resource_len(vb->pdev, 1)); + } + if (0 == retval) retval = -EIO; return retval;