staging: comedi: mite: remove mite member 'channel_allocated'
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 2 May 2016 17:11:41 +0000 (10:11 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 3 May 2016 21:11:15 +0000 (14:11 -0700)
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@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/mite.c
drivers/staging/comedi/drivers/mite.h

index 9a74e37bb2f7a4ea5e7918a54646fbd8f1d4c10e..14b5345a93571826f4e09ca998e8a55fbbd45d6d 100644 (file)
@@ -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();
        }
index d1d97eca5fe9409241022a35fe4dd5a8a038b6be..2d97ad4f6d43f90799e2462e61d0285815e5c0d8 100644 (file)
@@ -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 */