Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 439926c8 authored by Damian Hobson-Garcia's avatar Damian Hobson-Garcia Committed by Greg Kroah-Hartman
Browse files

drivers: uio_dmem_genirq: Allow partial success when opening device



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: default avatarDamian Hobson-Garcia <dhobsong@igel.co.jp>
Cc: "Hans J. Koch" <hjk@hansjkoch.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 87c4d1a7
Loading
Loading
Loading
Loading
+6 −6
Original line number Original line Diff line number Diff line
@@ -62,8 +62,6 @@ static int uio_dmem_genirq_open(struct uio_info *info, struct inode *inode)
				(dma_addr_t *)&uiomem->addr, GFP_KERNEL);
				(dma_addr_t *)&uiomem->addr, GFP_KERNEL);
		if (!addr) {
		if (!addr) {
			uiomem->addr = DMEM_MAP_ERROR;
			uiomem->addr = DMEM_MAP_ERROR;
			ret = -ENOMEM;
			break;
		}
		}
		priv->dmem_region_vaddr[dmem_region++] = addr;
		priv->dmem_region_vaddr[dmem_region++] = addr;
		++uiomem;
		++uiomem;
@@ -93,11 +91,13 @@ static int uio_dmem_genirq_release(struct uio_info *info, struct inode *inode)
	while (!priv->refcnt && uiomem < &priv->uioinfo->mem[MAX_UIO_MAPS]) {
	while (!priv->refcnt && uiomem < &priv->uioinfo->mem[MAX_UIO_MAPS]) {
		if (!uiomem->size)
		if (!uiomem->size)
			break;
			break;

		if (priv->dmem_region_vaddr[dmem_region]) {
			dma_free_coherent(&priv->pdev->dev, uiomem->size,
			dma_free_coherent(&priv->pdev->dev, uiomem->size,
				priv->dmem_region_vaddr[dmem_region++],
					priv->dmem_region_vaddr[dmem_region],
					uiomem->addr);
					uiomem->addr);
		}
		uiomem->addr = DMEM_MAP_ERROR;
		uiomem->addr = DMEM_MAP_ERROR;
		++dmem_region;
		++uiomem;
		++uiomem;
	}
	}