From patchwork Sat Feb 13 13:03:07 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 45238 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 5009AB7C33 for ; Sun, 14 Feb 2010 00:06:04 +1100 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NgHf5-0001ks-5F; Sat, 13 Feb 2010 13:03:51 +0000 Received: from mail-fx0-f223.google.com ([209.85.220.223]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NgHex-0001eL-KU for linux-mtd@lists.infradead.org; Sat, 13 Feb 2010 13:03:49 +0000 Received: by mail-fx0-f223.google.com with SMTP id 23so3374314fxm.2 for ; Sat, 13 Feb 2010 05:03:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references; bh=79lCl+GV6zXQF4JkKWG7hJC/lCd0rulkGX6CkgXiDe8=; b=StkLjoNzY6z+/AvNCqILyzVewgM1F/2cb+Zgj9m8UO6fl+8Lo4CepRDDCYNDT2LPTq XcDqjJkaH38N+KoI7njFEs6jkB1fKuXyFfbmhqVVZ1GsgEkObrafxs3YMRFdYZL/YVAR ea9Vki5Shw53CTZlszdO8lC5VTfpot8gyjGO8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=Q8C1czqzn7grQ7dOMCzghlpSp7TFKynQJNW7VRI3jv4TZjHYsryrUvvKQBSmscA/wm pQNcNzcQu5QgLX2QsCrArM1eYE9YGDOG9xTWh0jdy/7Xku99SwguHAIbGR8jkewjHeBd f9rFC5mI36fstJAH9f5XwUHaNVyylpKHPGyXw= Received: by 10.223.94.200 with SMTP id a8mr608747fan.86.1266066223171; Sat, 13 Feb 2010 05:03:43 -0800 (PST) Received: from localhost.localdomain (87.68.247.153.adsl.012.net.il [87.68.247.153]) by mx.google.com with ESMTPS id 16sm2205430fxm.0.2010.02.13.05.03.40 (version=SSLv3 cipher=RC4-MD5); Sat, 13 Feb 2010 05:03:42 -0800 (PST) From: Maxim Levitsky To: David Woodhouse Subject: [PATCH 08/14] MTD: nand: cleanup the nand_do_write_ops Date: Sat, 13 Feb 2010 15:03:07 +0200 Message-Id: <1266066193-17625-9-git-send-email-maximlevitsky@gmail.com> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1266066193-17625-1-git-send-email-maximlevitsky@gmail.com> References: <1266066193-17625-1-git-send-email-maximlevitsky@gmail.com> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20100213_080343_861133_D12102A0 X-CRM114-Status: GOOD ( 15.01 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.2.5 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- _SUMMARY_ Cc: Maxim Levitsky , Alex Dubov , Artem Bityutskiy , joern , Vitaly Wool , linux-kernel , "stanley.miao" , linux-mtd , Thomas Gleixner 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_do_write_ops have broken in regard to writing several pages, each with its own oob. Although nand_do_write_ops intends to allow such mode, it fails do do so Probably this was never tested. Also add missing checks for attemts to write at illegal offsets. Signed-off-by: Maxim Levitsky --- drivers/mtd/nand/nand_base.c | 24 +++++++++++++++++------- 1 files changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 53c1e04..2ff9c02 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -1881,11 +1881,9 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip, * @oob: oob data buffer * @ops: oob ops structure */ -static uint8_t *nand_fill_oob(struct nand_chip *chip, uint8_t *oob, - struct mtd_oob_ops *ops) +static uint8_t *nand_fill_oob(struct nand_chip *chip, uint8_t *oob, size_t len, + struct mtd_oob_ops *ops) { - size_t len = ops->ooblen; - switch(ops->mode) { case MTD_OOB_PLACE: @@ -1940,6 +1938,11 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, int chipnr, realpage, page, blockmask, column; struct nand_chip *chip = mtd->priv; uint32_t writelen = ops->len; + + uint32_t oobwritelen = ops->ooblen; + uint32_t oobmaxlen = ops->mode == MTD_OOB_AUTO ? + mtd->oobavail : mtd->oobsize; + uint8_t *oob = ops->oobbuf; uint8_t *buf = ops->datbuf; int ret, subpage; @@ -1981,6 +1984,10 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, if (likely(!oob)) memset(chip->oob_poi, 0xff, mtd->oobsize); + /* Don't allow multipage oob writes with offset */ + if (ops->ooboffs && (ops->ooboffs + ops->ooblen > oobmaxlen)) + return -EINVAL; + while(1) { int bytes = mtd->writesize; int cached = writelen > bytes && page != blockmask; @@ -1996,8 +2003,11 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, wbuf = chip->buffers->databuf; } - if (unlikely(oob)) - oob = nand_fill_oob(chip, oob, ops); + if (unlikely(oob)) { + size_t len = min(oobwritelen, oobmaxlen); + oob = nand_fill_oob(chip, oob, len, ops); + oobwritelen -= len; + } ret = chip->write_page(mtd, chip, wbuf, page, cached, (ops->mode == MTD_OOB_RAW)); @@ -2171,7 +2181,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, chip->pagebuf = -1; memset(chip->oob_poi, 0xff, mtd->oobsize); - nand_fill_oob(chip, ops->oobbuf, ops); + nand_fill_oob(chip, ops->oobbuf, ops->ooblen, ops); status = chip->ecc.write_oob(mtd, chip, page & chip->pagemask); memset(chip->oob_poi, 0xff, mtd->oobsize);