From patchwork Thu Feb 4 07:18:37 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Stanley.Miao" X-Patchwork-Id: 44450 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 15A25B7D27 for ; Thu, 4 Feb 2010 18:14:54 +1100 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1Ncvt8-00032H-IK; Thu, 04 Feb 2010 07:12:30 +0000 Received: from mail.windriver.com ([147.11.1.11]) by bombadil.infradead.org with esmtps (Exim 4.69 #1 (Red Hat Linux)) id 1Ncvt2-0002jg-Kf for linux-mtd@lists.infradead.org; Thu, 04 Feb 2010 07:12:28 +0000 Received: from ALA-MAIL03.corp.ad.wrs.com (ala-mail03 [147.11.57.144]) by mail.windriver.com (8.14.3/8.14.3) with ESMTP id o147CMjl025359 for ; Wed, 3 Feb 2010 23:12:22 -0800 (PST) Received: from ala-mail06.corp.ad.wrs.com ([147.11.57.147]) by ALA-MAIL03.corp.ad.wrs.com with Microsoft SMTPSVC(6.0.3790.1830); Wed, 3 Feb 2010 23:12:22 -0800 Received: from localhost.localdomain ([128.224.163.169]) by ala-mail06.corp.ad.wrs.com with Microsoft SMTPSVC(6.0.3790.1830); Wed, 3 Feb 2010 23:12:22 -0800 From: "Stanley.Miao" To: linux-mtd@lists.infradead.org Subject: [PATCH 1/1] mtd: nand: move the checking the validity of oob into nand_write_oob Date: Thu, 4 Feb 2010 15:18:37 +0800 Message-Id: <1265267917-2487-2-git-send-email-stanley.miao@windriver.com> X-Mailer: git-send-email 1.5.6.3 In-Reply-To: <1265267917-2487-1-git-send-email-stanley.miao@windriver.com> References: <1265267917-2487-1-git-send-email-stanley.miao@windriver.com> X-OriginalArrivalTime: 04 Feb 2010 07:12:22.0782 (UTC) FILETIME=[6593E1E0:01CAA569] X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20100204_021224_910993_DD86440C X-CRM114-Status: GOOD ( 24.73 ) X-Spam-Score: -1.0 (-) X-Spam-Report: SpamAssassin version 3.2.5 on bombadil.infradead.org summary: Content analysis details: (-1.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [147.11.1.11 listed in list.dnswl.org] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 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 nand_write_oob will invoke nand_do_write_oob or nand_do_write_ops depending on if ops->datbuf is NULL. nand_do_write_oob checked the validity of oob but nand_do_write_ops didn't. Now move the check into nand_write_oob to ensure the validity of oobbuf. Signed-off-by: Stanley.Miao --- drivers/mtd/nand/nand_base.c | 69 ++++++++++++++++++++++------------------- 1 files changed, 37 insertions(+), 32 deletions(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 8f2958f..29e2a06 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -2113,40 +2113,9 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len, static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops) { - int chipnr, page, status, len; + int chipnr, page, status; struct nand_chip *chip = mtd->priv; - DEBUG(MTD_DEBUG_LEVEL3, "%s: to = 0x%08x, len = %i\n", - __func__, (unsigned int)to, (int)ops->ooblen); - - if (ops->mode == MTD_OOB_AUTO) - len = chip->ecc.layout->oobavail; - else - len = mtd->oobsize; - - /* Do not allow write past end of page */ - if ((ops->ooboffs + ops->ooblen) > len) { - DEBUG(MTD_DEBUG_LEVEL0, "%s: Attempt to write " - "past end of page\n", __func__); - return -EINVAL; - } - - if (unlikely(ops->ooboffs >= len)) { - DEBUG(MTD_DEBUG_LEVEL0, "%s: Attempt to start " - "write outside oob\n", __func__); - return -EINVAL; - } - - /* Do not allow reads past end of device */ - if (unlikely(to >= mtd->size || - ops->ooboffs + ops->ooblen > - ((mtd->size >> chip->page_shift) - - (to >> chip->page_shift)) * len)) { - DEBUG(MTD_DEBUG_LEVEL0, "%s: Attempt write beyond " - "end of device\n", __func__); - return -EINVAL; - } - chipnr = (int)(to >> chip->chip_shift); chip->select_chip(mtd, chipnr); @@ -2203,6 +2172,42 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to, return -EINVAL; } + if (ops->oobbuf) { + int len; + DEBUG(MTD_DEBUG_LEVEL3, "%s: to = 0x%08x, ooblen = %i\n", + __func__, (unsigned int)to, (int)ops->ooblen); + + if (ops->mode == MTD_OOB_AUTO) + len = chip->ecc.layout->oobavail; + else + len = mtd->oobsize; + + /* Do not allow write past end of page */ + if ((ops->ooboffs + ops->ooblen) > len) { + DEBUG(MTD_DEBUG_LEVEL0, "%s: Attempt to write " + "past end of page\n", __func__); + return -EINVAL; + } + + if (unlikely(ops->ooboffs >= len)) { + DEBUG(MTD_DEBUG_LEVEL0, "%s: Attempt to start " + "write outside oob\n", __func__); + return -EINVAL; + } + + /* Do not allow reads past end of device */ + if (unlikely(to >= mtd->size || + ops->ooboffs + ops->ooblen > + ((mtd->size >> chip->page_shift) - + (to >> chip->page_shift)) * len)) { + DEBUG(MTD_DEBUG_LEVEL0, "%s: Attempt write beyond " + "end of device\n", __func__); + return -EINVAL; + } + + + } + nand_get_device(chip, mtd, FL_WRITING); switch(ops->mode) {