[PATCH 08/19] staging: comedi: mite: remove mite member 'channel_allocated'

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

 



An allocated mite_channel will have its 'ring' member initialized
to point to the mite_ring that will be used for DMA. A non-allocated
mite_channel will have a 'ring' member set to NULL, either by a
channel release or due to the initial kzalloc of the 'mite' struct.

Refactor the code to use the mite_chan->ring to detect in a channel
is allocated and remove the unnecessary member.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 drivers/staging/comedi/drivers/mite.c | 17 ++++++++---------
 drivers/staging/comedi/drivers/mite.h |  1 -
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/comedi/drivers/mite.c b/drivers/staging/comedi/drivers/mite.c
index 9a74e37..14b5345 100644
--- a/drivers/staging/comedi/drivers/mite.c
+++ b/drivers/staging/comedi/drivers/mite.c
@@ -392,9 +392,9 @@ struct mite_channel *mite_request_channel_in_range(struct mite *mite,
 						   unsigned int min_channel,
 						   unsigned int max_channel)
 {
-	int i;
+	struct mite_channel *mite_chan = NULL;
 	unsigned long flags;
-	struct mite_channel *channel = NULL;
+	int i;
 
 	/*
 	 * spin lock so mite_release_channel can be called safely
@@ -402,15 +402,15 @@ struct mite_channel *mite_request_channel_in_range(struct mite *mite,
 	 */
 	spin_lock_irqsave(&mite->lock, flags);
 	for (i = min_channel; i <= max_channel; ++i) {
-		if (mite->channel_allocated[i] == 0) {
-			mite->channel_allocated[i] = 1;
-			channel = &mite->channels[i];
-			channel->ring = ring;
+		mite_chan = &mite->channels[i];
+		if (!mite_chan->ring) {
+			mite_chan->ring = ring;
 			break;
 		}
+		mite_chan = NULL;
 	}
 	spin_unlock_irqrestore(&mite->lock, flags);
-	return channel;
+	return mite_chan;
 }
 EXPORT_SYMBOL_GPL(mite_request_channel_in_range);
 
@@ -421,7 +421,7 @@ void mite_release_channel(struct mite_channel *mite_chan)
 
 	/* spin lock to prevent races with mite_request_channel */
 	spin_lock_irqsave(&mite->lock, flags);
-	if (mite->channel_allocated[mite_chan->channel]) {
+	if (mite_chan->ring) {
 		mite_dma_disarm(mite_chan);
 		mite_dma_reset(mite_chan);
 		/*
@@ -433,7 +433,6 @@ void mite_release_channel(struct mite_channel *mite_chan)
 		       CHCR_CLR_MRDY_IE | CHCR_CLR_DRDY_IE |
 		       CHCR_CLR_LC_IE | CHCR_CLR_CONT_RB_IE,
 		       mite->mmio + MITE_CHCR(mite_chan->channel));
-		mite->channel_allocated[mite_chan->channel] = 0;
 		mite_chan->ring = NULL;
 		mmiowb();
 	}
diff --git a/drivers/staging/comedi/drivers/mite.h b/drivers/staging/comedi/drivers/mite.h
index d1d97ec..2d97ad4 100644
--- a/drivers/staging/comedi/drivers/mite.h
+++ b/drivers/staging/comedi/drivers/mite.h
@@ -54,7 +54,6 @@ struct mite {
 	struct pci_dev *pcidev;
 	void __iomem *mmio;
 	struct mite_channel channels[MAX_MITE_DMA_CHANNELS];
-	short channel_allocated[MAX_MITE_DMA_CHANNELS];
 	int num_channels;
 	unsigned int fifo_size;
 	/* protects mite_channel from being released by the driver */
-- 
2.6.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