Skip to content

Commit

Permalink
mtd: do not use mtd->sync directly
Browse files Browse the repository at this point in the history
This patch teaches 'mtd_sync()' to do nothing when the MTD driver does
not have the '->sync()' method, which allows us to remove all direct
'mtd->sync' accesses.

Signed-off-by: Artem Bityutskiy <[email protected]>
Signed-off-by: David Woodhouse <[email protected]>
  • Loading branch information
dedekind authored and David Woodhouse committed Jan 9, 2012
1 parent 1dbebd3 commit 327cf29
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 21 deletions.
3 changes: 1 addition & 2 deletions drivers/mtd/ftl.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,7 @@ static int reclaim_block(partition_t *part)
if (queued) {
pr_debug("ftl_cs: waiting for transfer "
"unit to be prepared...\n");
if (part->mbd.mtd->sync)
mtd_sync(part->mbd.mtd);
mtd_sync(part->mbd.mtd);
} else {
static int ne = 0;
if (++ne < 5)
Expand Down
7 changes: 2 additions & 5 deletions drivers/mtd/mtdblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@ static int mtdblock_release(struct mtd_blktrans_dev *mbd)

if (!--mtdblk->count) {
/* It was the last usage. Free the cache */
if (mbd->mtd->sync)
mtd_sync(mbd->mtd);
mtd_sync(mbd->mtd);
vfree(mtdblk->cache_data);
}

Expand All @@ -341,9 +340,7 @@ static int mtdblock_flush(struct mtd_blktrans_dev *dev)
mutex_lock(&mtdblk->cache_mutex);
write_cached_data(mtdblk);
mutex_unlock(&mtdblk->cache_mutex);

if (dev->mtd->sync)
mtd_sync(dev->mtd);
mtd_sync(dev->mtd);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/mtdchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static int mtdchar_close(struct inode *inode, struct file *file)
pr_debug("MTD_close\n");

/* Only sync if opened RW */
if ((file->f_mode & FMODE_WRITE) && mtd->sync)
if ((file->f_mode & FMODE_WRITE))
mtd_sync(mtd);

iput(mfi->ino);
Expand Down
3 changes: 1 addition & 2 deletions drivers/mtd/mtdswap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1047,8 +1047,7 @@ static int mtdswap_flush(struct mtd_blktrans_dev *dev)
{
struct mtdswap_dev *d = MTDSWAP_MBD_TO_MTDSWAP(dev);

if (d->mtd->sync)
mtd_sync(d->mtd);
mtd_sync(d->mtd);
return 0;
}

Expand Down
3 changes: 1 addition & 2 deletions drivers/mtd/rfd_ftl.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,7 @@ static int reclaim_block(struct partition *part, u_long *old_sector)
int rc;

/* we have a race if sync doesn't exist */
if (part->mbd.mtd->sync)
mtd_sync(part->mbd.mtd);
mtd_sync(part->mbd.mtd);

score = 0x7fffffff; /* MAX_INT */
best_block = -1;
Expand Down
4 changes: 1 addition & 3 deletions drivers/mtd/ubi/kapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,7 @@ int ubi_sync(int ubi_num)
if (!ubi)
return -ENODEV;

if (ubi->mtd->sync)
mtd_sync(ubi->mtd);

mtd_sync(ubi->mtd);
ubi_put_device(ubi);
return 0;
}
Expand Down
4 changes: 1 addition & 3 deletions fs/jffs2/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,7 @@ static void jffs2_put_super (struct super_block *sb)
jffs2_flash_cleanup(c);
kfree(c->inocache_list);
jffs2_clear_xattr_subsystem(c);
if (c->mtd->sync)
mtd_sync(c->mtd);

mtd_sync(c->mtd);
D1(printk(KERN_DEBUG "jffs2_put_super returning\n"));
}

Expand Down
3 changes: 1 addition & 2 deletions fs/logfs/dev_mtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ static void logfs_mtd_sync(struct super_block *sb)
{
struct mtd_info *mtd = logfs_super(sb)->s_mtd;

if (mtd->sync)
mtd_sync(mtd);
mtd_sync(mtd);
}

static int logfs_mtd_readpage(void *_sb, struct page *page)
Expand Down
3 changes: 2 additions & 1 deletion include/linux/mtd/mtd.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,

static inline void mtd_sync(struct mtd_info *mtd)
{
mtd->sync(mtd);
if (mtd->sync)
mtd->sync(mtd);
}

/* Chip-supported device locking */
Expand Down

0 comments on commit 327cf29

Please sign in to comment.