* [PATCH 0/5] use mutex instead of semaphore in several drivers
@ 2007-07-13 19:20 Matthias Kaehlcke
2007-07-13 19:23 ` [PATCH 1/5] use mutex instead of semaphore in SPI core/init code Matthias Kaehlcke
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Matthias Kaehlcke @ 2007-07-13 19:20 UTC (permalink / raw)
To: linux-kernel, akpm
This patchset converts semaphores that are used as mutexes to the
mutex API in the following drivers/code:
SPI core/init code
USB gadget serial
ELAN U132 adapter
Adutux
FTDI ELAN
--
Matthias Kaehlcke
Linux Application Developer
Barcelona
You must have a plan. If you don't have a plan,
you'll become part of somebody else's plan
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/5] use mutex instead of semaphore in SPI core/init code
2007-07-13 19:20 [PATCH 0/5] use mutex instead of semaphore in several drivers Matthias Kaehlcke
@ 2007-07-13 19:23 ` Matthias Kaehlcke
2007-07-13 19:59 ` David Brownell
2007-07-13 19:25 ` [PATCH 2/5] use mutex instead of semaphore in the USB gadget serial driver Matthias Kaehlcke
` (3 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Matthias Kaehlcke @ 2007-07-13 19:23 UTC (permalink / raw)
To: dbrownell, spi-devel-general; +Cc: linux-kernel, akpm
The SPI core/init code uses a semaphore as mutex. Use the mutex
API instead of the (binary) semaphore.
Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>
--
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 4831edb..018884d 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -23,6 +23,7 @@
#include <linux/device.h>
#include <linux/init.h>
#include <linux/cache.h>
+#include <linux/mutex.h>
#include <linux/spi/spi.h>
@@ -185,7 +186,7 @@ struct boardinfo {
};
static LIST_HEAD(board_list);
-static DECLARE_MUTEX(board_lock);
+static DEFINE_MUTEX(board_lock);
/**
@@ -292,9 +293,9 @@ spi_register_board_info(struct spi_board_info const *info, unsigned n)
bi->n_board_info = n;
memcpy(bi->board_info, info, n * sizeof *info);
- down(&board_lock);
+ mutex_lock(&board_lock);
list_add_tail(&bi->list, &board_list);
- up(&board_lock);
+ mutex_unlock(&board_lock);
return 0;
}
@@ -308,7 +309,7 @@ scan_boardinfo(struct spi_master *master)
struct boardinfo *bi;
struct device *dev = master->cdev.dev;
- down(&board_lock);
+ mutex_lock(&board_lock);
list_for_each_entry(bi, &board_list, list) {
struct spi_board_info *chip = bi->board_info;
unsigned n;
@@ -330,7 +331,7 @@ scan_boardinfo(struct spi_master *master)
(void) spi_new_device(master, chip);
}
}
- up(&board_lock);
+ mutex_unlock(&board_lock);
}
/*-------------------------------------------------------------------------*/
--
Matthias Kaehlcke
Linux Application Developer
Barcelona
Ma patrie est où je suis, où personne ne me dérange, où personne
ne me demande que je suis, d'où je viens et ce que je fais
(B. Traven)
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/5] use mutex instead of semaphore in the USB gadget serial driver
2007-07-13 19:20 [PATCH 0/5] use mutex instead of semaphore in several drivers Matthias Kaehlcke
2007-07-13 19:23 ` [PATCH 1/5] use mutex instead of semaphore in SPI core/init code Matthias Kaehlcke
@ 2007-07-13 19:25 ` Matthias Kaehlcke
2007-07-13 20:00 ` David Brownell
2007-07-13 19:26 ` [PATCH 3/5] use mutex instead of semaphore in the ELAN U132 adapter driver Matthias Kaehlcke
` (2 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Matthias Kaehlcke @ 2007-07-13 19:25 UTC (permalink / raw)
To: dbrownell, linux-usb-devel; +Cc: linux-kernel, akpm
The USB gadget serial driver uses a semaphore as mutex. Use the
mutex API instead of the (binary) semaphore.
Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>
--
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index dd33ff0..4192d24 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -33,6 +33,7 @@
#include <linux/device.h>
#include <linux/tty.h>
#include <linux/tty_flip.h>
+#include <linux/mutex.h>
#include <asm/byteorder.h>
#include <asm/io.h>
@@ -258,7 +259,7 @@ static const char *EP_IN_NAME;
static const char *EP_OUT_NAME;
static const char *EP_NOTIFY_NAME;
-static struct semaphore gs_open_close_sem[GS_NUM_PORTS];
+static struct mutex gs_open_close_lock[GS_NUM_PORTS];
static unsigned int read_q_size = GS_DEFAULT_READ_Q_SIZE;
static unsigned int write_q_size = GS_DEFAULT_WRITE_Q_SIZE;
@@ -595,7 +596,7 @@ static int __init gs_module_init(void)
tty_set_operations(gs_tty_driver, &gs_tty_ops);
for (i=0; i < GS_NUM_PORTS; i++)
- sema_init(&gs_open_close_sem[i], 1);
+ mutex_init(&gs_open_close_lock[i]);
retval = tty_register_driver(gs_tty_driver);
if (retval) {
@@ -635,7 +636,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
struct gs_port *port;
struct gs_dev *dev;
struct gs_buf *buf;
- struct semaphore *sem;
+ struct mutex *mtx;
int ret;
port_num = tty->index;
@@ -656,10 +657,10 @@ static int gs_open(struct tty_struct *tty, struct file *file)
return -ENODEV;
}
- sem = &gs_open_close_sem[port_num];
- if (down_interruptible(sem)) {
+ mtx = &gs_open_close_lock[port_num];
+ if (mutex_lock_interruptible(mtx)) {
printk(KERN_ERR
- "gs_open: (%d,%p,%p) interrupted waiting for semaphore\n",
+ "gs_open: (%d,%p,%p) interrupted waiting for mutex\n",
port_num, tty, file);
return -ERESTARTSYS;
}
@@ -754,12 +755,12 @@ static int gs_open(struct tty_struct *tty, struct file *file)
exit_unlock_port:
spin_unlock_irqrestore(&port->port_lock, flags);
- up(sem);
+ mutex_unlock(mtx);
return ret;
exit_unlock_dev:
spin_unlock_irqrestore(&dev->dev_lock, flags);
- up(sem);
+ mutex_unlock(mtx);
return ret;
}
@@ -781,7 +782,7 @@ exit_unlock_dev:
static void gs_close(struct tty_struct *tty, struct file *file)
{
struct gs_port *port = tty->driver_data;
- struct semaphore *sem;
+ struct mutex *mtx;
if (port == NULL) {
printk(KERN_ERR "gs_close: NULL port pointer\n");
@@ -790,8 +791,8 @@ static void gs_close(struct tty_struct *tty, struct file *file)
gs_debug("gs_close: (%d,%p,%p)\n", port->port_num, tty, file);
- sem = &gs_open_close_sem[port->port_num];
- down(sem);
+ mtx = &gs_open_close_lock[port->port_num];
+ mutex_lock(mtx);
spin_lock_irq(&port->port_lock);
@@ -846,7 +847,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
exit:
spin_unlock_irq(&port->port_lock);
- up(sem);
+ mutex_unlock(mtx);
}
/*
--
Matthias Kaehlcke
Linux Application Developer
Barcelona
If liberty means anything at all, it means the
right to tell people what they do not want to hear
(George Orwell)
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/5] use mutex instead of semaphore in the ELAN U132 adapter driver
2007-07-13 19:20 [PATCH 0/5] use mutex instead of semaphore in several drivers Matthias Kaehlcke
2007-07-13 19:23 ` [PATCH 1/5] use mutex instead of semaphore in SPI core/init code Matthias Kaehlcke
2007-07-13 19:25 ` [PATCH 2/5] use mutex instead of semaphore in the USB gadget serial driver Matthias Kaehlcke
@ 2007-07-13 19:26 ` Matthias Kaehlcke
2007-07-13 19:28 ` [PATCH 4/5] use mutex instead of semaphore in the Adutux driver Matthias Kaehlcke
2007-07-13 19:29 ` [PATCH 5/5] use mutex instead of semaphore in the FTDI ELAN driver Matthias Kaehlcke
4 siblings, 0 replies; 8+ messages in thread
From: Matthias Kaehlcke @ 2007-07-13 19:26 UTC (permalink / raw)
To: gregkh, linux-usb-users, linux-usb-devel; +Cc: linux-kernel, akpm
The ELAN U132 adapter driver uses the semaphore u132_module_lock
as mutex. Use the mutex API instead of the (binary) semaphore.
Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>
--
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index e98df2e..7f765ec 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -52,6 +52,7 @@
#include <linux/workqueue.h>
#include <linux/platform_device.h>
#include <linux/pci_ids.h>
+#include <linux/mutex.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/system.h>
@@ -83,7 +84,7 @@ static DECLARE_WAIT_QUEUE_HEAD(u132_hcd_wait);
* u132_module_lock exists to protect access to global variables
*
*/
-static struct semaphore u132_module_lock;
+static struct mutex u132_module_lock;
static int u132_exiting = 0;
static int u132_instances = 0;
static struct list_head u132_static_list;
@@ -258,10 +259,10 @@ static void u132_hcd_delete(struct kref *kref)
struct platform_device *pdev = u132->platform_dev;
struct usb_hcd *hcd = u132_to_hcd(u132);
u132->going += 1;
- down(&u132_module_lock);
+ mutex_lock(&u132_module_lock);
list_del_init(&u132->u132_list);
u132_instances -= 1;
- up(&u132_module_lock);
+ mutex_unlock(&u132_module_lock);
dev_warn(&u132->platform_dev->dev, "FREEING the hcd=%p and thus the u13"
"2=%p going=%d pdev=%p\n", hcd, u132, u132->going, pdev);
usb_put_hcd(hcd);
@@ -3111,10 +3112,10 @@ static int __devinit u132_probe(struct platform_device *pdev)
int retval = 0;
struct u132 *u132 = hcd_to_u132(hcd);
hcd->rsrc_start = 0;
- down(&u132_module_lock);
+ mutex_lock(&u132_module_lock);
list_add_tail(&u132->u132_list, &u132_static_list);
u132->sequence_num = ++u132_instances;
- up(&u132_module_lock);
+ mutex_unlock(&u132_module_lock);
u132_u132_init_kref(u132);
u132_initialise(u132, pdev);
hcd->product_desc = "ELAN U132 Host Controller";
@@ -3216,7 +3217,7 @@ static int __init u132_hcd_init(void)
INIT_LIST_HEAD(&u132_static_list);
u132_instances = 0;
u132_exiting = 0;
- init_MUTEX(&u132_module_lock);
+ mutex_init(&u132_module_lock);
if (usb_disabled())
return -ENODEV;
printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__,
@@ -3232,9 +3233,9 @@ static void __exit u132_hcd_exit(void)
{
struct u132 *u132;
struct u132 *temp;
- down(&u132_module_lock);
+ mutex_lock(&u132_module_lock);
u132_exiting += 1;
- up(&u132_module_lock);
+ mutex_unlock(&u132_module_lock);
list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) {
platform_device_unregister(u132->platform_dev);
} platform_driver_unregister(&u132_platform_driver);
--
Matthias Kaehlcke
Linux Application Developer
Barcelona
The salvation of mankind lies only in making everything the concern of all
(Alexander Solzhenitsyn)
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/5] use mutex instead of semaphore in the Adutux driver
2007-07-13 19:20 [PATCH 0/5] use mutex instead of semaphore in several drivers Matthias Kaehlcke
` (2 preceding siblings ...)
2007-07-13 19:26 ` [PATCH 3/5] use mutex instead of semaphore in the ELAN U132 adapter driver Matthias Kaehlcke
@ 2007-07-13 19:28 ` Matthias Kaehlcke
2007-07-13 19:29 ` [PATCH 5/5] use mutex instead of semaphore in the FTDI ELAN driver Matthias Kaehlcke
4 siblings, 0 replies; 8+ messages in thread
From: Matthias Kaehlcke @ 2007-07-13 19:28 UTC (permalink / raw)
To: gregkh, linux-usb-users, linux-usb-devel; +Cc: linux-kernel, akpm
The Adutux driver uses a semaphore as mutex. Use the mutex API
instead of the (binary) semaphore.
Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>
--
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
index d72c42e..274d08e 100644
--- a/drivers/usb/misc/adutux.c
+++ b/drivers/usb/misc/adutux.c
@@ -24,6 +24,7 @@
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/usb.h>
+#include <linux/mutex.h>
#include <asm/uaccess.h>
#ifdef CONFIG_USB_DEBUG
@@ -80,7 +81,7 @@ MODULE_DEVICE_TABLE(usb, device_table);
/* Structure to hold all of our device specific stuff */
struct adu_device {
- struct semaphore sem; /* locks this structure */
+ struct mutex mtx; /* locks this structure */
struct usb_device* udev; /* save off the usb device pointer */
struct usb_interface* interface;
unsigned char minor; /* the starting minor number for this device */
@@ -269,8 +270,8 @@ static int adu_open(struct inode *inode, struct file *file)
}
/* lock this device */
- if ((retval = down_interruptible(&dev->sem))) {
- dbg(2, "%s : sem down failed", __FUNCTION__);
+ if ((retval = mutex_lock_interruptible(&dev->mtx))) {
+ dbg(2, "%s : mutex lock failed", __FUNCTION__);
goto exit_no_device;
}
@@ -299,7 +300,7 @@ static int adu_open(struct inode *inode, struct file *file)
if (retval)
--dev->open_count;
}
- up(&dev->sem);
+ mutex_unlock(&dev->mtx);
exit_no_device:
dbg(2,"%s : leave, return value %d ", __FUNCTION__, retval);
@@ -347,7 +348,7 @@ static int adu_release(struct inode *inode, struct file *file)
}
/* lock our device */
- down(&dev->sem); /* not interruptible */
+ mutex_lock(&dev->mtx); /* not interruptible */
if (dev->open_count <= 0) {
dbg(1," %s : device not opened", __FUNCTION__);
@@ -357,7 +358,7 @@ static int adu_release(struct inode *inode, struct file *file)
if (dev->udev == NULL) {
/* the device was unplugged before the file was released */
- up(&dev->sem);
+ mutex_unlock(&dev->mtx);
adu_delete(dev);
dev = NULL;
} else {
@@ -367,7 +368,7 @@ static int adu_release(struct inode *inode, struct file *file)
exit:
if (dev)
- up(&dev->sem);
+ mutex_unlock(&dev->mtx);
dbg(2," %s : leave, return value %d", __FUNCTION__, retval);
return retval;
}
@@ -390,7 +391,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
dev = file->private_data;
dbg(2," %s : dev=%p", __FUNCTION__, dev);
/* lock this object */
- if (down_interruptible(&dev->sem))
+ if (mutex_lock_interruptible(&dev->mtx))
return -ERESTARTSYS;
/* verify that the device wasn't unplugged */
@@ -522,7 +523,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
exit:
/* unlock the device */
- up(&dev->sem);
+ mutex_unlock(&dev->mtx);
dbg(2," %s : leave, return value %d", __FUNCTION__, retval);
return retval;
@@ -543,7 +544,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
dev = file->private_data;
/* lock this object */
- retval = down_interruptible(&dev->sem);
+ retval = mutex_lock_interruptible(&dev->mtx);
if (retval)
goto exit_nolock;
@@ -571,9 +572,9 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
retval = -EINTR;
goto exit;
}
- up(&dev->sem);
+ mutex_unlock(&dev->mtx);
timeout = interruptible_sleep_on_timeout(&dev->write_wait, timeout);
- retval = down_interruptible(&dev->sem);
+ retval = mutex_lock_interruptible(&dev->mtx);
if (retval) {
retval = bytes_written ? bytes_written : retval;
goto exit_nolock;
@@ -638,7 +639,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
exit:
/* unlock the device */
- up(&dev->sem);
+ mutex_unlock(&dev->mtx);
exit_nolock:
dbg(2," %s : leave, return value %d", __FUNCTION__, retval);
@@ -698,7 +699,7 @@ static int adu_probe(struct usb_interface *interface,
goto exit;
}
- init_MUTEX(&dev->sem);
+ mutex_init(&dev->mtx);
spin_lock_init(&dev->buflock);
dev->udev = udev;
init_waitqueue_head(&dev->read_wait);
@@ -835,16 +836,16 @@ static void adu_disconnect(struct usb_interface *interface)
usb_deregister_dev(interface, &adu_class);
dev->minor = 0;
- down(&dev->sem); /* not interruptible */
+ mutex_lock(&dev->mtx); /* not interruptible */
/* if the device is not opened, then we clean up right now */
dbg(2," %s : open count %d", __FUNCTION__, dev->open_count);
if (!dev->open_count) {
- up(&dev->sem);
+ mutex_unlock(&dev->mtx);
adu_delete(dev);
} else {
dev->udev = NULL;
- up(&dev->sem);
+ mutex_unlock(&dev->mtx);
}
dev_info(&interface->dev, "ADU device adutux%d now disconnected",
--
Matthias Kaehlcke
Linux Application Developer
Barcelona
The assumption that what currently exists must necessarily
exist is the acid that corrodes all visionary thinking
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5/5] use mutex instead of semaphore in the FTDI ELAN driver
2007-07-13 19:20 [PATCH 0/5] use mutex instead of semaphore in several drivers Matthias Kaehlcke
` (3 preceding siblings ...)
2007-07-13 19:28 ` [PATCH 4/5] use mutex instead of semaphore in the Adutux driver Matthias Kaehlcke
@ 2007-07-13 19:29 ` Matthias Kaehlcke
4 siblings, 0 replies; 8+ messages in thread
From: Matthias Kaehlcke @ 2007-07-13 19:29 UTC (permalink / raw)
To: gregkh, linux-usb-users, linux-usb-devel; +Cc: linux-kernel, akpm
The FTDI ELAN driver uses a semaphore as mutex. Use the mutex API
instead of the (binary) semaphore.
Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>
--
diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index e0f122e..7cc6883 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -44,6 +44,7 @@
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/kref.h>
+#include <linux/mutex.h>
#include <asm/uaccess.h>
#include <linux/usb.h>
#include <linux/workqueue.h>
@@ -64,7 +65,7 @@ static struct workqueue_struct *respond_queue;
* ftdi_module_lock exists to protect access to global variables
*
*/
-static struct semaphore ftdi_module_lock;
+static struct mutex ftdi_module_lock;
static int ftdi_instances = 0;
static struct list_head ftdi_static_list;
/*
@@ -199,10 +200,10 @@ static void ftdi_elan_delete(struct kref *kref)
dev_warn(&ftdi->udev->dev, "FREEING ftdi=%p\n", ftdi);
usb_put_dev(ftdi->udev);
ftdi->disconnected += 1;
- down(&ftdi_module_lock);
+ mutex_lock(&ftdi_module_lock);
list_del_init(&ftdi->ftdi_list);
ftdi_instances -= 1;
- up(&ftdi_module_lock);
+ mutex_unlock(&ftdi_module_lock);
kfree(ftdi->bulk_in_buffer);
ftdi->bulk_in_buffer = NULL;
}
@@ -2780,10 +2781,10 @@ static int ftdi_elan_probe(struct usb_interface *interface,
return -ENOMEM;
}
memset(ftdi, 0x00, sizeof(struct usb_ftdi));
- down(&ftdi_module_lock);
+ mutex_lock(&ftdi_module_lock);
list_add_tail(&ftdi->ftdi_list, &ftdi_static_list);
ftdi->sequence_num = ++ftdi_instances;
- up(&ftdi_module_lock);
+ mutex_unlock(&ftdi_module_lock);
ftdi_elan_init_kref(ftdi);
init_MUTEX(&ftdi->sw_lock);
ftdi->udev = usb_get_dev(interface_to_usbdev(interface));
@@ -2909,7 +2910,7 @@ static int __init ftdi_elan_init(void)
int result;
printk(KERN_INFO "driver %s built at %s on %s\n", ftdi_elan_driver.name,
__TIME__, __DATE__);
- init_MUTEX(&ftdi_module_lock);
+ mutex_init(&ftdi_module_lock);
INIT_LIST_HEAD(&ftdi_static_list);
status_queue = create_singlethread_workqueue("ftdi-status-control");
if (!status_queue)
--
Matthias Kaehlcke
Linux Application Developer
Barcelona
If liberty means anything at all, it means the
right to tell people what they do not want to hear
(George Orwell)
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/5] use mutex instead of semaphore in SPI core/init code
2007-07-13 19:23 ` [PATCH 1/5] use mutex instead of semaphore in SPI core/init code Matthias Kaehlcke
@ 2007-07-13 19:59 ` David Brownell
0 siblings, 0 replies; 8+ messages in thread
From: David Brownell @ 2007-07-13 19:59 UTC (permalink / raw)
To: Matthias Kaehlcke; +Cc: dbrownell, spi-devel-general, linux-kernel, akpm
On Friday 13 July 2007, Matthias Kaehlcke wrote:
> The SPI core/init code uses a semaphore as mutex. Use the mutex
> API instead of the (binary) semaphore.
>
> Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>
ACK ... and thanks!
>
> --
>
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 4831edb..018884d 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -23,6 +23,7 @@
> #include <linux/device.h>
> #include <linux/init.h>
> #include <linux/cache.h>
> +#include <linux/mutex.h>
> #include <linux/spi/spi.h>
>
>
> @@ -185,7 +186,7 @@ struct boardinfo {
> };
>
> static LIST_HEAD(board_list);
> -static DECLARE_MUTEX(board_lock);
> +static DEFINE_MUTEX(board_lock);
>
>
> /**
> @@ -292,9 +293,9 @@ spi_register_board_info(struct spi_board_info const *info, unsigned n)
> bi->n_board_info = n;
> memcpy(bi->board_info, info, n * sizeof *info);
>
> - down(&board_lock);
> + mutex_lock(&board_lock);
> list_add_tail(&bi->list, &board_list);
> - up(&board_lock);
> + mutex_unlock(&board_lock);
> return 0;
> }
>
> @@ -308,7 +309,7 @@ scan_boardinfo(struct spi_master *master)
> struct boardinfo *bi;
> struct device *dev = master->cdev.dev;
>
> - down(&board_lock);
> + mutex_lock(&board_lock);
> list_for_each_entry(bi, &board_list, list) {
> struct spi_board_info *chip = bi->board_info;
> unsigned n;
> @@ -330,7 +331,7 @@ scan_boardinfo(struct spi_master *master)
> (void) spi_new_device(master, chip);
> }
> }
> - up(&board_lock);
> + mutex_unlock(&board_lock);
> }
>
> /*-------------------------------------------------------------------------*/
>
> --
> Matthias Kaehlcke
> Linux Application Developer
> Barcelona
>
> Ma patrie est où je suis, où personne ne me dérange, où personne
> ne me demande que je suis, d'où je viens et ce que je fais
> (B. Traven)
> .''`.
> using free software / Debian GNU/Linux | http://debian.org : :' :
> `. `'`
> gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/5] use mutex instead of semaphore in the USB gadget serial driver
2007-07-13 19:25 ` [PATCH 2/5] use mutex instead of semaphore in the USB gadget serial driver Matthias Kaehlcke
@ 2007-07-13 20:00 ` David Brownell
0 siblings, 0 replies; 8+ messages in thread
From: David Brownell @ 2007-07-13 20:00 UTC (permalink / raw)
To: Matthias Kaehlcke
Cc: dbrownell, linux-usb-devel, linux-kernel, akpm, alborchers
On Friday 13 July 2007, Matthias Kaehlcke wrote:
> The USB gadget serial driver uses a semaphore as mutex. Use the
> mutex API instead of the (binary) semaphore.
>
> Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>
ACK (and thanks)
>
> --
>
> diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
> index dd33ff0..4192d24 100644
> --- a/drivers/usb/gadget/serial.c
> +++ b/drivers/usb/gadget/serial.c
> @@ -33,6 +33,7 @@
> #include <linux/device.h>
> #include <linux/tty.h>
> #include <linux/tty_flip.h>
> +#include <linux/mutex.h>
>
> #include <asm/byteorder.h>
> #include <asm/io.h>
> @@ -258,7 +259,7 @@ static const char *EP_IN_NAME;
> static const char *EP_OUT_NAME;
> static const char *EP_NOTIFY_NAME;
>
> -static struct semaphore gs_open_close_sem[GS_NUM_PORTS];
> +static struct mutex gs_open_close_lock[GS_NUM_PORTS];
>
> static unsigned int read_q_size = GS_DEFAULT_READ_Q_SIZE;
> static unsigned int write_q_size = GS_DEFAULT_WRITE_Q_SIZE;
> @@ -595,7 +596,7 @@ static int __init gs_module_init(void)
> tty_set_operations(gs_tty_driver, &gs_tty_ops);
>
> for (i=0; i < GS_NUM_PORTS; i++)
> - sema_init(&gs_open_close_sem[i], 1);
> + mutex_init(&gs_open_close_lock[i]);
>
> retval = tty_register_driver(gs_tty_driver);
> if (retval) {
> @@ -635,7 +636,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
> struct gs_port *port;
> struct gs_dev *dev;
> struct gs_buf *buf;
> - struct semaphore *sem;
> + struct mutex *mtx;
> int ret;
>
> port_num = tty->index;
> @@ -656,10 +657,10 @@ static int gs_open(struct tty_struct *tty, struct file *file)
> return -ENODEV;
> }
>
> - sem = &gs_open_close_sem[port_num];
> - if (down_interruptible(sem)) {
> + mtx = &gs_open_close_lock[port_num];
> + if (mutex_lock_interruptible(mtx)) {
> printk(KERN_ERR
> - "gs_open: (%d,%p,%p) interrupted waiting for semaphore\n",
> + "gs_open: (%d,%p,%p) interrupted waiting for mutex\n",
> port_num, tty, file);
> return -ERESTARTSYS;
> }
> @@ -754,12 +755,12 @@ static int gs_open(struct tty_struct *tty, struct file *file)
>
> exit_unlock_port:
> spin_unlock_irqrestore(&port->port_lock, flags);
> - up(sem);
> + mutex_unlock(mtx);
> return ret;
>
> exit_unlock_dev:
> spin_unlock_irqrestore(&dev->dev_lock, flags);
> - up(sem);
> + mutex_unlock(mtx);
> return ret;
>
> }
> @@ -781,7 +782,7 @@ exit_unlock_dev:
> static void gs_close(struct tty_struct *tty, struct file *file)
> {
> struct gs_port *port = tty->driver_data;
> - struct semaphore *sem;
> + struct mutex *mtx;
>
> if (port == NULL) {
> printk(KERN_ERR "gs_close: NULL port pointer\n");
> @@ -790,8 +791,8 @@ static void gs_close(struct tty_struct *tty, struct file *file)
>
> gs_debug("gs_close: (%d,%p,%p)\n", port->port_num, tty, file);
>
> - sem = &gs_open_close_sem[port->port_num];
> - down(sem);
> + mtx = &gs_open_close_lock[port->port_num];
> + mutex_lock(mtx);
>
> spin_lock_irq(&port->port_lock);
>
> @@ -846,7 +847,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
>
> exit:
> spin_unlock_irq(&port->port_lock);
> - up(sem);
> + mutex_unlock(mtx);
> }
>
> /*
>
> --
> Matthias Kaehlcke
> Linux Application Developer
> Barcelona
>
> If liberty means anything at all, it means the
> right to tell people what they do not want to hear
> (George Orwell)
> .''`.
> using free software / Debian GNU/Linux | http://debian.org : :' :
> `. `'`
> gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-
>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2007-07-13 20:01 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-13 19:20 [PATCH 0/5] use mutex instead of semaphore in several drivers Matthias Kaehlcke
2007-07-13 19:23 ` [PATCH 1/5] use mutex instead of semaphore in SPI core/init code Matthias Kaehlcke
2007-07-13 19:59 ` David Brownell
2007-07-13 19:25 ` [PATCH 2/5] use mutex instead of semaphore in the USB gadget serial driver Matthias Kaehlcke
2007-07-13 20:00 ` David Brownell
2007-07-13 19:26 ` [PATCH 3/5] use mutex instead of semaphore in the ELAN U132 adapter driver Matthias Kaehlcke
2007-07-13 19:28 ` [PATCH 4/5] use mutex instead of semaphore in the Adutux driver Matthias Kaehlcke
2007-07-13 19:29 ` [PATCH 5/5] use mutex instead of semaphore in the FTDI ELAN driver Matthias Kaehlcke
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox