From 5a731c70bc79d3d41f37d9bf4ab4d549333bff37 Mon Sep 17 00:00:00 2001 From: Ksenija Stanojevic Date: Fri, 2 Oct 2015 22:09:43 +0200 Subject: [PATCH] Staging: comedi: Use mutex instead of semaphore in ni_usb6501.c 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 Reviewed-by: Arnd Bergmann Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/ni_usb6501.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/staging/comedi/drivers/ni_usb6501.c b/drivers/staging/comedi/drivers/ni_usb6501.c index 88de8da3eff3..95b537a8ecdb 100644 --- a/drivers/staging/comedi/drivers/ni_usb6501.c +++ b/drivers/staging/comedi/drivers/ni_usb6501.c @@ -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 = { -- 2.30.2