[PATCH] sem2mutex: drivers/mtd/

Semaphore to mutex conversion.

The conversion was generated via scripts, and the result was validated
automatically via a script as well.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Acked-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
Ingo Molnar 2006-03-31 02:29:41 -08:00 committed by Linus Torvalds
parent 040d79f906
commit 48b192686d
8 changed files with 71 additions and 68 deletions

View File

@ -29,7 +29,7 @@
#include <linux/list.h>
#include <linux/init.h>
#include <linux/mtd/mtd.h>
#include <linux/mutex.h>
#define err(format, arg...) printk(KERN_ERR "blkmtd: " format "\n" , ## arg)
#define info(format, arg...) printk(KERN_INFO "blkmtd: " format "\n" , ## arg)
@ -46,7 +46,7 @@ struct blkmtd_dev {
struct list_head list;
struct block_device *blkdev;
struct mtd_info mtd_info;
struct semaphore wrbuf_mutex;
struct mutex wrbuf_mutex;
};
@ -268,7 +268,7 @@ static int write_pages(struct blkmtd_dev *dev, const u_char *buf, loff_t to,
if(end_len)
pagecnt++;
down(&dev->wrbuf_mutex);
mutex_lock(&dev->wrbuf_mutex);
DEBUG(3, "blkmtd: write: start_len = %zd len = %zd end_len = %zd pagecnt = %d\n",
start_len, len, end_len, pagecnt);
@ -376,7 +376,7 @@ static int write_pages(struct blkmtd_dev *dev, const u_char *buf, loff_t to,
blkmtd_write_out(bio);
DEBUG(2, "blkmtd: write: end, retlen = %zd, err = %d\n", *retlen, err);
up(&dev->wrbuf_mutex);
mutex_unlock(&dev->wrbuf_mutex);
if(retlen)
*retlen = thislen;
@ -659,7 +659,7 @@ static struct blkmtd_dev *add_device(char *devname, int readonly, int erase_size
memset(dev, 0, sizeof(struct blkmtd_dev));
dev->blkdev = bdev;
if(!readonly) {
init_MUTEX(&dev->wrbuf_mutex);
mutex_init(&dev->wrbuf_mutex);
}
dev->mtd_info.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;

View File

@ -18,6 +18,7 @@
#include <linux/init.h>
#include <linux/mtd/mtd.h>
#include <linux/buffer_head.h>
#include <linux/mutex.h>
#define VERSION "$Revision: 1.30 $"
@ -31,7 +32,7 @@ struct block2mtd_dev {
struct list_head list;
struct block_device *blkdev;
struct mtd_info mtd;
struct semaphore write_mutex;
struct mutex write_mutex;
};
@ -134,9 +135,9 @@ static int block2mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
int err;
instr->state = MTD_ERASING;
down(&dev->write_mutex);
mutex_lock(&dev->write_mutex);
err = _block2mtd_erase(dev, from, len);
up(&dev->write_mutex);
mutex_unlock(&dev->write_mutex);
if (err) {
ERROR("erase failed err = %d", err);
instr->state = MTD_ERASE_FAILED;
@ -249,9 +250,9 @@ static int block2mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
if (to + len > mtd->size)
len = mtd->size - to;
down(&dev->write_mutex);
mutex_lock(&dev->write_mutex);
err = _block2mtd_write(dev, buf, to, len, retlen);
up(&dev->write_mutex);
mutex_unlock(&dev->write_mutex);
if (err > 0)
err = 0;
return err;
@ -310,7 +311,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
goto devinit_err;
}
init_MUTEX(&dev->write_mutex);
mutex_init(&dev->write_mutex);
/* Setup the MTD structure */
/* make the name contain the block device in */

View File

@ -606,7 +606,7 @@ static void DoC2k_init(struct mtd_info *mtd)
this->curfloor = -1;
this->curchip = -1;
init_MUTEX(&this->lock);
mutex_init(&this->lock);
/* Ident all the chips present. */
DoC_ScanChips(this, maxchips);
@ -646,7 +646,7 @@ static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
if (from >= this->totlen)
return -EINVAL;
down(&this->lock);
mutex_lock(&this->lock);
*retlen = 0;
while (left) {
@ -775,7 +775,7 @@ static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
buf += len;
}
up(&this->lock);
mutex_unlock(&this->lock);
return ret;
}
@ -804,7 +804,7 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
if (to >= this->totlen)
return -EINVAL;
down(&this->lock);
mutex_lock(&this->lock);
*retlen = 0;
while (left) {
@ -874,7 +874,7 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
printk(KERN_ERR "Error programming flash\n");
/* Error in programming */
*retlen = 0;
up(&this->lock);
mutex_unlock(&this->lock);
return -EIO;
}
@ -936,7 +936,7 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
printk(KERN_ERR "Error programming flash\n");
/* Error in programming */
*retlen = 0;
up(&this->lock);
mutex_unlock(&this->lock);
return -EIO;
}
@ -957,7 +957,7 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
ret = doc_write_oob_nolock(mtd, to, 8, &dummy, x);
if (ret) {
up(&this->lock);
mutex_unlock(&this->lock);
return ret;
}
}
@ -967,7 +967,7 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
buf += len;
}
up(&this->lock);
mutex_unlock(&this->lock);
return 0;
}
@ -1038,7 +1038,7 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
int len256 = 0, ret;
struct Nand *mychip;
down(&this->lock);
mutex_lock(&this->lock);
mychip = &this->chips[ofs >> this->chipshift];
@ -1084,7 +1084,7 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
ret = DoC_WaitReady(this);
up(&this->lock);
mutex_unlock(&this->lock);
return ret;
}
@ -1198,10 +1198,10 @@ static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
struct DiskOnChip *this = mtd->priv;
int ret;
down(&this->lock);
mutex_lock(&this->lock);
ret = doc_write_oob_nolock(mtd, ofs, len, retlen, buf);
up(&this->lock);
mutex_unlock(&this->lock);
return ret;
}
@ -1215,10 +1215,10 @@ static int doc_erase(struct mtd_info *mtd, struct erase_info *instr)
struct Nand *mychip;
int status;
down(&this->lock);
mutex_lock(&this->lock);
if (ofs & (mtd->erasesize-1) || len & (mtd->erasesize-1)) {
up(&this->lock);
mutex_unlock(&this->lock);
return -EINVAL;
}
@ -1266,7 +1266,7 @@ static int doc_erase(struct mtd_info *mtd, struct erase_info *instr)
callback:
mtd_erase_callback(instr);
up(&this->lock);
mutex_unlock(&this->lock);
return 0;
}

View File

@ -19,12 +19,12 @@
#include <linux/spinlock.h>
#include <linux/hdreg.h>
#include <linux/init.h>
#include <asm/semaphore.h>
#include <linux/mutex.h>
#include <asm/uaccess.h>
static LIST_HEAD(blktrans_majors);
extern struct semaphore mtd_table_mutex;
extern struct mutex mtd_table_mutex;
extern struct mtd_info *mtd_table[];
struct mtd_blkcore_priv {
@ -122,9 +122,9 @@ static int mtd_blktrans_thread(void *arg)
spin_unlock_irq(rq->queue_lock);
down(&dev->sem);
mutex_lock(&dev->lock);
res = do_blktrans_request(tr, dev, req);
up(&dev->sem);
mutex_unlock(&dev->lock);
spin_lock_irq(rq->queue_lock);
@ -235,8 +235,8 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
int last_devnum = -1;
struct gendisk *gd;
if (!down_trylock(&mtd_table_mutex)) {
up(&mtd_table_mutex);
if (!!mutex_trylock(&mtd_table_mutex)) {
mutex_unlock(&mtd_table_mutex);
BUG();
}
@ -267,7 +267,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
return -EBUSY;
}
init_MUTEX(&new->sem);
mutex_init(&new->lock);
list_add_tail(&new->list, &tr->devs);
added:
if (!tr->writesect)
@ -313,8 +313,8 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)
{
if (!down_trylock(&mtd_table_mutex)) {
up(&mtd_table_mutex);
if (!!mutex_trylock(&mtd_table_mutex)) {
mutex_unlock(&mtd_table_mutex);
BUG();
}
@ -378,14 +378,14 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
memset(tr->blkcore_priv, 0, sizeof(*tr->blkcore_priv));
down(&mtd_table_mutex);
mutex_lock(&mtd_table_mutex);
ret = register_blkdev(tr->major, tr->name);
if (ret) {
printk(KERN_WARNING "Unable to register %s block device on major %d: %d\n",
tr->name, tr->major, ret);
kfree(tr->blkcore_priv);
up(&mtd_table_mutex);
mutex_unlock(&mtd_table_mutex);
return ret;
}
spin_lock_init(&tr->blkcore_priv->queue_lock);
@ -396,7 +396,7 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
if (!tr->blkcore_priv->rq) {
unregister_blkdev(tr->major, tr->name);
kfree(tr->blkcore_priv);
up(&mtd_table_mutex);
mutex_unlock(&mtd_table_mutex);
return -ENOMEM;
}
@ -407,7 +407,7 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
blk_cleanup_queue(tr->blkcore_priv->rq);
unregister_blkdev(tr->major, tr->name);
kfree(tr->blkcore_priv);
up(&mtd_table_mutex);
mutex_unlock(&mtd_table_mutex);
return ret;
}
@ -419,7 +419,7 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
tr->add_mtd(tr, mtd_table[i]);
}
up(&mtd_table_mutex);
mutex_unlock(&mtd_table_mutex);
return 0;
}
@ -428,7 +428,7 @@ int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr)
{
struct list_head *this, *next;
down(&mtd_table_mutex);
mutex_lock(&mtd_table_mutex);
/* Clean up the kernel thread */
tr->blkcore_priv->exiting = 1;
@ -446,7 +446,7 @@ int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr)
blk_cleanup_queue(tr->blkcore_priv->rq);
unregister_blkdev(tr->major, tr->name);
up(&mtd_table_mutex);
mutex_unlock(&mtd_table_mutex);
kfree(tr->blkcore_priv);

View File

@ -19,11 +19,13 @@
#include <linux/mtd/mtd.h>
#include <linux/mtd/blktrans.h>
#include <linux/mutex.h>
static struct mtdblk_dev {
struct mtd_info *mtd;
int count;
struct semaphore cache_sem;
struct mutex cache_mutex;
unsigned char *cache_data;
unsigned long cache_offset;
unsigned int cache_size;
@ -284,7 +286,7 @@ static int mtdblock_open(struct mtd_blktrans_dev *mbd)
mtdblk->count = 1;
mtdblk->mtd = mtd;
init_MUTEX (&mtdblk->cache_sem);
mutex_init(&mtdblk->cache_mutex);
mtdblk->cache_state = STATE_EMPTY;
if ((mtdblk->mtd->flags & MTD_CAP_RAM) != MTD_CAP_RAM &&
mtdblk->mtd->erasesize) {
@ -306,9 +308,9 @@ static int mtdblock_release(struct mtd_blktrans_dev *mbd)
DEBUG(MTD_DEBUG_LEVEL1, "mtdblock_release\n");
down(&mtdblk->cache_sem);
mutex_lock(&mtdblk->cache_mutex);
write_cached_data(mtdblk);
up(&mtdblk->cache_sem);
mutex_unlock(&mtdblk->cache_mutex);
if (!--mtdblk->count) {
/* It was the last usage. Free the device */
@ -327,9 +329,9 @@ static int mtdblock_flush(struct mtd_blktrans_dev *dev)
{
struct mtdblk_dev *mtdblk = mtdblks[dev->devnum];
down(&mtdblk->cache_sem);
mutex_lock(&mtdblk->cache_mutex);
write_cached_data(mtdblk);
up(&mtdblk->cache_sem);
mutex_unlock(&mtdblk->cache_mutex);
if (mtdblk->mtd->sync)
mtdblk->mtd->sync(mtdblk->mtd);

View File

@ -27,7 +27,7 @@
/* These are exported solely for the purpose of mtd_blkdevs.c. You
should not use them for _anything_ else */
DECLARE_MUTEX(mtd_table_mutex);
DEFINE_MUTEX(mtd_table_mutex);
struct mtd_info *mtd_table[MAX_MTD_DEVICES];
EXPORT_SYMBOL_GPL(mtd_table_mutex);
@ -49,7 +49,7 @@ int add_mtd_device(struct mtd_info *mtd)
{
int i;
down(&mtd_table_mutex);
mutex_lock(&mtd_table_mutex);
for (i=0; i < MAX_MTD_DEVICES; i++)
if (!mtd_table[i]) {
@ -67,7 +67,7 @@ int add_mtd_device(struct mtd_info *mtd)
not->add(mtd);
}
up(&mtd_table_mutex);
mutex_unlock(&mtd_table_mutex);
/* We _know_ we aren't being removed, because
our caller is still holding us here. So none
of this try_ nonsense, and no bitching about it
@ -76,7 +76,7 @@ int add_mtd_device(struct mtd_info *mtd)
return 0;
}
up(&mtd_table_mutex);
mutex_unlock(&mtd_table_mutex);
return 1;
}
@ -94,7 +94,7 @@ int del_mtd_device (struct mtd_info *mtd)
{
int ret;
down(&mtd_table_mutex);
mutex_lock(&mtd_table_mutex);
if (mtd_table[mtd->index] != mtd) {
ret = -ENODEV;
@ -118,7 +118,7 @@ int del_mtd_device (struct mtd_info *mtd)
ret = 0;
}
up(&mtd_table_mutex);
mutex_unlock(&mtd_table_mutex);
return ret;
}
@ -135,7 +135,7 @@ void register_mtd_user (struct mtd_notifier *new)
{
int i;
down(&mtd_table_mutex);
mutex_lock(&mtd_table_mutex);
list_add(&new->list, &mtd_notifiers);
@ -145,7 +145,7 @@ void register_mtd_user (struct mtd_notifier *new)
if (mtd_table[i])
new->add(mtd_table[i]);
up(&mtd_table_mutex);
mutex_unlock(&mtd_table_mutex);
}
/**
@ -162,7 +162,7 @@ int unregister_mtd_user (struct mtd_notifier *old)
{
int i;
down(&mtd_table_mutex);
mutex_lock(&mtd_table_mutex);
module_put(THIS_MODULE);
@ -171,7 +171,7 @@ int unregister_mtd_user (struct mtd_notifier *old)
old->remove(mtd_table[i]);
list_del(&old->list);
up(&mtd_table_mutex);
mutex_unlock(&mtd_table_mutex);
return 0;
}
@ -193,7 +193,7 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
struct mtd_info *ret = NULL;
int i;
down(&mtd_table_mutex);
mutex_lock(&mtd_table_mutex);
if (num == -1) {
for (i=0; i< MAX_MTD_DEVICES; i++)
@ -211,7 +211,7 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
if (ret)
ret->usecount++;
up(&mtd_table_mutex);
mutex_unlock(&mtd_table_mutex);
return ret;
}
@ -219,9 +219,9 @@ void put_mtd_device(struct mtd_info *mtd)
{
int c;
down(&mtd_table_mutex);
mutex_lock(&mtd_table_mutex);
c = --mtd->usecount;
up(&mtd_table_mutex);
mutex_unlock(&mtd_table_mutex);
BUG_ON(c < 0);
module_put(mtd->owner);
@ -319,7 +319,7 @@ static int mtd_read_proc (char *page, char **start, off_t off, int count,
int len, l, i;
off_t begin = 0;
down(&mtd_table_mutex);
mutex_lock(&mtd_table_mutex);
len = sprintf(page, "dev: size erasesize name\n");
for (i=0; i< MAX_MTD_DEVICES; i++) {
@ -337,7 +337,7 @@ static int mtd_read_proc (char *page, char **start, off_t off, int count,
*eof = 1;
done:
up(&mtd_table_mutex);
mutex_unlock(&mtd_table_mutex);
if (off >= len+begin)
return 0;
*start = page + (off-begin);

View File

@ -10,7 +10,7 @@
#ifndef __MTD_TRANS_H__
#define __MTD_TRANS_H__
#include <asm/semaphore.h>
#include <linux/mutex.h>
struct hd_geometry;
struct mtd_info;
@ -22,7 +22,7 @@ struct mtd_blktrans_dev {
struct mtd_blktrans_ops *tr;
struct list_head list;
struct mtd_info *mtd;
struct semaphore sem;
struct mutex lock;
int devnum;
int blksize;
unsigned long size;

View File

@ -15,7 +15,7 @@
#define __MTD_DOC2000_H__
#include <linux/mtd/mtd.h>
#include <asm/semaphore.h>
#include <linux/mutex.h>
#define DoC_Sig1 0
#define DoC_Sig2 1
@ -187,7 +187,7 @@ struct DiskOnChip {
int numchips;
struct Nand *chips;
struct mtd_info *nextdoc;
struct semaphore lock;
struct mutex lock;
};
int doc_decode_ecc(unsigned char sector[512], unsigned char ecc1[6]);