mtd: mtdblock: call mtd_sync() only if opened for write
authorAlexander Stein <alexander.stein@systec-electronic.com>
Tue, 10 Jan 2012 12:26:58 +0000 (13:26 +0100)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 26 Mar 2012 23:11:11 +0000 (00:11 +0100)
Because it is useless to call it if the device is opened in R/O mode, and also
harmful: on CFI NOR flash it may block for long time waiting for erase
operations to complete is another partition with a R/W file-system on this
chip.

Artem Bityutskiy: write commit message, amend the patch to match the latest
tree (we use mtd_sync(), not mtd->sync() nowadays).

Signed-off-by: Alexander Stein <alexander.stein@systec-electronic.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
drivers/mtd/mtd_blkdevs.c
drivers/mtd/mtdblock.c
include/linux/mtd/blktrans.h

index 424ca5f93c6c37f74304f04a2e393523ae453f7a..f1f06715d4e0b8e3f800e456ef83aa3d27fee3ce 100644 (file)
@@ -233,6 +233,7 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode)
        ret = __get_mtd_device(dev->mtd);
        if (ret)
                goto error_release;
+       dev->file_mode = mode;
 
 unlock:
        dev->open++;
index af6591237b9b51f22022e61a653fa7a5d8e29845..6c6d80736fadfb4013871b31795e17354a4d671e 100644 (file)
@@ -321,8 +321,12 @@ 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 */
-               mtd_sync(mbd->mtd);
+               /*
+                * It was the last usage. Free the cache, but only sync if
+                * opened for writing.
+                */
+               if (mbd->file_mode & FMODE_WRITE)
+                       mtd_sync(mbd->mtd);
                vfree(mtdblk->cache_data);
        }
 
index 1bbd9f28924564d188f2a01bc2c14a3ee49f691b..ed270bd2e4df0d724bda716234a418cec30822c0 100644 (file)
@@ -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 {