diff options
author | Vimal Singh <vimalsingh@ti.com> | 2010-02-03 03:42:24 -0500 |
---|---|---|
committer | David Woodhouse <David.Woodhouse@intel.com> | 2010-02-26 08:21:22 -0500 |
commit | 6fe5a6acdc126107e54a6c584536e09ab7dde949 (patch) | |
tree | c9005ec5e3363bb34c9d64883569963d16b839be | |
parent | 91f8026603d4443d1b24ee3552c5a58682bbae27 (diff) |
mtd: nand: create a helper verification function
... 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 <vimalsingh@ti.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
-rw-r--r-- | 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 8f2958fe2148..2dfeb4bea83a 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 mtd_info *mtd, loff_t to, | |||
108 | */ | 108 | */ |
109 | DEFINE_LED_TRIGGER(nand_led_trigger); | 109 | DEFINE_LED_TRIGGER(nand_led_trigger); |
110 | 110 | ||
111 | static int check_offs_len(struct mtd_info *mtd, | ||
112 | loff_t ofs, uint64_t len) | ||
113 | { | ||
114 | struct nand_chip *chip = mtd->priv; | ||
115 | int ret = 0; | ||
116 | |||
117 | /* Start address must align on block boundary */ | ||
118 | if (ofs & ((1 << chip->phys_erase_shift) - 1)) { | ||
119 | DEBUG(MTD_DEBUG_LEVEL0, "%s: Unaligned address\n", __func__); | ||
120 | ret = -EINVAL; | ||
121 | } | ||
122 | |||
123 | /* Length must align on block boundary */ | ||
124 | if (len & ((1 << chip->phys_erase_shift) - 1)) { | ||
125 | DEBUG(MTD_DEBUG_LEVEL0, "%s: Length not block aligned\n", | ||
126 | __func__); | ||
127 | ret = -EINVAL; | ||
128 | } | ||
129 | |||
130 | /* Do not allow past end of device */ | ||
131 | if (ofs + len > mtd->size) { | ||
132 | DEBUG(MTD_DEBUG_LEVEL0, "%s: Past end of device\n", | ||
133 | __func__); | ||
134 | ret = -EINVAL; | ||
135 | } | ||
136 | |||
137 | return ret; | ||
138 | } | ||
139 | |||
111 | /** | 140 | /** |
112 | * nand_release_device - [GENERIC] release chip | 141 | * nand_release_device - [GENERIC] release chip |
113 | * @mtd: MTD device structure | 142 | * @mtd: MTD device structure |
@@ -2293,25 +2322,8 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, | |||
2293 | __func__, (unsigned long long)instr->addr, | 2322 | __func__, (unsigned long long)instr->addr, |
2294 | (unsigned long long)instr->len); | 2323 | (unsigned long long)instr->len); |
2295 | 2324 | ||
2296 | /* Start address must align on block boundary */ | 2325 | if (check_offs_len(mtd, instr->addr, instr->len)) |
2297 | if (instr->addr & ((1 << chip->phys_erase_shift) - 1)) { | ||
2298 | DEBUG(MTD_DEBUG_LEVEL0, "%s: Unaligned address\n", __func__); | ||
2299 | return -EINVAL; | ||
2300 | } | ||
2301 | |||
2302 | /* Length must align on block boundary */ | ||
2303 | if (instr->len & ((1 << chip->phys_erase_shift) - 1)) { | ||
2304 | DEBUG(MTD_DEBUG_LEVEL0, "%s: Length not block aligned\n", | ||
2305 | __func__); | ||
2306 | return -EINVAL; | ||
2307 | } | ||
2308 | |||
2309 | /* Do not allow erase past end of device */ | ||
2310 | if ((instr->len + instr->addr) > mtd->size) { | ||
2311 | DEBUG(MTD_DEBUG_LEVEL0, "%s: Erase past end of device\n", | ||
2312 | __func__); | ||
2313 | return -EINVAL; | 2326 | return -EINVAL; |
2314 | } | ||
2315 | 2327 | ||
2316 | instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN; | 2328 | instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN; |
2317 | 2329 | ||