From patchwork Wed Feb 3 15:48:46 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: vimal singh X-Patchwork-Id: 44386 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 EDF76B7D36 for ; Thu, 4 Feb 2010 02:52:55 +1100 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NchVI-0000BK-Iu; Wed, 03 Feb 2010 15:50:56 +0000 Received: from mail-bw0-f221.google.com ([209.85.218.221]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NchVB-00008v-Bj for linux-mtd@lists.infradead.org; Wed, 03 Feb 2010 15:50:54 +0000 Received: by bwz21 with SMTP id 21so1147942bwz.4 for ; Wed, 03 Feb 2010 07:50:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:from:date:message-id :subject:to:cc:content-type; bh=ejnNPO05vTa0PvRqVhrKRrebwA5ewrO+ffrJa4WpTQk=; b=IcXy2XWwBkd/YhhIpY+Ou1QKKL3Ml2BdSYEBsCZAmDDWrxgFb25iSD/iIOqvGd6nTF OygGWFwLzdSQqT2vRWPOaM/DkNNM6ce0mc/qvspRCwuce3/LZO/RN1B5zouAmdOC5383 VxHL4z+vLzzSml8kP5j4xudAE/9x5jZEHS6r4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:cc:content-type; b=ip+BLjsQTRKHxpHK8CW8dSCFjah8EzxAN7NY3gcZ/gZsboP8g3gH7fRkiWE+yww+ew skffbj3st1EUc4bVX2OPGI9S9HIMoru3UvdICGY6LYDMfu3m5uxAuv3sJ/75XRuU2Ngx 0TFRRgALTLjxGlYdbChIE9zQSqKzreK2+RkeU= MIME-Version: 1.0 Received: by 10.204.34.17 with SMTP id j17mr4878962bkd.188.1265212241862; Wed, 03 Feb 2010 07:50:41 -0800 (PST) From: Vimal Singh Date: Wed, 3 Feb 2010 21:18:46 +0530 Message-ID: Subject: [PATCH v2 1/2] Creating helper func for 'ofs' and 'len' verification for 'nand_erase_nand' To: Linux MTD X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20100203_105049_581383_E110052D X-CRM114-Status: GOOD ( 14.10 ) 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: Artem Bityutskiy 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: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From 288857587cc64c6d223cce6a4f49826ccf9ff0a9 Mon Sep 17 00:00:00 2001 From: Vimal Singh Date: Wed, 3 Feb 2010 14:12:24 +0530 Subject: [PATCH 1/2] Creating helper func for 'ofs' and 'len' verification for 'nand_erase_nand' These checks are expected to be used by 'nand_lock' and 'nand_unlock' routines too. As all these three are block aligned operations. So, creating a helper function for this makes sense. Signed-off-by: Vimal Singh --- drivers/mtd/nand/nand_base.c | 48 ++++++++++++++++++++++++++--------------- 1 files changed, 30 insertions(+), 18 deletions(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 8f2958f..2dfeb4b 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -108,6 +108,35 @@ static int nand_do_write_oob(struct */ DEFINE_LED_TRIGGER(nand_led_trigger); +static int check_offs_len(struct mtd_info *mtd, + loff_t ofs, uint64_t len) +{ + struct nand_chip *chip = mtd->priv; + int ret = 0; + + /* Start address must align on block boundary */ + if (ofs & ((1 << chip->phys_erase_shift) - 1)) { + DEBUG(MTD_DEBUG_LEVEL0, "%s: Unaligned address\n", __func__); + ret = -EINVAL; + } + + /* Length must align on block boundary */ + if (len & ((1 << chip->phys_erase_shift) - 1)) { + DEBUG(MTD_DEBUG_LEVEL0, "%s: Length not block aligned\n", + __func__); + ret = -EINVAL; + } + + /* Do not allow past end of device */ + if (ofs + len > mtd->size) { + DEBUG(MTD_DEBUG_LEVEL0, "%s: Past end of device\n", + __func__); + ret = -EINVAL; + } + + return ret; +} + /** * nand_release_device - [GENERIC] release chip * @mtd: MTD device structure @@ -2293,25 +2322,8 @@ int nand_erase_nand(struct __func__, (unsigned long long)instr->addr, (unsigned long long)instr->len); - /* Start address must align on block boundary */ - if (instr->addr & ((1 << chip->phys_erase_shift) - 1)) { - DEBUG(MTD_DEBUG_LEVEL0, "%s: Unaligned address\n", __func__); - return -EINVAL; - } - - /* Length must align on block boundary */ - if (instr->len & ((1 << chip->phys_erase_shift) - 1)) { - DEBUG(MTD_DEBUG_LEVEL0, "%s: Length not block aligned\n", - __func__); - return -EINVAL; - } - - /* Do not allow erase past end of device */ - if ((instr->len + instr->addr) > mtd->size) { - DEBUG(MTD_DEBUG_LEVEL0, "%s: Erase past end of device\n", - __func__); + if (check_offs_len(mtd, instr->addr, instr->len)) return -EINVAL; - } instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN;