Re: [PATCH 1/2] staging: comedi: cb_pcidas64: refactor out function

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

 



On 27/02/17 21:08, Tobin C. Harding wrote:
Function contains code at differing levels of abstraction. This is
shown by the fact that conditional is loop-invariant. Code may be
refactored out into a separate function.

Refactor out loop body to separate function. Do not alter original
code structure of loop body (to ease review). Add local variables to
new function in identical manner to calling function.

Signed-off-by: Tobin C. Harding <me@xxxxxxxx>
---
 drivers/staging/comedi/drivers/cb_pcidas64.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/comedi/drivers/cb_pcidas64.c b/drivers/staging/comedi/drivers/cb_pcidas64.c
index 3b98193..385f007 100644
--- a/drivers/staging/comedi/drivers/cb_pcidas64.c
+++ b/drivers/staging/comedi/drivers/cb_pcidas64.c
@@ -1480,12 +1480,29 @@ static void init_stc_registers(struct comedi_device *dev)
 	disable_ai_pacing(dev);
 };

+static int alloc_dma_member(int i, struct comedi_device *dev)

It would be better if the parameters were reversed for consistency with other functions, where the 'struct comedi_device *' parameter comes first.

Also, the function name could be improved as the function that calls its allocates various DMA things. This is allocating a DMA buffer for the the AO subdevice, so perhaps the name could be 'alloc_dma_ao_buffer'.

+{
+	struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+	struct pcidas64_private *devpriv = dev->private;
+
+	devpriv->ao_buffer[i] =
+		dma_alloc_coherent(&pcidev->dev,
+				DMA_BUFFER_SIZE,
+				&devpriv->
+				ao_buffer_bus_addr[i],
+				GFP_KERNEL);
+	if (!devpriv->ao_buffer[i])
+		return -ENOMEM;
+	return 0;
+}
+
 static int alloc_and_init_dma_members(struct comedi_device *dev)
 {
 	const struct pcidas64_board *board = dev->board_ptr;
 	struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 	struct pcidas64_private *devpriv = dev->private;
 	int i;
+	int ret;

 	/* allocate pci dma buffers */
 	for (i = 0; i < ai_dma_ring_count(board); i++) {
@@ -1498,14 +1515,9 @@ static int alloc_and_init_dma_members(struct comedi_device *dev)
 	}
 	for (i = 0; i < AO_DMA_RING_COUNT; i++) {
 		if (ao_cmd_is_supported(board)) {
-			devpriv->ao_buffer[i] =
-				dma_alloc_coherent(&pcidev->dev,
-						   DMA_BUFFER_SIZE,
-						   &devpriv->
-						   ao_buffer_bus_addr[i],
-						   GFP_KERNEL);
-			if (!devpriv->ao_buffer[i])
-				return -ENOMEM;
+			ret = alloc_dma_member(i, dev);
+			if (ret)
+				return ret; /* -ENOMEM */
 		}
 	}
 	/* allocate dma descriptors */



--
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@xxxxxxxxx> )=-
-=(                          Web: http://www.mev.co.uk/  )=-
_______________________________________________
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