From: Vimal Singh <vimal.newwork@gmail.com>
To: Linux MTD <linux-mtd@lists.infradead.org>
Cc: Artem Bityutskiy <dedekind1@gmail.com>
Subject: [PATCH 2/2] Creating helper func for block alignment verfication
Date: Wed, 13 Jan 2010 18:23:59 +0530 [thread overview]
Message-ID: <ce9ab5791001130453md91ad46ld84f9d51ccd96e87@mail.gmail.com> (raw)
>From cde21be80002b49fb8baeb341e8ae5a1a2394cb6 Mon Sep 17 00:00:00 2001
From: Vimal Singh <vimalsingh@ti.com>
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 <vimalsingh@ti.com>
---
drivers/mtd/nand/nand_base.c | 96 ++++++++++++++---------------------------
1 files changed, 33 insertions(+), 63 deletions(-)
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 4e27426..0bd3092 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -108,6 +108,36 @@ 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;
+
+ 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 0;
+}
+
/**
* nand_release_device - [GENERIC] release chip
* @mtd: MTD device structure
@@ -894,28 +924,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;
+ if (block_alignment_verification(mtd, ofs, len))
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;
- goto out;
- }
/* Align to last block address if size addresses end of the device */
if (ofs + len == mtd->size)
@@ -968,31 +978,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;
+ if (block_alignment_verification(mtd, ofs, len))
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;
- goto out;
- }
nand_get_device(chip, mtd, FL_LOCKING);
@@ -2495,25 +2482,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__);
+ if (block_alignment_verification(mtd, instr->addr, instr->len))
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__);
- return -EINVAL;
- }
instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN;
--
1.5.5
next reply other threads:[~2010-01-13 12:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-13 12:53 Vimal Singh [this message]
2010-01-13 13:06 ` [PATCH 2/2] Creating helper func for block alignment verfication Vimal Singh
2010-01-13 13:20 ` Vimal Singh
2010-01-13 13:29 ` [PATCH v2 " Vimal Singh
2010-01-13 13:37 ` Vimal Singh
2010-01-28 14:46 ` Artem Bityutskiy
2010-01-29 4:19 ` Vimal Singh
2010-01-29 4:45 ` Artem Bityutskiy
2010-01-29 5:38 ` Vimal Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ce9ab5791001130453md91ad46ld84f9d51ccd96e87@mail.gmail.com \
--to=vimal.newwork@gmail.com \
--cc=dedekind1@gmail.com \
--cc=linux-mtd@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox