media: ngene: Replace semaphore stream_mutex with mutex
authorBinoy Jayan <binoy.jayan@linaro.org>
Tue, 13 Jun 2017 08:58:49 +0000 (05:58 -0300)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Sat, 24 Jun 2017 19:42:00 +0000 (16:42 -0300)
The semaphore 'stream_mutex' is used as a simple mutex, so
it should be written as one. Also moving the mutex_[lock/unlock]
to the caller as it is anyway locked at the beginning of the
callee thus avoiding repetition.

Signed-off-by: Binoy Jayan <binoy.jayan@linaro.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/pci/ngene/ngene-core.c
drivers/media/pci/ngene/ngene.h

index eeb61ebbfd2e619d641211bdb29cb47cadc67e0f..ea649012b8c744a0c0ba533401cf3e11a4623f14 100644 (file)
@@ -560,7 +560,6 @@ static int ngene_command_stream_control(struct ngene *dev, u8 stream,
        u16 BsSPI = ((stream & 1) ? 0x9800 : 0x9700);
        u16 BsSDO = 0x9B00;
 
-       down(&dev->stream_mutex);
        memset(&com, 0, sizeof(com));
        com.cmd.hdr.Opcode = CMD_CONTROL;
        com.cmd.hdr.Length = sizeof(struct FW_STREAM_CONTROL) - 2;
@@ -586,17 +585,13 @@ static int ngene_command_stream_control(struct ngene *dev, u8 stream,
                        chan->State = KSSTATE_ACQUIRE;
                        chan->HWState = HWSTATE_STOP;
                        spin_unlock_irq(&chan->state_lock);
-                       if (ngene_command(dev, &com) < 0) {
-                               up(&dev->stream_mutex);
+                       if (ngene_command(dev, &com) < 0)
                                return -1;
-                       }
                        /* clear_buffers(chan); */
                        flush_buffers(chan);
-                       up(&dev->stream_mutex);
                        return 0;
                }
                spin_unlock_irq(&chan->state_lock);
-               up(&dev->stream_mutex);
                return 0;
        }
 
@@ -692,11 +687,9 @@ static int ngene_command_stream_control(struct ngene *dev, u8 stream,
                chan->HWState = HWSTATE_STARTUP;
        spin_unlock_irq(&chan->state_lock);
 
-       if (ngene_command(dev, &com) < 0) {
-               up(&dev->stream_mutex);
+       if (ngene_command(dev, &com) < 0)
                return -1;
-       }
-       up(&dev->stream_mutex);
+
        return 0;
 }
 
@@ -750,8 +743,11 @@ void set_transfer(struct ngene_channel *chan, int state)
                /* else printk(KERN_INFO DEVICE_NAME ": lock=%08x\n",
                           ngreadl(0x9310)); */
 
+       mutex_lock(&dev->stream_mutex);
        ret = ngene_command_stream_control(dev, chan->number,
                                           control, mode, flags);
+       mutex_unlock(&dev->stream_mutex);
+
        if (!ret)
                chan->running = state;
        else
@@ -1347,7 +1343,7 @@ static int ngene_start(struct ngene *dev)
        init_waitqueue_head(&dev->tx_wq);
        init_waitqueue_head(&dev->rx_wq);
        mutex_init(&dev->cmd_mutex);
-       sema_init(&dev->stream_mutex, 1);
+       mutex_init(&dev->stream_mutex);
        sema_init(&dev->pll_mutex, 1);
        sema_init(&dev->i2c_switch_mutex, 1);
        spin_lock_init(&dev->cmd_lock);
index e600b70415daa6a15e0e862c5a96fc041cafa171..0dd15d61b8ee93412d8f785c39c3872703ad2368 100644 (file)
@@ -763,7 +763,7 @@ struct ngene {
        wait_queue_head_t     cmd_wq;
        int                   cmd_done;
        struct mutex          cmd_mutex;
-       struct semaphore      stream_mutex;
+       struct mutex          stream_mutex;
        struct semaphore      pll_mutex;
        struct semaphore      i2c_switch_mutex;
        int                   i2c_current_channel;