From patchwork Tue Apr 17 11:11:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Djelic X-Patchwork-Id: 153134 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 98CDDB707F for ; Tue, 17 Apr 2012 21:15:03 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SK6LI-000725-Ea; Tue, 17 Apr 2012 11:13:04 +0000 Received: from mail-wi0-f169.google.com ([209.85.212.169]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1SK6LC-00071K-Qu for linux-mtd@lists.infradead.org; Tue, 17 Apr 2012 11:13:02 +0000 Received: by wibhm17 with SMTP id hm17so489988wib.0 for ; Tue, 17 Apr 2012 04:12:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=bLO/ApugNiK8BYT/H7zdrsVx4LYbGFaaeP3WPL1Dfaw=; b=EaxyvFsJHb4Ltb0bVM86sVL1+e+hHs9ALt6ANs3GaWbO/vZMbMS7r8BLBqmr6t4Ijm ZKBXH8y/xu+uhqs8LbAUYLj3pKy+cV6+lv4fqSL0CucEYW8o6W4hMaGH1hfFxnn0iI5F l3LSnyIloPTNUhh4TVUwDh6jgEOkNxKtumT4I51iZcLkM3Wq+af55p7+XNJ4FokJRc1T uOoXuG/OOeMLygCtivq7GTfXjqa4lG7KGZUGLr74be3tgXN6n6++7n9P7nZg9QH0DI// zBcLoswIWJvAfh1bg/7qE7oON2n5RG9BV8WTEgHfb0+3yIBOkoM5lGcIJl1eN6dnxBkL 8tRg== Received: by 10.216.137.232 with SMTP id y82mr9018942wei.82.1334661177115; Tue, 17 Apr 2012 04:12:57 -0700 (PDT) Received: from aigle.Parrot.Biz (102.213-31-46.rdns.acropolistelecom.net. [46.31.213.102]) by mx.google.com with ESMTPS id gg2sm42278116wib.7.2012.04.17.04.12.55 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 17 Apr 2012 04:12:56 -0700 (PDT) From: Ivan Djelic To: linux-mtd@lists.infradead.org Subject: [PATCH] mtd: nand: omap: fix race condition in omap_wait() Date: Tue, 17 Apr 2012 13:11:53 +0200 Message-Id: <1334661113-24709-1-git-send-email-ivan.djelic@parrot.com> X-Mailer: git-send-email 1.7.10 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.212.169 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (ivantchek[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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: ivan.djelic@parrot.com 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 If a context switch occurs in function omap_wait() just before the while loop is entered, then upon return from context switch the timeout may already have elapsed: in that case, status is never read from NAND device, and omap_wait() returns an error. This failure has been experimentally observed during stress tests. This patch ensures a NAND status read is always performed before returning, as in the generic nand_wait() function. Signed-off-by: Ivan Djelic --- drivers/mtd/nand/omap2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c index c2b0bba..45c6205 100644 --- a/drivers/mtd/nand/omap2.c +++ b/drivers/mtd/nand/omap2.c @@ -879,7 +879,7 @@ static int omap_wait(struct mtd_info *mtd, struct nand_chip *chip) struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, mtd); unsigned long timeo = jiffies; - int status = NAND_STATUS_FAIL, state = this->state; + int status, state = this->state; if (state == FL_ERASING) timeo += (HZ * 400) / 1000; @@ -894,6 +894,8 @@ static int omap_wait(struct mtd_info *mtd, struct nand_chip *chip) break; cond_resched(); } + + status = gpmc_nand_read(info->gpmc_cs, GPMC_NAND_DATA); return status; }