blob: bd53c57a656068cf3d5094c472a3cd49783d8133 [file] [log] [blame]
From dhobsong@igel.co.jp Wed Nov 21 18:27:22 2012
From: Damian Hobson-Garcia <dhobsong@igel.co.jp>
Date: Thu, 22 Nov 2012 11:26:52 +0900
Subject: [PATCH 5/6] drivers: uio_dmem_genirq: Allow partial success when opening device
To: gregkh@linuxfoundation.org
Cc: ltsi-dev@lists.linuxfoundation.org, Damian Hobson-Garcia <dhobsong@igel.co.jp>
Message-ID: <1353551213-17996-6-git-send-email-dhobsong@igel.co.jp>
The uio device should not fail on open just because one memory allocation
fails. The device might export several regions, the failure of some of
which may or may not be a problem for the user space driver. Failing
regions will remain unmapped, and successful regions will be mapped and
exported to user space. Also deals with the case where failing to map
a region after successfully allocating others would not unmap the
successfully allocated regions before dying.
Signed-off-by: Damian Hobson-Garcia <dhobsong@igel.co.jp>
---
drivers/uio/uio_dmem_genirq.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
--- a/drivers/uio/uio_dmem_genirq.c
+++ b/drivers/uio/uio_dmem_genirq.c
@@ -62,8 +62,6 @@ static int uio_dmem_genirq_open(struct u
(dma_addr_t *)&uiomem->addr, GFP_KERNEL);
if (!addr) {
uiomem->addr = DMEM_MAP_ERROR;
- ret = -ENOMEM;
- break;
}
priv->dmem_region_vaddr[dmem_region++] = addr;
++uiomem;
@@ -93,11 +91,13 @@ static int uio_dmem_genirq_release(struc
while (!priv->refcnt && uiomem < &priv->uioinfo->mem[MAX_UIO_MAPS]) {
if (!uiomem->size)
break;
-
- dma_free_coherent(&priv->pdev->dev, uiomem->size,
- priv->dmem_region_vaddr[dmem_region++],
- uiomem->addr);
+ if (priv->dmem_region_vaddr[dmem_region]) {
+ dma_free_coherent(&priv->pdev->dev, uiomem->size,
+ priv->dmem_region_vaddr[dmem_region],
+ uiomem->addr);
+ }
uiomem->addr = DMEM_MAP_ERROR;
+ ++dmem_region;
++uiomem;
}