From patchwork Sat Jan 14 14:55:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artem Bityutskiy X-Patchwork-Id: 136080 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5CFB9B6F62 for ; Sun, 15 Jan 2012 01:55:19 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Rm4zK-0003dq-0Q; Sat, 14 Jan 2012 14:53:46 +0000 Received: from mail-iy0-f177.google.com ([209.85.210.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Rm4zH-0003dc-Ha for linux-mtd@lists.infradead.org; Sat, 14 Jan 2012 14:53:44 +0000 Received: by iakl21 with SMTP id l21so7034827iak.36 for ; Sat, 14 Jan 2012 06:53:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:subject:from:reply-to:to:cc:date:in-reply-to:references :content-type:x-mailer:mime-version; bh=LWyXg91B/GuT8AGY/whn5fIdBVAPlslL0H45dj8X1xg=; b=GCSY7piPVh1x/YNart4Ipvox5XX475x0srRfukbPsFPrcpXCOgpGMlDVx5Y3FHXWOM wZJBigMY+PaIxxNHHgmj6A/AAUrxwfvpYdhQYRntOdfilcJr/YIg7x2EuirFA6sTtW2+ wYUGcu+no5zA/QAFOwFWZPrgKn7vsWjyRE9O8= Received: by 10.50.187.226 with SMTP id fv2mr2631143igc.20.1326552821926; Sat, 14 Jan 2012 06:53:41 -0800 (PST) Received: from [127.0.0.1] (jfdmzpr01-ext.jf.intel.com. [134.134.139.70]) by mx.google.com with ESMTPS id r18sm41819448ibh.4.2012.01.14.06.53.37 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 14 Jan 2012 06:53:40 -0800 (PST) Message-ID: <1326552921.19039.75.camel@sauron.fi.intel.com> Subject: Re: [PATCH] [MTD] Only call mtd->sync() method in mtdblock_release if opened for write. From: Artem Bityutskiy To: Alexander Stein Date: Sat, 14 Jan 2012 16:55:21 +0200 In-Reply-To: <1326198418-8996-1-git-send-email-alexander.stein@systec-electronic.com> References: <1326198418-8996-1-git-send-email-alexander.stein@systec-electronic.com> X-Mailer: Evolution 3.2.2 (3.2.2-1.fc16) Mime-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.210.177 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (dedekind1[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (dedekind1[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: David Woodhouse , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: dedekind1@gmail.com List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org On Tue, 2012-01-10 at 13:26 +0100, Alexander Stein wrote: > Signed-off-by: Alexander Stein Added commit message, amended the patch, and pushed to l2-mtd.git, thanks! From 961aa500ce7592a4ac917b7b56a15d1998722acf Mon Sep 17 00:00:00 2001 From: Alexander Stein Date: Tue, 10 Jan 2012 13:26:58 +0100 Subject: [PATCH] mtd: mtdblock: call mtd_sync() only if opened for write 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 Signed-off-by: Artem Bityutskiy --- drivers/mtd/mtd_blkdevs.c | 1 + drivers/mtd/mtdblock.c | 8 ++++++-- include/linux/mtd/blktrans.h | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index 424ca5f..f1f0671 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -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++; diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c index af65912..6c6d807 100644 --- a/drivers/mtd/mtdblock.c +++ b/drivers/mtd/mtdblock.c @@ -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); } 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 {