use mutex instead of semaphore in several drivers
Subsystems (2)
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/code:
I2O
IDE
CAPI 2.0
ST M25Pxx MTD
DataFlash MTD
Signature · 10 lines
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 `-PATCH 1/5 Use mutexes instead of semaphores in I2O driver
The I2O driver uses two semaphores as mutexes. Use the mutex API instead of the (binary) semaphores.
--
drivers/message/i2o/device.c +8 -8
@@ -62,7 +62,7 @@ int i2o_device_claim(struct i2o_device *dev) {int rc =0 ; -down (&dev->lock); +mutex_lock (&dev->lock); rc =i2o_device_issue_claim (dev,I2O_CMD_UTIL_CLAIM ,I2O_CLAIM_PRIMARY );if (!rc)
@@ -72,7 +72,7 @@ int i2o_device_claim(struct i2o_device *dev)pr_debug ("i2o: claim of device %d failed %d\n" , dev->lct_data.tid, rc); -up (&dev->lock); +mutex_unlock (&dev->lock);return rc; }
@@ -96,7 +96,7 @@ int i2o_device_claim_release(struct i2o_device *dev)int tries;int rc =0 ; -down (&dev->lock); +mutex_lock (&dev->lock);/* * If the controller takes a nonblocking approach to
@@ -118,7 +118,7 @@ int i2o_device_claim_release(struct i2o_device *dev)pr_debug ("i2o: claim release of device %d failed %d\n" , dev->lct_data.tid, rc); -up (&dev->lock); +mutex_unlock (&dev->lock);return rc; }
@@ -198,7 +198,7 @@ static struct i2o_device *i2o_device_alloc(void)return ERR_PTR (-ENOMEM );INIT_LIST_HEAD (&dev->list); -init_MUTEX (&dev->lock); +mutex_init (&dev->lock); dev->device.bus = &i2o_bus_type; dev->device.release = &i2o_device_release;
@@ -326,7 +326,7 @@ int i2o_device_parse_lct(struct i2o_controller *c)u16 table_size;u32 buf; -down (&c->lct_lock); +mutex_lock (&c->lct_lock);kfree (c->lct);
@@ -335,7 +335,7 @@ int i2o_device_parse_lct(struct i2o_controller *c) lct = c->lct =kmalloc (table_size *4 ,GFP_KERNEL );if (!lct) { -up (&c->lct_lock); +mutex_unlock (&c->lct_lock);return -ENOMEM ; }
@@ -408,7 +408,7 @@ int i2o_device_parse_lct(struct i2o_controller *c)i2o_device_remove (dev); } -up (&c->lct_lock); +mutex_unlock (&c->lct_lock);return 0 ; }
drivers/message/i2o/exec-osm.c +2 -2
@@ -537,7 +537,7 @@ static int i2o_exec_lct_notify(struct i2o_controller *c, u32 change_ind)struct device *dev;struct i2o_message *msg; -down (&c->lct_lock); +mutex_lock (&c->lct_lock); dev = &c->pdev->dev;
@@ -561,7 +561,7 @@ static int i2o_exec_lct_notify(struct i2o_controller *c, u32 change_ind)i2o_msg_post (c, msg); -up (&c->lct_lock); +mutex_unlock (&c->lct_lock);return 0 ; };
drivers/message/i2o/iop.c +1 -1
@@ -1067,7 +1067,7 @@ struct i2o_controller *i2o_iop_alloc(void)INIT_LIST_HEAD (&c->devices);spin_lock_init (&c->lock); -init_MUTEX (&c->lct_lock); +mutex_init (&c->lct_lock);device_initialize (&c->device);
include/linux/i2o.h +3 -2
@@ -31,6 +31,7 @@#include <linux/slab.h> #include <linux/workqueue.h> /* work_struct */ #include <linux/mempool.h> +#include <linux/mutex.h> #include <asm/io.h> #include <asm/semaphore.h> /* Needed for MUTEX init macros */
@@ -425,7 +426,7 @@ struct i2o_device {struct device device; -struct semaphore lock;/* device lock */ +struct mutex lock;/* device lock */ };/*
@@ -544,7 +545,7 @@ struct i2o_controller {struct i2o_dma hrt;/* HW Resource Table */ i2o_lct *lct;/* Logical Config Table */ struct i2o_dma dlct;/* Temp LCT */ -struct semaphore lct_lock;/* Lock for LCT updates */ +struct mutex lct_lock;/* Lock for LCT updates */ struct i2o_dma status_block;/* IOP status block */ struct i2o_io base;/* controller messaging unit */
Signature · 10 lines
Matthias Kaehlcke
Linux Application Developer
Barcelona
Dreams and reality are opposites. Action synthesizes them
(Assata Shakur)
.''`.
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 IDE driver
In reply to Matthias KaehlckeThe IDE driver uses a semaphore as mutex. Use the mutex API instead of the (binary) semaphore.
--
drivers/ide/ide-disk.c +4 -4
@@ -1178,11 +1178,11 @@ static int idedisk_ioctl(struct inode *inode, struct file *file,return generic_ide_ioctl (drive, file, bdev, cmd, arg); read_val: -down (&ide_setting_sem); +mutex_lock (&ide_setting_mtx);spin_lock_irqsave (&ide_lock, flags); err = *val;spin_unlock_irqrestore (&ide_lock, flags); -up (&ide_setting_sem); +mutex_unlock (&ide_setting_mtx);return err >=0 ?put_user (err, (long __user *)arg) : err; set_val:
@@ -1192,9 +1192,9 @@ set_val:if (!capable (CAP_SYS_ADMIN )) err = -EACCES ;else { -down (&ide_setting_sem); +mutex_lock (&ide_setting_mtx); err =setfunc (drive, arg); -up (&ide_setting_sem); +mutex_unlock (&ide_setting_mtx); } }return err;
drivers/ide/ide-proc.c +17 -17
@@ -154,7 +154,7 @@ static int __ide_add_setting(ide_drive_t *drive, const char *name, int rw, int d {ide_settings_t **p = (ide_settings_t **) &drive->settings, *setting =NULL ; -down (&ide_setting_sem); +mutex_lock (&ide_setting_mtx);while ((*p) &&strcmp ((*p)->name, name) <0 ) p = &((*p)->next);if ((setting =kzalloc (sizeof (*setting),GFP_KERNEL )) ==NULL )
@@ -175,10 +175,10 @@ static int __ide_add_setting(ide_drive_t *drive, const char *name, int rw, int dif (auto_remove) setting->auto_remove =1 ; *p = setting; -up (&ide_setting_sem); +mutex_unlock (&ide_setting_mtx);return 0 ; abort: -up (&ide_setting_sem); +mutex_unlock (&ide_setting_mtx);kfree (setting);return -1 ; }
@@ -222,7 +222,7 @@ static void __ide_remove_setting (ide_drive_t *drive, char *name)* * Automatically remove all the driver specific settings for this * drive. This function may not be called from IRQ context. The -* caller must hold ide_setting_sem. +* caller must hold ide_setting_mtx. */ static void auto_remove_settings (ide_drive_t *drive)
@@ -267,7 +267,7 @@ static ide_settings_t *ide_find_setting_by_name(ide_drive_t *drive, char *name)* @setting: drive setting * * Read a drive setting and return the value. The caller -* must hold the ide_setting_sem when making this call. +* must hold the ide_setting_mtx when making this call. * * BUGS: the data return and error are the same return value * so an error -EINVAL and true return of the same value cannot
@@ -304,7 +304,7 @@ static int ide_read_setting(ide_drive_t *drive, ide_settings_t *setting)* @val: value * * Write a drive setting if it is possible. The caller -* must hold the ide_setting_sem when making this call. +* must hold the ide_setting_mtx when making this call. * * BUGS: the data return and error are the same return value * so an error -EINVAL and true return of the same value cannot
@@ -365,7 +365,7 @@ static int set_xfer_rate (ide_drive_t *drive, int arg)* @drive: drive being configured * * Add the generic parts of the system settings to the /proc files. -* The caller must not be holding the ide_setting_sem. +* The caller must not be holding the ide_setting_mtx. */ void ide_add_generic_settings (ide_drive_t *drive)
@@ -406,7 +406,7 @@ static int proc_ide_read_settingsproc_ide_settings_warn (); -down (&ide_setting_sem); +mutex_lock (&ide_setting_mtx); out +=sprintf (out,"name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n" ); out +=sprintf (out,"----\t\t\t-----\t\t---\t\t---\t\t----\n" );while (setting) {
@@ -426,7 +426,7 @@ static int proc_ide_read_settings setting = setting->next; } len = out - page; -up (&ide_setting_sem); +mutex_unlock (&ide_setting_mtx);PROC_IDE_READ_RETURN (page,start,off,count,eof,len); }
@@ -506,16 +506,16 @@ static int proc_ide_write_settings(struct file *file, const char __user *buffer, ++p; } -down (&ide_setting_sem); +mutex_lock (&ide_setting_mtx); setting =ide_find_setting_by_name (drive, name);if (!setting) { -up (&ide_setting_sem); +mutex_unlock (&ide_setting_mtx); goto parse_error; }if (for_real)ide_write_setting (drive, setting, val * setting->div_factor / setting->mul_factor); -up (&ide_setting_sem); +mutex_unlock (&ide_setting_mtx); } }while (!for_real++);free_page ((unsigned long )buf);
@@ -703,7 +703,7 @@ EXPORT_SYMBOL(ide_proc_register_driver);* Clean up the driver specific /proc files and IDE settings * for a given drive. * -* Takes ide_setting_sem and ide_lock. +* Takes ide_setting_mtx and ide_lock. * Caller must hold none of the locks. */
@@ -713,10 +713,10 @@ void ide_proc_unregister_driver(ide_drive_t *drive, ide_driver_t *driver)ide_remove_proc_entries (drive->proc, driver->proc); -down (&ide_setting_sem); +mutex_lock (&ide_setting_mtx);spin_lock_irqsave (&ide_lock, flags);/* -* ide_setting_sem protects the settings list +* ide_setting_mtx protects the settings list * ide_lock protects the use of settings * * so we need to hold both, ide_settings_sem because we want to
@@ -724,11 +724,11 @@ void ide_proc_unregister_driver(ide_drive_t *drive, ide_driver_t *driver)* a setting out that is being used. * * OTOH both ide_{read,write}_setting are only ever used under -* ide_setting_sem. +* ide_setting_mtx. */ auto_remove_settings (drive);spin_unlock_irqrestore (&ide_lock, flags); -up (&ide_setting_sem); +mutex_unlock (&ide_setting_mtx); }EXPORT_SYMBOL (ide_proc_unregister_driver);
drivers/ide/ide.c +6 -6
@@ -817,9 +817,9 @@ EXPORT_SYMBOL(ide_register_hw);* Locks for IDE setting functionality */ -DECLARE_MUTEX (ide_setting_sem); +DEFINE_MUTEX (ide_setting_mtx); -EXPORT_SYMBOL_GPL (ide_setting_sem); +EXPORT_SYMBOL_GPL (ide_setting_mtx);/** * ide_spin_wait_hwgroup - wait for group
@@ -1181,11 +1181,11 @@ int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device } read_val: -down (&ide_setting_sem); +mutex_lock (&ide_setting_mtx);spin_lock_irqsave (&ide_lock, flags); err = *val;spin_unlock_irqrestore (&ide_lock, flags); -up (&ide_setting_sem); +mutex_unlock (&ide_setting_mtx);return err >=0 ?put_user (err, (long __user *)arg) : err; set_val:
@@ -1195,9 +1195,9 @@ set_val:if (!capable (CAP_SYS_ADMIN )) err = -EACCES ;else { -down (&ide_setting_sem); +mutex_lock (&ide_setting_mtx); err =setfunc (drive, arg); -up (&ide_setting_sem); +mutex_unlock (&ide_setting_mtx); } }return err;
include/linux/ide.h +2 -1
@@ -25,6 +25,7 @@#include <asm/system.h> #include <asm/io.h> #include <asm/semaphore.h> +#include <asm/mutex.h> /****************************************************************************** * IDE driver configuration options (play with these as desired):
@@ -863,7 +864,7 @@ typedef struct hwgroup_s {typedef struct ide_driver_s ide_driver_t ; -extern struct semaphore ide_setting_sem; +extern struct mutex ide_setting_mtx;int set_io_32bit (ide_drive_t *,int );int set_pio_mode (ide_drive_t *,int );
Signature · 12 lines
Matthias Kaehlcke
Linux Application Developer
Barcelona
Usually when people are sad, they don't do anything. They just cry over
their condition. But when they get angry, they bring about a change
(Malcolm X)
.''`.
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 CAPI 2.0 driver
In reply to Matthias KaehlckeThe CAPI 2.0 driver uses a semaphore as mutex. Use the mutex API instead of the (binary) semaphore.
--
drivers/isdn/capi/kcapi.c +3 -3
@@ -258,7 +258,7 @@ static void recv_handler(struct work_struct *work)if ((!ap) || (ap->release_in_progress))return ; -down (&ap->recv_sem); +mutex_lock (&ap->recv_mtx);while ((skb =skb_dequeue (&ap->recv_queue))) {if (CAPIMSG_CMD (skb->data) ==CAPI_DATA_B3_IND ) ap->nrecvdatapkt++;
@@ -267,7 +267,7 @@ static void recv_handler(struct work_struct *work) ap->recv_message (ap, skb); } -up (&ap->recv_sem); +mutex_unlock (&ap->recv_mtx); }void capi_ctr_handle_message (struct capi_ctr * card,u16 appl,struct sk_buff *skb)
@@ -547,7 +547,7 @@ u16 capi20_register(struct capi20_appl *ap) ap->nsentctlpkt =0 ; ap->nsentdatapkt =0 ; ap->callback =NULL ; -init_MUTEX (&ap->recv_sem); +mutex_init (&ap->recv_mtx);skb_queue_head_init (&ap->recv_queue);INIT_WORK (&ap->recv_work, recv_handler); ap->release_in_progress =0 ;
include/linux/kernelcapi.h +1 -1
@@ -64,7 +64,7 @@ struct capi20_appl {unsigned long nrecvdatapkt;unsigned long nsentctlpkt;unsigned long nsentdatapkt; -struct semaphore recv_sem; +struct mutex recv_mtx;struct sk_buff_head recv_queue;struct work_struct recv_work;int release_in_progress;
Signature · 10 lines
Matthias Kaehlcke
Linux Application Developer
Barcelona
Dreams and reality are opposites. Action synthesizes them
(Assata Shakur)
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-PATCH 4/5 Use mutex instead of semaphore in the MTD ST M25Pxx driver
In reply to Matthias KaehlckeThe MTD ST M25Pxx driver uses a semaphore as mutex. Use the mutex API instead of the (binary) semaphore.
--
drivers/mtd/devices/m25p80.c +10 -11
@@ -24,8 +24,7 @@#include <linux/mtd/partitions.h> #include <linux/spi/spi.h> #include <linux/spi/flash.h> - -#include <asm/semaphore.h> +#include <linux/mutex.h> /* NOTE: AT 25F and SST 25LF series are very similar,
@@ -201,13 +200,13 @@ static int m25p80_erase(struct mtd_info *mtd, struct erase_info *instr) addr = instr->addr; len = instr->len; -down (&flash->lock); +mutex_lock (&flash->lock);/* now erase those sectors */ while (len) {if (erase_sector (flash, addr)) { instr->state =MTD_ERASE_FAILED ; -up (&flash->lock); +mutex_unlock (&flash->lock);return -EIO ; }
@@ -215,7 +214,7 @@ static int m25p80_erase(struct mtd_info *mtd, struct erase_info *instr) len -= mtd->erasesize; } -up (&flash->lock); +mutex_unlock (&flash->lock); instr->state =MTD_ERASE_DONE ;mtd_erase_callback (instr);
@@ -260,12 +259,12 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len,if (retlen) *retlen =0 ; -down (&flash->lock); +mutex_lock (&flash->lock);/* Wait till previous write/erase is done. */ if (wait_till_ready (flash)) {/* REVISIT status return?? */ -up (&flash->lock); +mutex_unlock (&flash->lock);return 1 ; }
@@ -281,7 +280,7 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len, *retlen = m.actual_length -sizeof (flash->command); -up (&flash->lock); +mutex_unlock (&flash->lock);return 0 ; }
@@ -323,7 +322,7 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len, t[1 ].tx_buf = buf;spi_message_add_tail (&t[1 ], &m); -down (&flash->lock); +mutex_lock (&flash->lock);/* Wait until finished previous write command. */ if (wait_till_ready (flash))
@@ -384,7 +383,7 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len, } } -up (&flash->lock); +mutex_unlock (&flash->lock);return 0 ; }
@@ -456,7 +455,7 @@ static int __devinit m25p_probe(struct spi_device *spi)return -ENOMEM ; flash->spi = spi; -init_MUTEX (&flash->lock); +mutex_init (&flash->lock);dev_set_drvdata (&spi->dev, flash);if (data->name)
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 `-PATCH 5/5 Use mutex instead of semaphore in the MTD DataFlash driver
In reply to Matthias KaehlckeThe MTD DataFlash driver uses a semaphore as mutex. Use the mutex API instead
of the (binary) semaphore.
--
drivers/mtd/devices/mtd_dataflash.c +9 -8
@@ -14,6 +14,7 @@#include <linux/slab.h> #include <linux/delay.h> #include <linux/device.h> +#include <linux/mutex.h> #include <linux/spi/spi.h> #include <linux/spi/flash.h>
@@ -89,7 +90,7 @@ struct dataflash {unsigned short page_offset;/* offset in flash address */ unsigned int page_size;/* of bytes per page */ -struct semaphore lock; +struct mutex lock;struct spi_device *spi;struct mtd_info mtd;
@@ -167,7 +168,7 @@ static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr) x.len =4 ;spi_message_add_tail (&x, &msg); -down (&priv->lock); +mutex_lock (&priv->lock);while (instr->len >0 ) {unsigned int pageaddr;int status;
@@ -210,7 +211,7 @@ static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr) instr->len -= priv->page_size; } } -up (&priv->lock); +mutex_unlock (&priv->lock);/* Inform MTD subsystem that erase is complete */ instr->state =MTD_ERASE_DONE ;
@@ -266,7 +267,7 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len, x[1 ].len = len;spi_message_add_tail (&x[1 ], &msg); -down (&priv->lock); +mutex_lock (&priv->lock);/* Continuous read, max clock = f(car) which may be less than * the peak rate available. Some chips support commands with
@@ -279,7 +280,7 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len,/* plus 4 "don't care" bytes */ status =spi_sync (priv->spi, &msg); -up (&priv->lock); +mutex_unlock (&priv->lock);if (status >=0 ) { *retlen = msg.actual_length -8 ;
@@ -336,7 +337,7 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,else writelen = len; -down (&priv->lock); +mutex_lock (&priv->lock);while (remaining >0 ) {DEBUG (MTD_DEBUG_LEVEL3 ,"write @ %i:%i len=%i\n" , pageaddr, offset, writelen);
@@ -441,7 +442,7 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,else writelen = remaining; } -up (&priv->lock); +mutex_unlock (&priv->lock);return status; }
@@ -463,7 +464,7 @@ add_dataflash(struct spi_device *spi, char *name,if (!priv)return -ENOMEM ; -init_MUTEX (&priv->lock); +mutex_init (&priv->lock); priv->spi = spi; priv->page_size = pagesize; priv->page_offset = pageoffset;
Signature · 10 lines
Matthias Kaehlcke
Linux Application Developer
Barcelona
Nothing is more despicable than respect based on fear
(Albert Camus)
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-Bartlomiej Zolnierkiewicz
AppliedRe: [PATCH 2/5] Use mutex instead of semaphore in IDE driver
In reply to Matthias KaehlckeQuoted 4 lines · Matthias Kaehlcke
The IDE driver uses a semaphore as mutex. Use the mutex API instead of the (binary) semaphore.
Signed-off-by Matthias Kaehlcke <[email protected]>
applied
Since I already had a patch from you with identical patch summary/description (but for ide_cfg_sem semaphore) in my tree, I almost overlooked this one. :)
Please choose more descriptive patch summary/description next time.
Thanks,
Bart