Skip to content

Commit

Permalink
[PATCH] sem2mutex: drivers/mtd/
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Ingo Molnar authored and Linus Torvalds committed Mar 31, 2006
1 parent 040d79f commit 48b1926
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 68 deletions.
10 changes: 5 additions & 5 deletions drivers/mtd/devices/blkmtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
};


Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 7 additions & 6 deletions drivers/mtd/devices/block2mtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 $"

Expand All @@ -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;
};


Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
30 changes: 15 additions & 15 deletions drivers/mtd/devices/doc2000.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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;

}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
32 changes: 16 additions & 16 deletions drivers/mtd/mtd_blkdevs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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);

Expand Down
14 changes: 8 additions & 6 deletions drivers/mtd/mtdblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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 */
Expand All @@ -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);
Expand Down
Loading

0 comments on commit 48b1926

Please sign in to comment.