Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 195875
b: refs/heads/master
c: 6fe5a6a
h: refs/heads/master
i:
  195873: e1b74b0
  195871: d1b65b3
v: v3
  • Loading branch information
Vimal Singh authored and David Woodhouse committed Feb 26, 2010
1 parent 27f2ba7 commit 9dc574b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 91f8026603d4443d1b24ee3552c5a58682bbae27
refs/heads/master: 6fe5a6acdc126107e54a6c584536e09ab7dde949
48 changes: 30 additions & 18 deletions trunk/drivers/mtd/nand/nand_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,35 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
*/
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
Expand Down Expand Up @@ -2293,25 +2322,8 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
__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;

Expand Down

0 comments on commit 9dc574b

Please sign in to comment.