use mutex instead of semaphore in several drivers
Subsystems (5)
cover use mutex instead of semaphore in several drivers
This patchset converts semaphores that are used as mutexes to the mutex API in the following drivers:
Megaraid Mailbox
Philips webcam
SMSC LPC47M192
Virtual Video
VLSI 82C147 IrDA controller
Signature · 11 lines
Matthias Kaehlcke
Linux Application Developer
Barcelona
Insanity: doing the same thing over and over
again and expecting different results
(Albert Einstein)
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-PATCH 1/5 use mutex instead of semaphore in Megaraid Mailbox driver
The Megaraid Mailbox driver uses a semaphore as mutex. Use the mutex API instead of the (binary) semaphore.
--
drivers/scsi/megaraid/mega_common.h +1 -0
@@ -21,6 +21,7 @@#include <linux/types.h> #include <linux/pci.h> #include <linux/spinlock.h> +#include <linux/mutex.h> #include <linux/interrupt.h> #include <linux/delay.h> #include <linux/blkdev.h>
drivers/scsi/megaraid/megaraid_mbox.c +3 -3
@@ -3957,7 +3957,7 @@ megaraid_sysfs_alloc_resources(adapter_t *adapter)megaraid_sysfs_free_resources (adapter); } -sema_init (&raid_dev->sysfs_sem,1 ); +mutex_init (&raid_dev->sysfs_mtx);init_waitqueue_head (&raid_dev->sysfs_wait_q);
@@ -4058,7 +4058,7 @@ megaraid_sysfs_get_ldmap(adapter_t *adapter)/* * Allow only one read at a time to go through the sysfs attributes */ -down (&raid_dev->sysfs_sem); +mutex_lock (&raid_dev->sysfs_mtx); uioc = raid_dev->sysfs_uioc; mbox64 = raid_dev->sysfs_mbox64;
@@ -4134,7 +4134,7 @@ megaraid_sysfs_get_ldmap(adapter_t *adapter)del_timer_sync (timerp); -up (&raid_dev->sysfs_sem); +mutex_unlock (&raid_dev->sysfs_mtx);return rval; }
drivers/scsi/megaraid/megaraid_mbox.h +2 -2
@@ -168,7 +168,7 @@ typedef struct {* @hw_error : set if FW not responding * @fast_load : If set, skip physical device scanning * @channel_class : channel class, RAID or SCSI -* @sysfs_sem : semaphore to serialize access to sysfs res. +* @sysfs_mtx : mutex to serialize access to sysfs res. * @sysfs_uioc : management packet to issue FW calls from sysfs * @sysfs_mbox64 : mailbox packet to issue FW calls from sysfs * @sysfs_buffer : data buffer for FW commands issued from sysfs
@@ -208,7 +208,7 @@ typedef struct {int hw_error;int fast_load;uint8_t channel_class; -struct semaphore sysfs_sem; +struct mutex sysfs_mtx;uioc_t *sysfs_uioc;mbox64_t *sysfs_mbox64;caddr_t sysfs_buffer;
Signature · 10 lines
Matthias Kaehlcke
Linux Application Developer
Barcelona
An ounce of practice is worth more than tons of preaching
(Mahatma Gandhi)
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-RE: [PATCH 1/5] use mutex instead of semaphore in Megaraid Mailbox driver
Thank you Matthias for the patch.
Regards,
Sumant
-----Original Message-----
From: Matthias Kaehlcke [mailto:[email protected]]
Sent: Sunday, July 01, 2007 9:29 AM
To: DL-MegaRAID Linux; [email protected]
Cc: [email protected]; [email protected]
Subject: [PATCH 1/5] use mutex instead of semaphore in Megaraid Mailbox driver
The Megaraid Mailbox driver uses a semaphore as mutex. Use the mutex API instead of the (binary) semaphore.
--
(quoted diff) +0 -0
b/drivers/scsi/megaraid/mega_common.h
index 26e1e6c..fef9ac9 100644
drivers/scsi/megaraid/mega_common.h +1 -0
@@ -21,6 +21,7 @@#include <linux/types.h> #include <linux/pci.h> #include <linux/spinlock.h> +#include <linux/mutex.h> #include <linux/interrupt.h> #include <linux/delay.h> #include <linux/blkdev.h>
(quoted diff) +0 -0
b/drivers/scsi/megaraid/megaraid_mbox.c
index 04d0b69..2cecc64 100644
drivers/scsi/megaraid/megaraid_mbox.c +1 -1
@@ -3957,7 +3957,7 @@ megaraid_sysfs_alloc_resources(adapter_t *adapter)megaraid_sysfs_free_resources (adapter); } -sema_init (&raid_dev->sysfs_sem,1 ); +mutex_init (&raid_dev->sysfs_mtx);init_waitqueue_head (&raid_dev->sysfs_wait_q);
@@ -4058,7 +4058,7 @@ megaraid_sysfs_get_ldmap(adapter_t *adapter)/* * Allow only one read at a time to go through the sysfs
attributes
*/
- down(&raid_dev->sysfs_sem);
+ mutex_lock(&raid_dev->sysfs_mtx);
uioc = raid_dev->sysfs_uioc;
mbox64 = raid_dev->sysfs_mbox64;
@@ -4134,7 +4134,7 @@ megaraid_sysfs_get_ldmap(adapter_t *adapter)
del_timer_sync(timerp);
- up(&raid_dev->sysfs_sem);
+ mutex_unlock(&raid_dev->sysfs_mtx);
return rval;
}
(quoted diff) +0 -0
b/drivers/scsi/megaraid/megaraid_mbox.h
index 9de803c..626459d 100644
drivers/scsi/megaraid/megaraid_mbox.h +0 -1
@@ -168,7 +168,7 @@ typedef struct {* @hw_error : set if FW not responding * @fast_load : If set, skip physical device scanning * @channel_class : channel class, RAID or SCSI -* @sysfs_sem : semaphore to serialize access to sysfs
res.
+ * @sysfs_mtx : mutex to serialize access to sysfs
res.
* @sysfs_uioc : management packet to issue FW calls
from sysfs
* @sysfs_mbox64 : mailbox packet to issue FW calls from
sysfs
* @sysfs_buffer : data buffer for FW commands issued
from sysfs
@@ -208,7 +208,7 @@ typedef struct {
int hw_error;
int fast_load;
uint8_t channel_class;
- struct semaphore sysfs_sem;
+ struct mutex sysfs_mtx;
uioc_t *sysfs_uioc;
mbox64_t *sysfs_mbox64;
caddr_t sysfs_buffer;
--
Matthias Kaehlcke
Linux Application Developer
Barcelona
An ounce of practice is worth more than tons of preaching
(Mahatma Gandhi)
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
. '`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-
PATCH 2/5 use mutex instead of semaphore in Philips webcam driver
In reply to Matthias KaehlckeThe Philips webcam driver uses a semaphore as mutex. Use the mutex API instead of the (binary) semaphore.
--
drivers/media/video/pwc/pwc-if.c +6 -6
@@ -1099,7 +1099,7 @@ static int pwc_video_open(struct inode *inode, struct file *file)return -EBUSY ; } -down (&pdev->modlock); +mutex_lock (&pdev->modlock);if (!pdev->usb_init) {PWC_DEBUG_OPEN ("Doing first time initialization.\n" ); pdev->usb_init =1 ;
@@ -1131,7 +1131,7 @@ static int pwc_video_open(struct inode *inode, struct file *file)if (i <0 ) {PWC_DEBUG_OPEN ("Failed to allocate buffers memory.\n" );pwc_free_buffers (pdev); -up (&pdev->modlock); +mutex_unlock (&pdev->modlock);return i; }
@@ -1172,7 +1172,7 @@ static int pwc_video_open(struct inode *inode, struct file *file)if (i) {PWC_DEBUG_OPEN ("Second attempt at set_video_mode failed.\n" );pwc_free_buffers (pdev); -up (&pdev->modlock); +mutex_unlock (&pdev->modlock);return i; }
@@ -1181,7 +1181,7 @@ static int pwc_video_open(struct inode *inode, struct file *file)PWC_DEBUG_OPEN ("Failed to init ISOC stuff = %d.\n" , i);pwc_isoc_cleanup (pdev);pwc_free_buffers (pdev); -up (&pdev->modlock); +mutex_unlock (&pdev->modlock);return i; }
@@ -1191,7 +1191,7 @@ static int pwc_video_open(struct inode *inode, struct file *file) pdev->vopen++; file->private_data = vdev; -up (&pdev->modlock); +mutex_unlock (&pdev->modlock);PWC_DEBUG_OPEN ("<< video_open() returns 0.\n" );return 0 ; }
@@ -1685,7 +1685,7 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id pdev->angle_range.tilt_max =2500 ; } -init_MUTEX (&pdev->modlock); +mutex_init (&pdev->modlock);spin_lock_init (&pdev->ptrlock); pdev->udev = udev;
drivers/media/video/pwc/pwc.h +2 -2
@@ -31,7 +31,7 @@#include <linux/wait.h> #include <linux/smp_lock.h> #include <linux/version.h> -#include <asm/semaphore.h> +#include <linux/mutex.h> #include <asm/errno.h> #include <linux/videodev.h> #include <media/v4l2-common.h>
@@ -244,7 +244,7 @@ struct pwc_deviceint image_read_pos;/* In case we read data in pieces, keep track of were we are in the imagebuffer */ int image_used[MAX_IMAGES ];/* For MCAPTURE and SYNC */ -struct semaphore modlock;/* to prevent races in video_open(), etc */ +struct mutex modlock;/* to prevent races in video_open(), etc */ spinlock_t ptrlock;/* for manipulating the buffer pointers */ /*** motorized pan/tilt feature */
Signature · 10 lines
Matthias Kaehlcke
Linux Application Developer
Barcelona
"The only important thing Windows does better
than Debian is implementing the win32 platform"
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-PATCH 3/5 use mutex instead of semaphore in SMSC LPC47M192 driver
In reply to Matthias KaehlckeThe SMSC LPC47M192 driver uses a semaphore as mutex. Use the mutex API instead of the (binary) semaphore.
--
drivers/hwmon/smsc47m192.c +15 -14
@@ -31,6 +31,7 @@#include <linux/hwmon-vid.h> #include <linux/err.h> #include <linux/sysfs.h> +#include <linux/mutex.h> /* Addresses to scan */ static unsigned short normal_i2c[] = {0x2c ,0x2d ,I2C_CLIENT_END };
@@ -97,7 +98,7 @@ static inline int TEMP_FROM_REG(s8 val)struct smsc47m192_data {struct i2c_client client;struct class_device *class_dev; -struct semaphore update_lock; +struct mutex update_lock;char valid;/* !=0 if following fields are valid */ unsigned long last_updated;/* In jiffies */
@@ -164,11 +165,11 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,struct smsc47m192_data *data =i2c_get_clientdata (client);unsigned long val =simple_strtoul (buf,NULL ,10 ); -down (&data->update_lock); +mutex_lock (&data->update_lock); data->in_min[nr] =IN_TO_REG (val, nr);i2c_smbus_write_byte_data (client,SMSC47M192_REG_IN_MIN (nr), data->in_min[nr]); -up (&data->update_lock); +mutex_unlock (&data->update_lock);return count; }
@@ -181,11 +182,11 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,struct smsc47m192_data *data =i2c_get_clientdata (client);unsigned long val =simple_strtoul (buf,NULL ,10 ); -down (&data->update_lock); +mutex_lock (&data->update_lock); data->in_max[nr] =IN_TO_REG (val, nr);i2c_smbus_write_byte_data (client,SMSC47M192_REG_IN_MAX (nr), data->in_max[nr]); -up (&data->update_lock); +mutex_unlock (&data->update_lock);return count; }
@@ -243,11 +244,11 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,struct smsc47m192_data *data =i2c_get_clientdata (client);long val =simple_strtol (buf,NULL ,10 ); -down (&data->update_lock); +mutex_lock (&data->update_lock); data->temp_min[nr] =TEMP_TO_REG (val);i2c_smbus_write_byte_data (client,SMSC47M192_REG_TEMP_MIN [nr], data->temp_min[nr]); -up (&data->update_lock); +mutex_unlock (&data->update_lock);return count; }
@@ -260,11 +261,11 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,struct smsc47m192_data *data =i2c_get_clientdata (client);long val =simple_strtol (buf,NULL ,10 ); -down (&data->update_lock); +mutex_lock (&data->update_lock); data->temp_max[nr] =TEMP_TO_REG (val);i2c_smbus_write_byte_data (client,SMSC47M192_REG_TEMP_MAX [nr], data->temp_max[nr]); -up (&data->update_lock); +mutex_unlock (&data->update_lock);return count; }
@@ -287,7 +288,7 @@ static ssize_t set_temp_offset(struct device *dev, struct device_attributeu8 sfr =i2c_smbus_read_byte_data (client,SMSC47M192_REG_SFR );long val =simple_strtol (buf,NULL ,10 ); -down (&data->update_lock); +mutex_lock (&data->update_lock); data->temp_offset[nr] =TEMP_TO_REG (val);if (nr>1 ) i2c_smbus_write_byte_data(client,
@@ -303,7 +304,7 @@ static ssize_t set_temp_offset(struct device *dev, struct device_attribute }else if ((sfr &0x10 ) == (nr==0 ?0x10 :0 ))i2c_smbus_write_byte_data (client,SMSC47M192_REG_TEMP_OFFSET (nr),0 ); -up (&data->update_lock); +mutex_unlock (&data->update_lock);return count; }
@@ -531,7 +532,7 @@ static int smsc47m192_detect(struct i2c_adapter *adapter, int address,/* Fill in the remaining client fields and put into the global list */ strlcpy (client->name,"smsc47m192" ,I2C_NAME_SIZE ); data->vrm =vid_which_vrm (); -init_MUTEX (&data->update_lock); +mutex_init (&data->update_lock);/* Tell the I2C layer a new client has arrived */ if ((err =i2c_attach_client (client)))
@@ -594,7 +595,7 @@ static struct smsc47m192_data *smsc47m192_update_device(struct device *dev)struct smsc47m192_data *data =i2c_get_clientdata (client);int i, config; -down (&data->update_lock); +mutex_lock (&data->update_lock);if (time_after (jiffies, data->last_updated +HZ +HZ /2 ) || !data->valid) {
@@ -645,7 +646,7 @@ static struct smsc47m192_data *smsc47m192_update_device(struct device *dev) data->valid =1 ; } -up (&data->update_lock); +mutex_unlock (&data->update_lock);return data; }
Signature · 10 lines
Matthias Kaehlcke
Linux Application Developer
Barcelona
El camino se hace al andar
(Antonio Machado)
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-Re: [lm-sensors] [PATCH 3/5] use mutex instead of semaphore in SMSC LPC47M192 driver
Hi Matthias:
Quoted 4 lines · Matthias Kaehlcke
The SMSC LPC47M192 driver uses a semaphore as mutex. Use the mutex API instead of the (binary) semaphore.
Signed-off-by Matthias Kaehlcke <[email protected]>
Already in my testing tree[1] and therefore in latest -mm as well.
[1] http://lm-sensors.org/kernel?p=kernel/mhoffman/hwmon-2.6.git;a=shortlog;h=testing
Regards,
Signature · 8 lines
Mark M. Hoffman [email protected] _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
PATCH 4/5 use mutex instead of semaphore in Virtual Video driver
In reply to Matthias KaehlckeThe Virtual Video driver uses a semaphore as mutex. Use the mutex API instead of the (binary) semaphore.
--
drivers/media/video/vivi.c +8 -7
@@ -25,6 +25,7 @@#include <linux/pci.h> #include <linux/random.h> #include <linux/version.h> +#include <linux/mutex.h> #include <linux/videodev2.h> #include <linux/dma-mapping.h> #ifdef CONFIG_VIDEO_V4L1_COMPAT
@@ -168,7 +169,7 @@ static LIST_HEAD(vivi_devlist);struct vivi_dev {struct list_head vivi_devlist; -struct semaphore lock; +struct mutex lock;int users;
@@ -892,16 +893,16 @@ static struct videobuf_queue_ops vivi_video_qops = {static int res_get (struct vivi_dev *dev,struct vivi_fh *fh) {/* is it free? */ -down (&dev->lock); +mutex_lock (&dev->lock);if (dev->resources) {/* no, someone else uses it */ -up (&dev->lock); +mutex_unlock (&dev->lock);return 0 ; }/* it's free, grab it */ dev->resources =1 ;dprintk (1 ,"res: get\n" ); -up (&dev->lock); +mutex_unlock (&dev->lock);return 1 ; }
@@ -912,10 +913,10 @@ static int res_locked(struct vivi_dev *dev)static void res_free (struct vivi_dev *dev,struct vivi_fh *fh) { -down (&dev->lock); +mutex_lock (&dev->lock); dev->resources =0 ;dprintk (1 ,"res: put\n" ); -up (&dev->lock); +mutex_lock (&dev->lock); }/* ------------------------------------------------------------------
@@ -1422,7 +1423,7 @@ static int __init vivi_init(void)init_waitqueue_head (&dev->vidq.wq);/* initialize locks */ -init_MUTEX (&dev->lock); +mutex_init (&dev->lock); dev->vidq.timeout.function = vivi_vid_timeout; dev->vidq.timeout.data = (unsigned long )dev;
Signature · 12 lines
Matthias Kaehlcke
Linux Application Developer
Barcelona
In itself, homosexuality is as limiting as heterosexuality: the
ideal should be to be capable of loving a woman or a man; either,
a human being, without feeling fear, restraint, or obligation
(Simone de Beauvoir)
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-PATCH 5/5 use mutex instead of semaphore in VLSI 82C147 IrDA controller driver
In reply to Matthias KaehlckeThe VLSI 82C147 IrDA controller driver uses a semaphore as mutex. Use the mutex API instead of the (binary) semaphore.
--
drivers/net/irda/vlsi_ir.c +14 -13
@@ -44,6 +44,7 @@ MODULE_LICENSE("GPL");#include <linux/time.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> +#include <linux/mutex.h> #include <asm/uaccess.h> #include <asm/byteorder.h>
@@ -1660,8 +1661,8 @@ vlsi_irda_probe(struct pci_dev *pdev, const struct pci_device_id *id) idev = ndev->priv;spin_lock_init (&idev->lock); -init_MUTEX (&idev->sem); -down (&idev->sem); +mutex_init (&idev->mtx); +mutex_lock (&idev->mtx); idev->pdev = pdev;if (vlsi_irda_init (ndev) <0 )
@@ -1689,12 +1690,12 @@ vlsi_irda_probe(struct pci_dev *pdev, const struct pci_device_id *id)IRDA_MESSAGE ("%s: registered device %s\n" , drivername, ndev->name);pci_set_drvdata (pdev, ndev); -up (&idev->sem); +mutex_unlock (&idev->mtx);return 0 ; out_freedev: -up (&idev->sem); +mutex_unlock (&idev->mtx);free_netdev (ndev); out_disable:pci_disable_device (pdev);
@@ -1716,12 +1717,12 @@ static void __devexit vlsi_irda_remove(struct pci_dev *pdev)unregister_netdev (ndev); idev = ndev->priv; -down (&idev->sem); +mutex_lock (&idev->mtx);if (idev->proc_entry) {remove_proc_entry (ndev->name, vlsi_proc_root); idev->proc_entry =NULL ; } -up (&idev->sem); +mutex_unlock (&idev->mtx);free_netdev (ndev);
@@ -1751,7 +1752,7 @@ static int vlsi_irda_suspend(struct pci_dev *pdev, pm_message_t state)return 0 ; } idev = ndev->priv; -down (&idev->sem); +mutex_lock (&idev->mtx);if (pdev->current_state !=0 ) {/* already suspended */ if (state.event > pdev->current_state) {/* simply go deeper */ pci_set_power_state (pdev,pci_choose_state (pdev, state));
@@ -1759,7 +1760,7 @@ static int vlsi_irda_suspend(struct pci_dev *pdev, pm_message_t state) }else IRDA_ERROR ("%s - %s: invalid suspend request %u -> %u\n" , __FUNCTION__,pci_name (pdev), pdev->current_state, state.event); -up (&idev->sem); +mutex_unlock (&idev->mtx);return 0 ; }
@@ -1775,7 +1776,7 @@ static int vlsi_irda_suspend(struct pci_dev *pdev, pm_message_t state)pci_set_power_state (pdev,pci_choose_state (pdev, state)); pdev->current_state = state.event; idev->resume_ok =1 ; -up (&idev->sem); +mutex_unlock (&idev->mtx);return 0 ; }
@@ -1790,9 +1791,9 @@ static int vlsi_irda_resume(struct pci_dev *pdev)return 0 ; } idev = ndev->priv; -down (&idev->sem); +mutex_lock (&idev->mtx);if (pdev->current_state ==0 ) { -up (&idev->sem); +mutex_unlock (&idev->mtx);IRDA_WARNING ("%s - %s: already resumed\n" , __FUNCTION__,pci_name (pdev));return 0 ;
@@ -1814,7 +1815,7 @@ static int vlsi_irda_resume(struct pci_dev *pdev)* device and independently resume_ok should catch any garbage config. */ IRDA_WARNING ("%s - hm, nothing to resume?\n" , __FUNCTION__); -up (&idev->sem); +mutex_unlock (&idev->mtx);return 0 ; }
@@ -1824,7 +1825,7 @@ static int vlsi_irda_resume(struct pci_dev *pdev)netif_device_attach (ndev); } idev->resume_ok =0 ; -up (&idev->sem); +mutex_unlock (&idev->mtx);return 0 ; }
drivers/net/irda/vlsi_ir.h +1 -1
@@ -728,7 +728,7 @@ typedef struct vlsi_irda_dev {struct timeval last_rx;spinlock_t lock; -struct semaphore sem; +struct mutex mtx;u8 resume_ok;struct proc_dir_entry *proc_entry;
Signature · 11 lines
Matthias Kaehlcke
Linux Application Developer
Barcelona
You can chain me, you can torture me, you can even
destroy this body, but you will never imprison my mind
(Mahatma Gandhi)
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-