From patchwork Tue Jan 10 12:26:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Stein X-Patchwork-Id: 135228 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 94632B6FC4 for ; Tue, 10 Jan 2012 23:32:01 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1RkanM-0002Eq-KV; Tue, 10 Jan 2012 12:27:16 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1RkanK-0002ER-28 for linux-mtd@merlin.infradead.org; Tue, 10 Jan 2012 12:27:14 +0000 Received: from webbox1416.server-home.net ([77.236.96.61]) by casper.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1RkanG-0001tY-Ta for linux-mtd@lists.infradead.org; Tue, 10 Jan 2012 12:27:11 +0000 Received: from comm.systec-electronic.de (95-91-85-164-dynip.superkabel.de [95.91.85.164]) by webbox1416.server-home.net (Postfix) with ESMTPA id 92C4C27A604; Tue, 10 Jan 2012 13:30:51 +0100 (CET) Received: from ws-stein.systec-electronic.de (unknown [192.168.10.38]) by comm.systec-electronic.de (Postfix) with ESMTP id DE75C97C068; Tue, 10 Jan 2012 13:27:06 +0100 (CET) From: Alexander Stein To: linux-mtd@lists.infradead.org Subject: [PATCH] [MTD] Only call mtd->sync() method in mtdblock_release if opened for write. Date: Tue, 10 Jan 2012 13:26:58 +0100 Message-Id: <1326198418-8996-1-git-send-email-alexander.stein@systec-electronic.com> X-Mailer: git-send-email 1.7.3.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20120110_122711_131140_3FC1AA83 X-CRM114-Status: GOOD ( 11.07 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on casper.infradead.org summary: Content analysis details: (-1.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: David Woodhouse , linux-kernel@vger.kernel.org, Alexander Stein X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Signed-off-by: Alexander Stein --- drivers/mtd/mtd_blkdevs.c | 1 + drivers/mtd/mtdblock.c | 7 +++++-- include/linux/mtd/blktrans.h | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) 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 {