Patchwork [MTD] Only call mtd->sync() method in mtdblock_release if opened for write.

login
register
mail settings
Submitter Alexander Stein
Date Jan. 10, 2012, 12:26 p.m.
Message ID <1326198418-8996-1-git-send-email-alexander.stein@systec-electronic.com>
Download mbox | patch
Permalink /patch/135228/
State New
Headers show

Comments

Alexander Stein - Jan. 10, 2012, 12:26 p.m.
Signed-off-by: Alexander Stein <alexander.stein@systec-electronic.com>
---
 drivers/mtd/mtd_blkdevs.c    |    1 +
 drivers/mtd/mtdblock.c       |    7 +++++--
 include/linux/mtd/blktrans.h |    1 +
 3 files changed, 7 insertions(+), 2 deletions(-)

Patch

diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index ed8b5e7..e8aac1d 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -234,6 +234,7 @@  static int blktrans_open(struct block_device *bdev, fmode_t mode)
 	if (ret)
 		goto error_release;
 
+	dev->file_mode = mode;
 unlock:
 	mutex_unlock(&dev->lock);
 	blktrans_dev_put(dev);
diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
index 7c1dc90..3904df1 100644
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -321,8 +321,11 @@  static int mtdblock_release(struct mtd_blktrans_dev *mbd)
 	mutex_unlock(&mtdblk->cache_mutex);
 
 	if (!--mtdblk->count) {
-		/* It was the last usage. Free the cache */
-		if (mbd->mtd->sync)
+		/*
+		 * It was the last usage. Free the cache
+		 * But only sync if opened writeable
+		 */
+		if ((mbd->file_mode & FMODE_WRITE) && mbd->mtd->sync)
 			mbd->mtd->sync(mbd->mtd);
 		vfree(mtdblk->cache_data);
 	}
diff --git a/include/linux/mtd/blktrans.h b/include/linux/mtd/blktrans.h
index 1bbd9f2..ed270bd 100644
--- a/include/linux/mtd/blktrans.h
+++ b/include/linux/mtd/blktrans.h
@@ -47,6 +47,7 @@  struct mtd_blktrans_dev {
 	struct request_queue *rq;
 	spinlock_t queue_lock;
 	void *priv;
+	fmode_t file_mode;
 };
 
 struct mtd_blktrans_ops {