Skip to content

Commit 48b1926

Browse files
Ingo MolnarLinus Torvalds
authored andcommitted
[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>
1 parent 040d79f commit 48b1926

File tree

8 files changed

+71
-68
lines changed

8 files changed

+71
-68
lines changed

drivers/mtd/devices/blkmtd.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <linux/list.h>
3030
#include <linux/init.h>
3131
#include <linux/mtd/mtd.h>
32-
32+
#include <linux/mutex.h>
3333

3434
#define err(format, arg...) printk(KERN_ERR "blkmtd: " format "\n" , ## arg)
3535
#define info(format, arg...) printk(KERN_INFO "blkmtd: " format "\n" , ## arg)
@@ -46,7 +46,7 @@ struct blkmtd_dev {
4646
struct list_head list;
4747
struct block_device *blkdev;
4848
struct mtd_info mtd_info;
49-
struct semaphore wrbuf_mutex;
49+
struct mutex wrbuf_mutex;
5050
};
5151

5252

@@ -268,7 +268,7 @@ static int write_pages(struct blkmtd_dev *dev, const u_char *buf, loff_t to,
268268
if(end_len)
269269
pagecnt++;
270270

271-
down(&dev->wrbuf_mutex);
271+
mutex_lock(&dev->wrbuf_mutex);
272272

273273
DEBUG(3, "blkmtd: write: start_len = %zd len = %zd end_len = %zd pagecnt = %d\n",
274274
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,
376376
blkmtd_write_out(bio);
377377

378378
DEBUG(2, "blkmtd: write: end, retlen = %zd, err = %d\n", *retlen, err);
379-
up(&dev->wrbuf_mutex);
379+
mutex_unlock(&dev->wrbuf_mutex);
380380

381381
if(retlen)
382382
*retlen = thislen;
@@ -659,7 +659,7 @@ static struct blkmtd_dev *add_device(char *devname, int readonly, int erase_size
659659
memset(dev, 0, sizeof(struct blkmtd_dev));
660660
dev->blkdev = bdev;
661661
if(!readonly) {
662-
init_MUTEX(&dev->wrbuf_mutex);
662+
mutex_init(&dev->wrbuf_mutex);
663663
}
664664

665665
dev->mtd_info.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;

drivers/mtd/devices/block2mtd.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/init.h>
1919
#include <linux/mtd/mtd.h>
2020
#include <linux/buffer_head.h>
21+
#include <linux/mutex.h>
2122

2223
#define VERSION "$Revision: 1.30 $"
2324

@@ -31,7 +32,7 @@ struct block2mtd_dev {
3132
struct list_head list;
3233
struct block_device *blkdev;
3334
struct mtd_info mtd;
34-
struct semaphore write_mutex;
35+
struct mutex write_mutex;
3536
};
3637

3738

@@ -134,9 +135,9 @@ static int block2mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
134135
int err;
135136

136137
instr->state = MTD_ERASING;
137-
down(&dev->write_mutex);
138+
mutex_lock(&dev->write_mutex);
138139
err = _block2mtd_erase(dev, from, len);
139-
up(&dev->write_mutex);
140+
mutex_unlock(&dev->write_mutex);
140141
if (err) {
141142
ERROR("erase failed err = %d", err);
142143
instr->state = MTD_ERASE_FAILED;
@@ -249,9 +250,9 @@ static int block2mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
249250
if (to + len > mtd->size)
250251
len = mtd->size - to;
251252

252-
down(&dev->write_mutex);
253+
mutex_lock(&dev->write_mutex);
253254
err = _block2mtd_write(dev, buf, to, len, retlen);
254-
up(&dev->write_mutex);
255+
mutex_unlock(&dev->write_mutex);
255256
if (err > 0)
256257
err = 0;
257258
return err;
@@ -310,7 +311,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
310311
goto devinit_err;
311312
}
312313

313-
init_MUTEX(&dev->write_mutex);
314+
mutex_init(&dev->write_mutex);
314315

315316
/* Setup the MTD structure */
316317
/* make the name contain the block device in */

drivers/mtd/devices/doc2000.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ static void DoC2k_init(struct mtd_info *mtd)
606606

607607
this->curfloor = -1;
608608
this->curchip = -1;
609-
init_MUTEX(&this->lock);
609+
mutex_init(&this->lock);
610610

611611
/* Ident all the chips present. */
612612
DoC_ScanChips(this, maxchips);
@@ -646,7 +646,7 @@ static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
646646
if (from >= this->totlen)
647647
return -EINVAL;
648648

649-
down(&this->lock);
649+
mutex_lock(&this->lock);
650650

651651
*retlen = 0;
652652
while (left) {
@@ -775,7 +775,7 @@ static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
775775
buf += len;
776776
}
777777

778-
up(&this->lock);
778+
mutex_unlock(&this->lock);
779779

780780
return ret;
781781
}
@@ -804,7 +804,7 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
804804
if (to >= this->totlen)
805805
return -EINVAL;
806806

807-
down(&this->lock);
807+
mutex_lock(&this->lock);
808808

809809
*retlen = 0;
810810
while (left) {
@@ -874,7 +874,7 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
874874
printk(KERN_ERR "Error programming flash\n");
875875
/* Error in programming */
876876
*retlen = 0;
877-
up(&this->lock);
877+
mutex_unlock(&this->lock);
878878
return -EIO;
879879
}
880880

@@ -936,7 +936,7 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
936936
printk(KERN_ERR "Error programming flash\n");
937937
/* Error in programming */
938938
*retlen = 0;
939-
up(&this->lock);
939+
mutex_unlock(&this->lock);
940940
return -EIO;
941941
}
942942

@@ -957,7 +957,7 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
957957

958958
ret = doc_write_oob_nolock(mtd, to, 8, &dummy, x);
959959
if (ret) {
960-
up(&this->lock);
960+
mutex_unlock(&this->lock);
961961
return ret;
962962
}
963963
}
@@ -967,7 +967,7 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
967967
buf += len;
968968
}
969969

970-
up(&this->lock);
970+
mutex_unlock(&this->lock);
971971
return 0;
972972
}
973973

@@ -1038,7 +1038,7 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
10381038
int len256 = 0, ret;
10391039
struct Nand *mychip;
10401040

1041-
down(&this->lock);
1041+
mutex_lock(&this->lock);
10421042

10431043
mychip = &this->chips[ofs >> this->chipshift];
10441044

@@ -1084,7 +1084,7 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
10841084

10851085
ret = DoC_WaitReady(this);
10861086

1087-
up(&this->lock);
1087+
mutex_unlock(&this->lock);
10881088
return ret;
10891089

10901090
}
@@ -1198,10 +1198,10 @@ static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
11981198
struct DiskOnChip *this = mtd->priv;
11991199
int ret;
12001200

1201-
down(&this->lock);
1201+
mutex_lock(&this->lock);
12021202
ret = doc_write_oob_nolock(mtd, ofs, len, retlen, buf);
12031203

1204-
up(&this->lock);
1204+
mutex_unlock(&this->lock);
12051205
return ret;
12061206
}
12071207

@@ -1215,10 +1215,10 @@ static int doc_erase(struct mtd_info *mtd, struct erase_info *instr)
12151215
struct Nand *mychip;
12161216
int status;
12171217

1218-
down(&this->lock);
1218+
mutex_lock(&this->lock);
12191219

12201220
if (ofs & (mtd->erasesize-1) || len & (mtd->erasesize-1)) {
1221-
up(&this->lock);
1221+
mutex_unlock(&this->lock);
12221222
return -EINVAL;
12231223
}
12241224

@@ -1266,7 +1266,7 @@ static int doc_erase(struct mtd_info *mtd, struct erase_info *instr)
12661266
callback:
12671267
mtd_erase_callback(instr);
12681268

1269-
up(&this->lock);
1269+
mutex_unlock(&this->lock);
12701270
return 0;
12711271
}
12721272

drivers/mtd/mtd_blkdevs.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
#include <linux/spinlock.h>
2020
#include <linux/hdreg.h>
2121
#include <linux/init.h>
22-
#include <asm/semaphore.h>
22+
#include <linux/mutex.h>
2323
#include <asm/uaccess.h>
2424

2525
static LIST_HEAD(blktrans_majors);
2626

27-
extern struct semaphore mtd_table_mutex;
27+
extern struct mutex mtd_table_mutex;
2828
extern struct mtd_info *mtd_table[];
2929

3030
struct mtd_blkcore_priv {
@@ -122,9 +122,9 @@ static int mtd_blktrans_thread(void *arg)
122122

123123
spin_unlock_irq(rq->queue_lock);
124124

125-
down(&dev->sem);
125+
mutex_lock(&dev->lock);
126126
res = do_blktrans_request(tr, dev, req);
127-
up(&dev->sem);
127+
mutex_unlock(&dev->lock);
128128

129129
spin_lock_irq(rq->queue_lock);
130130

@@ -235,8 +235,8 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
235235
int last_devnum = -1;
236236
struct gendisk *gd;
237237

238-
if (!down_trylock(&mtd_table_mutex)) {
239-
up(&mtd_table_mutex);
238+
if (!!mutex_trylock(&mtd_table_mutex)) {
239+
mutex_unlock(&mtd_table_mutex);
240240
BUG();
241241
}
242242

@@ -267,7 +267,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
267267
return -EBUSY;
268268
}
269269

270-
init_MUTEX(&new->sem);
270+
mutex_init(&new->lock);
271271
list_add_tail(&new->list, &tr->devs);
272272
added:
273273
if (!tr->writesect)
@@ -313,8 +313,8 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
313313

314314
int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)
315315
{
316-
if (!down_trylock(&mtd_table_mutex)) {
317-
up(&mtd_table_mutex);
316+
if (!!mutex_trylock(&mtd_table_mutex)) {
317+
mutex_unlock(&mtd_table_mutex);
318318
BUG();
319319
}
320320

@@ -378,14 +378,14 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
378378

379379
memset(tr->blkcore_priv, 0, sizeof(*tr->blkcore_priv));
380380

381-
down(&mtd_table_mutex);
381+
mutex_lock(&mtd_table_mutex);
382382

383383
ret = register_blkdev(tr->major, tr->name);
384384
if (ret) {
385385
printk(KERN_WARNING "Unable to register %s block device on major %d: %d\n",
386386
tr->name, tr->major, ret);
387387
kfree(tr->blkcore_priv);
388-
up(&mtd_table_mutex);
388+
mutex_unlock(&mtd_table_mutex);
389389
return ret;
390390
}
391391
spin_lock_init(&tr->blkcore_priv->queue_lock);
@@ -396,7 +396,7 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
396396
if (!tr->blkcore_priv->rq) {
397397
unregister_blkdev(tr->major, tr->name);
398398
kfree(tr->blkcore_priv);
399-
up(&mtd_table_mutex);
399+
mutex_unlock(&mtd_table_mutex);
400400
return -ENOMEM;
401401
}
402402

@@ -407,7 +407,7 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
407407
blk_cleanup_queue(tr->blkcore_priv->rq);
408408
unregister_blkdev(tr->major, tr->name);
409409
kfree(tr->blkcore_priv);
410-
up(&mtd_table_mutex);
410+
mutex_unlock(&mtd_table_mutex);
411411
return ret;
412412
}
413413

@@ -419,7 +419,7 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
419419
tr->add_mtd(tr, mtd_table[i]);
420420
}
421421

422-
up(&mtd_table_mutex);
422+
mutex_unlock(&mtd_table_mutex);
423423

424424
return 0;
425425
}
@@ -428,7 +428,7 @@ int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr)
428428
{
429429
struct list_head *this, *next;
430430

431-
down(&mtd_table_mutex);
431+
mutex_lock(&mtd_table_mutex);
432432

433433
/* Clean up the kernel thread */
434434
tr->blkcore_priv->exiting = 1;
@@ -446,7 +446,7 @@ int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr)
446446
blk_cleanup_queue(tr->blkcore_priv->rq);
447447
unregister_blkdev(tr->major, tr->name);
448448

449-
up(&mtd_table_mutex);
449+
mutex_unlock(&mtd_table_mutex);
450450

451451
kfree(tr->blkcore_priv);
452452

drivers/mtd/mtdblock.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919

2020
#include <linux/mtd/mtd.h>
2121
#include <linux/mtd/blktrans.h>
22+
#include <linux/mutex.h>
23+
2224

2325
static struct mtdblk_dev {
2426
struct mtd_info *mtd;
2527
int count;
26-
struct semaphore cache_sem;
28+
struct mutex cache_mutex;
2729
unsigned char *cache_data;
2830
unsigned long cache_offset;
2931
unsigned int cache_size;
@@ -284,7 +286,7 @@ static int mtdblock_open(struct mtd_blktrans_dev *mbd)
284286
mtdblk->count = 1;
285287
mtdblk->mtd = mtd;
286288

287-
init_MUTEX (&mtdblk->cache_sem);
289+
mutex_init(&mtdblk->cache_mutex);
288290
mtdblk->cache_state = STATE_EMPTY;
289291
if ((mtdblk->mtd->flags & MTD_CAP_RAM) != MTD_CAP_RAM &&
290292
mtdblk->mtd->erasesize) {
@@ -306,9 +308,9 @@ static int mtdblock_release(struct mtd_blktrans_dev *mbd)
306308

307309
DEBUG(MTD_DEBUG_LEVEL1, "mtdblock_release\n");
308310

309-
down(&mtdblk->cache_sem);
311+
mutex_lock(&mtdblk->cache_mutex);
310312
write_cached_data(mtdblk);
311-
up(&mtdblk->cache_sem);
313+
mutex_unlock(&mtdblk->cache_mutex);
312314

313315
if (!--mtdblk->count) {
314316
/* It was the last usage. Free the device */
@@ -327,9 +329,9 @@ static int mtdblock_flush(struct mtd_blktrans_dev *dev)
327329
{
328330
struct mtdblk_dev *mtdblk = mtdblks[dev->devnum];
329331

330-
down(&mtdblk->cache_sem);
332+
mutex_lock(&mtdblk->cache_mutex);
331333
write_cached_data(mtdblk);
332-
up(&mtdblk->cache_sem);
334+
mutex_unlock(&mtdblk->cache_mutex);
333335

334336
if (mtdblk->mtd->sync)
335337
mtdblk->mtd->sync(mtdblk->mtd);

0 commit comments

Comments
 (0)