Staging: comedi: Use mutex instead of semaphore in ni_usb6501.c
authorKsenija Stanojevic <ksenija.stanojevic@gmail.com>
Fri, 2 Oct 2015 20:09:43 +0000 (22:09 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 4 Oct 2015 08:32:56 +0000 (09:32 +0100)
Replace binary semaphore with mutex because mutex gives better
performance.
This change is safe because the thread that decrements the value of semaphore
is also the one that increments it, and acts like a mutex where owner of the
lock is the only one that can release the lock.

Signed-off-by: Ksenija Stanojevic <ksenija.stanojevic@gmail.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/ni_usb6501.c

index 88de8da3eff3f272669f23a0b1d11929bb31daf7..95b537a8ecdb13b17e9d753f22a6c0dd04c60f99 100644 (file)
@@ -166,7 +166,7 @@ enum commands {
 struct ni6501_private {
        struct usb_endpoint_descriptor *ep_rx;
        struct usb_endpoint_descriptor *ep_tx;
-       struct semaphore sem;
+       struct mutex mut;
        u8 *usb_rx_buf;
        u8 *usb_tx_buf;
 };
@@ -183,7 +183,7 @@ static int ni6501_port_command(struct comedi_device *dev, int command,
        if (command != SET_PORT_DIR && !bitmap)
                return -EINVAL;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        switch (command) {
        case READ_PORT:
@@ -248,7 +248,7 @@ static int ni6501_port_command(struct comedi_device *dev, int command,
                ret = -EINVAL;
        }
 end:
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret;
 }
@@ -265,7 +265,7 @@ static int ni6501_counter_command(struct comedi_device *dev, int command,
        if ((command == READ_COUNTER || command ==  WRITE_COUNTER) && !val)
                return -EINVAL;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        switch (command) {
        case START_COUNTER:
@@ -338,7 +338,7 @@ static int ni6501_counter_command(struct comedi_device *dev, int command,
                ret = -EINVAL;
        }
 end:
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret;
 }
@@ -535,7 +535,7 @@ static int ni6501_auto_attach(struct comedi_device *dev,
        if (ret)
                return ret;
 
-       sema_init(&devpriv->sem, 1);
+       mutex_init(&devpriv->mut);
        usb_set_intfdata(intf, devpriv);
 
        ret = comedi_alloc_subdevices(dev, 2);
@@ -573,14 +573,14 @@ static void ni6501_detach(struct comedi_device *dev)
        if (!devpriv)
                return;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        usb_set_intfdata(intf, NULL);
 
        kfree(devpriv->usb_rx_buf);
        kfree(devpriv->usb_tx_buf);
 
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 }
 
 static struct comedi_driver ni6501_driver = {