@@ -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);
@@ -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);
}
@@ -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 {
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(-)