From patchwork Wed Jan 13 13:37:43 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: vimal singh X-Patchwork-Id: 42823 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 334741007D2 for ; Thu, 14 Jan 2010 00:40:20 +1100 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NV3QJ-0004l0-KL; Wed, 13 Jan 2010 13:38:11 +0000 Received: from mail-bw0-f212.google.com ([209.85.218.212]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NV3QC-0004eu-Mr for linux-mtd@lists.infradead.org; Wed, 13 Jan 2010 13:38:09 +0000 Received: by bwz4 with SMTP id 4so15534525bwz.2 for ; Wed, 13 Jan 2010 05:38:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:cc:content-type; bh=mypg5/j9v+LJaqAQNEc3wK5vzeHJyG6ew2k5GmStgZs=; b=nF+HVVotr4qcOt1jqdRdRCrUkHFyF2eajn4OlfK8AgHUnYrTJCuzY8xD5hzHEuGHKa dcR2IhL3TubLk/LUquacanefkl42pk07ieqsmOkG5bRDufMn7fQfpavrK1pAqho1Arq8 aT3lkn2DShv4mNtw4DZpHaJyoPGRrtQfDr5xw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=B3whGEcUP7hqHI91zcaez+se8iuDBwSo8fZpmnEzSK7DSStnXJMR31homHrf8zCBjC QLckNKElfUBMP1rsejUl7/8EKmRb5XSiJrCRT9OzuboysDfk7ixJpqWNKHlKOn75qiyg wIOeilFPmCvDIBWfmyUt3tHJOpqzF1nrDxehU= MIME-Version: 1.0 Received: by 10.204.32.6 with SMTP id a6mr4924228bkd.93.1263389883210; Wed, 13 Jan 2010 05:38:03 -0800 (PST) In-Reply-To: References: From: Vimal Singh Date: Wed, 13 Jan 2010 19:07:43 +0530 Message-ID: Subject: Re: [PATCH v2 2/2] Creating helper func for block alignment verfication To: Linux MTD X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20100113_083805_170151_74AA10DF X-CRM114-Status: GOOD ( 22.11 ) 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 On Wed, Jan 13, 2010 at 6:59 PM, Vimal Singh wrote: > From 310f7faa8f319bd9384512f7d5a7f13dcfbeebc8 Mon Sep 17 00:00:00 2001 > From: Vimal Singh > Date: Wed, 13 Jan 2010 18:11:47 +0530 > Subject: [PATCH] Creating helper func for block alignment verfication > > These checks are fairly common in 'nand_erase_nand', 'nand_lock' > and 'nand_unlock' functions. > There is something seriously wrong with me... I posted old patch again. :( I am sorry for this. Below is the correct patch. No more confusion this time. -vimal From 7516e73f22b8822552f28d50bb104d888c5385b3 Mon Sep 17 00:00:00 2001 From: Vimal Singh Date: Wed, 13 Jan 2010 18:11:47 +0530 Subject: [PATCH] Creating helper func for block alignment verfication These checks are fairly common in 'nand_erase_nand', 'nand_lock' and 'nand_unlock' fucntions. Signed-off-by: Vimal Singh --- drivers/mtd/nand/nand_base.c | 98 +++++++++++++++--------------------------- 1 files changed, 35 insertions(+), 63 deletions(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 4e27426..63ee49e 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -108,6 +108,38 @@ static int nand_do_write_oob(struct */ DEFINE_LED_TRIGGER(nand_led_trigger); +static int block_alignment_verification(struct mtd_info *mtd, + loff_t ofs, uint64_t len) +{ + struct nand_chip *chip = mtd->priv; + int ret = 0; + + DEBUG(MTD_DEBUG_LEVEL3, "%s: start = 0x%012llx, len = %llu\n", + __func__, (unsigned long long)ofs, len); + + /* 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 @@ -894,28 +926,8 @@ int nand_unlock(struct mtd_info int chipnr; struct nand_chip *chip = mtd->priv; - /* 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; - goto out; - } - - /* 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; - goto out; - } - - /* 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; + if (block_alignment_verification(mtd, ofs, len)) goto out; - } /* Align to last block address if size addresses end of the device */ if (ofs + len == mtd->size) @@ -968,31 +980,8 @@ int nand_lock(struct mtd_info int chipnr, status, page; struct nand_chip *chip = mtd->priv; - DEBUG(MTD_DEBUG_LEVEL3, "%s: start = 0x%012llx, len = %llu\n", - __func__, (unsigned long long)ofs, len); - - /* 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; - goto out; - } - - /* 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; - goto out; - } - - /* 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; + if (block_alignment_verification(mtd, ofs, len)) goto out; - } nand_get_device(chip, mtd, FL_LOCKING); @@ -2495,25 +2484,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__); + if (block_alignment_verification(mtd, instr->addr, instr->len)) 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__); - return -EINVAL; - } instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN;