[PATCH 02/37] staging: comedi: das1800: reduce indent level of das1800_init_dma()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



An IRQ and at least one DMA channel are required to use DMA with this driver.
Move the check to the caller to reduce the indent level of this function.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 drivers/staging/comedi/drivers/das1800.c | 129 ++++++++++++++++---------------
 1 file changed, 65 insertions(+), 64 deletions(-)

diff --git a/drivers/staging/comedi/drivers/das1800.c b/drivers/staging/comedi/drivers/das1800.c
index be825d2..c415b57 100644
--- a/drivers/staging/comedi/drivers/das1800.c
+++ b/drivers/staging/comedi/drivers/das1800.c
@@ -1240,72 +1240,70 @@ static int das1800_init_dma(struct comedi_device *dev, unsigned int dma0,
 	struct das1800_private *devpriv = dev->private;
 	unsigned long flags;
 
-	/*  need an irq to do dma */
-	if (dev->irq && dma0) {
-		/* encode dma0 and dma1 into 2 digit hexadecimal for switch */
-		switch ((dma0 & 0x7) | (dma1 << 4)) {
-		case 0x5:	/*  dma0 == 5 */
-			devpriv->dma_bits |= DMA_CH5;
-			break;
-		case 0x6:	/*  dma0 == 6 */
-			devpriv->dma_bits |= DMA_CH6;
-			break;
-		case 0x7:	/*  dma0 == 7 */
-			devpriv->dma_bits |= DMA_CH7;
-			break;
-		case 0x65:	/*  dma0 == 5, dma1 == 6 */
-			devpriv->dma_bits |= DMA_CH5_CH6;
-			break;
-		case 0x76:	/*  dma0 == 6, dma1 == 7 */
-			devpriv->dma_bits |= DMA_CH6_CH7;
-			break;
-		case 0x57:	/*  dma0 == 7, dma1 == 5 */
-			devpriv->dma_bits |= DMA_CH7_CH5;
-			break;
-		default:
-			dev_err(dev->class_dev,
-				"only supports dma channels 5 through 7\n");
-			dev_err(dev->class_dev,
-				"Dual dma only allows the following combinations:\n");
-			dev_err(dev->class_dev,
-				"dma 5,6 / 6,7 / or 7,5\n");
-			return -EINVAL;
-		}
-		if (request_dma(dma0, dev->driver->driver_name)) {
+	/* encode dma0 and dma1 into 2 digit hexadecimal for switch */
+	switch ((dma0 & 0x7) | (dma1 << 4)) {
+	case 0x5:	/*  dma0 == 5 */
+		devpriv->dma_bits |= DMA_CH5;
+		break;
+	case 0x6:	/*  dma0 == 6 */
+		devpriv->dma_bits |= DMA_CH6;
+		break;
+	case 0x7:	/*  dma0 == 7 */
+		devpriv->dma_bits |= DMA_CH7;
+		break;
+	case 0x65:	/*  dma0 == 5, dma1 == 6 */
+		devpriv->dma_bits |= DMA_CH5_CH6;
+		break;
+	case 0x76:	/*  dma0 == 6, dma1 == 7 */
+		devpriv->dma_bits |= DMA_CH6_CH7;
+		break;
+	case 0x57:	/*  dma0 == 7, dma1 == 5 */
+		devpriv->dma_bits |= DMA_CH7_CH5;
+		break;
+	default:
+		dev_err(dev->class_dev,
+			"only supports dma channels 5 through 7\n");
+		dev_err(dev->class_dev,
+			"Dual dma only allows the following combinations:\n");
+		dev_err(dev->class_dev,
+			"dma 5,6 / 6,7 / or 7,5\n");
+		return -EINVAL;
+	}
+	if (request_dma(dma0, dev->driver->driver_name)) {
+		dev_err(dev->class_dev,
+			"failed to allocate dma channel %i\n", dma0);
+		return -EINVAL;
+	}
+	devpriv->dma0 = dma0;
+	devpriv->dma_current = dma0;
+	if (dma1) {
+		if (request_dma(dma1, dev->driver->driver_name)) {
 			dev_err(dev->class_dev,
-				"failed to allocate dma channel %i\n", dma0);
+				"failed to allocate dma channel %i\n",
+				dma1);
 			return -EINVAL;
 		}
-		devpriv->dma0 = dma0;
-		devpriv->dma_current = dma0;
-		if (dma1) {
-			if (request_dma(dma1, dev->driver->driver_name)) {
-				dev_err(dev->class_dev,
-					"failed to allocate dma channel %i\n",
-					dma1);
-				return -EINVAL;
-			}
-			devpriv->dma1 = dma1;
-		}
-		devpriv->ai_buf0 = kmalloc(DMA_BUF_SIZE, GFP_KERNEL | GFP_DMA);
-		if (devpriv->ai_buf0 == NULL)
+		devpriv->dma1 = dma1;
+	}
+	devpriv->ai_buf0 = kmalloc(DMA_BUF_SIZE, GFP_KERNEL | GFP_DMA);
+	if (devpriv->ai_buf0 == NULL)
+		return -ENOMEM;
+	devpriv->dma_current_buf = devpriv->ai_buf0;
+	if (dma1) {
+		devpriv->ai_buf1 =
+			kmalloc(DMA_BUF_SIZE, GFP_KERNEL | GFP_DMA);
+		if (devpriv->ai_buf1 == NULL)
 			return -ENOMEM;
-		devpriv->dma_current_buf = devpriv->ai_buf0;
-		if (dma1) {
-			devpriv->ai_buf1 =
-			    kmalloc(DMA_BUF_SIZE, GFP_KERNEL | GFP_DMA);
-			if (devpriv->ai_buf1 == NULL)
-				return -ENOMEM;
-		}
-		flags = claim_dma_lock();
-		disable_dma(devpriv->dma0);
-		set_dma_mode(devpriv->dma0, DMA_MODE_READ);
-		if (dma1) {
-			disable_dma(devpriv->dma1);
-			set_dma_mode(devpriv->dma1, DMA_MODE_READ);
-		}
-		release_dma_lock(flags);
 	}
+	flags = claim_dma_lock();
+	disable_dma(devpriv->dma0);
+	set_dma_mode(devpriv->dma0, DMA_MODE_READ);
+	if (dma1) {
+		disable_dma(devpriv->dma1);
+		set_dma_mode(devpriv->dma1, DMA_MODE_READ);
+	}
+	release_dma_lock(flags);
+
 	return 0;
 }
 
@@ -1437,9 +1435,12 @@ static int das1800_attach(struct comedi_device *dev,
 		}
 	}
 
-	ret = das1800_init_dma(dev, dma0, dma1);
-	if (ret < 0)
-		return ret;
+	/* an irq and one dma channel is required to use dma */
+	if (dev->irq & dma0) {
+		ret = das1800_init_dma(dev, dma0, dma1);
+		if (ret < 0)
+			return ret;
+	}
 
 	if (devpriv->ai_buf0 == NULL) {
 		devpriv->ai_buf0 =
-- 
2.0.3

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux