Commit 5def4898 authored by Artem Bityutskiy's avatar Artem Bityutskiy Committed by David Woodhouse

mtd: do not duplicate length and offset checks in drivers

We already verify that offset and length are within the MTD device size
in the MTD API functions. Let's remove the duplicated checks in drivers.
This patch only affects the following API's:

'mtd_erase()'
'mtd_point()'
'mtd_unpoint()'
'mtd_get_unmapped_area()'
'mtd_read()'
'mtd_write()'
'mtd_panic_write()'
'mtd_lock()'
'mtd_unlock()'
'mtd_is_locked()'
'mtd_block_isbad()'
'mtd_block_markbad()'

This patch adds a bit of noise by removing too sparse empty lines, but this is
not too bad.
Signed-off-by: default avatarArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent 8273a0c9
...@@ -1324,7 +1324,7 @@ static int cfi_intelext_point(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -1324,7 +1324,7 @@ static int cfi_intelext_point(struct mtd_info *mtd, loff_t from, size_t len,
int chipnum; int chipnum;
int ret = 0; int ret = 0;
if (!map->virt || (from + len > mtd->size)) if (!map->virt)
return -EINVAL; return -EINVAL;
/* Now lock the chip(s) to POINT state */ /* Now lock the chip(s) to POINT state */
......
...@@ -904,12 +904,6 @@ static int cfi_staa_erase_varsize(struct mtd_info *mtd, ...@@ -904,12 +904,6 @@ static int cfi_staa_erase_varsize(struct mtd_info *mtd,
int i, first; int i, first;
struct mtd_erase_region_info *regions = mtd->eraseregions; struct mtd_erase_region_info *regions = mtd->eraseregions;
if (instr->addr > mtd->size)
return -EINVAL;
if ((instr->len + instr->addr) > mtd->size)
return -EINVAL;
/* Check that both start and end of the requested erase are /* Check that both start and end of the requested erase are
* aligned with the erasesize at the appropriate addresses. * aligned with the erasesize at the appropriate addresses.
*/ */
...@@ -1155,9 +1149,6 @@ static int cfi_staa_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) ...@@ -1155,9 +1149,6 @@ static int cfi_staa_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
if (len & (mtd->erasesize -1)) if (len & (mtd->erasesize -1))
return -EINVAL; return -EINVAL;
if ((len + ofs) > mtd->size)
return -EINVAL;
chipnum = ofs >> cfi->chipshift; chipnum = ofs >> cfi->chipshift;
adr = ofs - (chipnum << cfi->chipshift); adr = ofs - (chipnum << cfi->chipshift);
......
...@@ -173,12 +173,6 @@ int cfi_varsize_frob(struct mtd_info *mtd, varsize_frob_t frob, ...@@ -173,12 +173,6 @@ int cfi_varsize_frob(struct mtd_info *mtd, varsize_frob_t frob,
int i, first; int i, first;
struct mtd_erase_region_info *regions = mtd->eraseregions; struct mtd_erase_region_info *regions = mtd->eraseregions;
if (ofs > mtd->size)
return -EINVAL;
if ((len + ofs) > mtd->size)
return -EINVAL;
/* Check that both start and end of the requested erase are /* Check that both start and end of the requested erase are
* aligned with the erasesize at the appropriate addresses. * aligned with the erasesize at the appropriate addresses.
*/ */
......
...@@ -104,11 +104,6 @@ static int block2mtd_read(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -104,11 +104,6 @@ static int block2mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
int offset = from & (PAGE_SIZE-1); int offset = from & (PAGE_SIZE-1);
int cpylen; int cpylen;
if (from > mtd->size)
return -EINVAL;
if (from + len > mtd->size)
len = mtd->size - from;
if (retlen) if (retlen)
*retlen = 0; *retlen = 0;
...@@ -190,10 +185,6 @@ static int block2mtd_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -190,10 +185,6 @@ static int block2mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
if (!len) if (!len)
return 0; return 0;
if (to >= mtd->size)
return -ENOSPC;
if (to + len > mtd->size)
len = mtd->size - to;
mutex_lock(&dev->write_mutex); mutex_lock(&dev->write_mutex);
err = _block2mtd_write(dev, buf, to, len, retlen); err = _block2mtd_write(dev, buf, to, len, retlen);
......
...@@ -602,10 +602,6 @@ static int doc_read(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -602,10 +602,6 @@ static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
int i, len256 = 0, ret=0; int i, len256 = 0, ret=0;
size_t left = len; size_t left = len;
/* Don't allow read past end of device */
if (from >= this->totlen)
return -EINVAL;
mutex_lock(&this->lock); mutex_lock(&this->lock);
*retlen = 0; *retlen = 0;
...@@ -748,10 +744,6 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -748,10 +744,6 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
size_t left = len; size_t left = len;
int status; int status;
/* Don't allow write past end of device */
if (to >= this->totlen)
return -EINVAL;
mutex_lock(&this->lock); mutex_lock(&this->lock);
*retlen = 0; *retlen = 0;
......
...@@ -383,10 +383,6 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len, ...@@ -383,10 +383,6 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
void __iomem *docptr = this->virtadr; void __iomem *docptr = this->virtadr;
struct Nand *mychip = &this->chips[from >> (this->chipshift)]; struct Nand *mychip = &this->chips[from >> (this->chipshift)];
/* Don't allow read past end of device */
if (from >= this->totlen)
return -EINVAL;
/* Don't allow a single read to cross a 512-byte block boundary */ /* Don't allow a single read to cross a 512-byte block boundary */
if (from + len > ((from | 0x1ff) + 1)) if (from + len > ((from | 0x1ff) + 1))
len = ((from | 0x1ff) + 1) - from; len = ((from | 0x1ff) + 1) - from;
...@@ -494,10 +490,6 @@ static int doc_write (struct mtd_info *mtd, loff_t to, size_t len, ...@@ -494,10 +490,6 @@ static int doc_write (struct mtd_info *mtd, loff_t to, size_t len,
void __iomem *docptr = this->virtadr; void __iomem *docptr = this->virtadr;
struct Nand *mychip = &this->chips[to >> (this->chipshift)]; struct Nand *mychip = &this->chips[to >> (this->chipshift)];
/* Don't allow write past end of device */
if (to >= this->totlen)
return -EINVAL;
#if 0 #if 0
/* Don't allow a single write to cross a 512-byte block boundary */ /* Don't allow a single write to cross a 512-byte block boundary */
if (to + len > ( (to | 0x1ff) + 1)) if (to + len > ( (to | 0x1ff) + 1))
......
...@@ -581,10 +581,6 @@ static int doc_read(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -581,10 +581,6 @@ static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
void __iomem * docptr = this->virtadr; void __iomem * docptr = this->virtadr;
struct Nand *mychip = &this->chips[from >> (this->chipshift)]; struct Nand *mychip = &this->chips[from >> (this->chipshift)];
/* Don't allow read past end of device */
if (from >= this->totlen)
return -EINVAL;
/* Don't allow a single read to cross a 512-byte block boundary */ /* Don't allow a single read to cross a 512-byte block boundary */
if (from + len > ((from | 0x1ff) + 1)) if (from + len > ((from | 0x1ff) + 1))
len = ((from | 0x1ff) + 1) - from; len = ((from | 0x1ff) + 1) - from;
...@@ -700,10 +696,6 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -700,10 +696,6 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
void __iomem * docptr = this->virtadr; void __iomem * docptr = this->virtadr;
struct Nand *mychip = &this->chips[to >> (this->chipshift)]; struct Nand *mychip = &this->chips[to >> (this->chipshift)];
/* Don't allow write past end of device */
if (to >= this->totlen)
return -EINVAL;
/* Don't allow writes which aren't exactly one block (512 bytes) */ /* Don't allow writes which aren't exactly one block (512 bytes) */
if ((to & 0x1ff) || (len != 0x200)) if ((to & 0x1ff) || (len != 0x200))
return -EINVAL; return -EINVAL;
......
...@@ -367,9 +367,6 @@ static int flash_erase (struct mtd_info *mtd,struct erase_info *instr) ...@@ -367,9 +367,6 @@ static int flash_erase (struct mtd_info *mtd,struct erase_info *instr)
printk (KERN_DEBUG "%s(addr = 0x%.8x, len = %d)\n", __func__, instr->addr, instr->len); printk (KERN_DEBUG "%s(addr = 0x%.8x, len = %d)\n", __func__, instr->addr, instr->len);
#endif #endif
/* sanity checks */
if (instr->addr + instr->len > mtd->size) return (-EINVAL);
/* /*
* check that both start and end of the requested erase are * check that both start and end of the requested erase are
* aligned with the erasesize at the appropriate addresses. * aligned with the erasesize at the appropriate addresses.
...@@ -442,7 +439,6 @@ static int flash_read (struct mtd_info *mtd,loff_t from,size_t len,size_t *retle ...@@ -442,7 +439,6 @@ static int flash_read (struct mtd_info *mtd,loff_t from,size_t len,size_t *retle
/* sanity checks */ /* sanity checks */
if (!len) return (0); if (!len) return (0);
if (from + len > mtd->size) return (-EINVAL);
/* we always read len bytes */ /* we always read len bytes */
*retlen = len; *retlen = len;
...@@ -526,7 +522,6 @@ static int flash_write (struct mtd_info *mtd,loff_t to,size_t len,size_t *retlen ...@@ -526,7 +522,6 @@ static int flash_write (struct mtd_info *mtd,loff_t to,size_t len,size_t *retlen
/* sanity checks */ /* sanity checks */
if (!len) return (0); if (!len) return (0);
if (to + len > mtd->size) return (-EINVAL);
/* first, we write a 0xFF.... padded byte until we reach a dword boundary */ /* first, we write a 0xFF.... padded byte until we reach a dword boundary */
if (to & (BUSWIDTH - 1)) if (to & (BUSWIDTH - 1))
......
...@@ -288,9 +288,6 @@ static int m25p80_erase(struct mtd_info *mtd, struct erase_info *instr) ...@@ -288,9 +288,6 @@ static int m25p80_erase(struct mtd_info *mtd, struct erase_info *instr)
__func__, (long long)instr->addr, __func__, (long long)instr->addr,
(long long)instr->len); (long long)instr->len);
/* sanity checks */
if (instr->addr + instr->len > flash->mtd.size)
return -EINVAL;
div_u64_rem(instr->len, mtd->erasesize, &rem); div_u64_rem(instr->len, mtd->erasesize, &rem);
if (rem) if (rem)
return -EINVAL; return -EINVAL;
...@@ -353,9 +350,6 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -353,9 +350,6 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len,
if (!len) if (!len)
return 0; return 0;
if (from + len > flash->mtd.size)
return -EINVAL;
spi_message_init(&m); spi_message_init(&m);
memset(t, 0, (sizeof t)); memset(t, 0, (sizeof t));
...@@ -423,9 +417,6 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -423,9 +417,6 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
if (!len) if (!len)
return(0); return(0);
if (to + len > flash->mtd.size)
return -EINVAL;
spi_message_init(&m); spi_message_init(&m);
memset(t, 0, (sizeof t)); memset(t, 0, (sizeof t));
...@@ -515,9 +506,6 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -515,9 +506,6 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
if (!len) if (!len)
return 0; return 0;
if (to + len > flash->mtd.size)
return -EINVAL;
spi_message_init(&m); spi_message_init(&m);
memset(t, 0, (sizeof t)); memset(t, 0, (sizeof t));
......
...@@ -59,12 +59,8 @@ static int ms02nv_read(struct mtd_info *mtd, loff_t from, ...@@ -59,12 +59,8 @@ static int ms02nv_read(struct mtd_info *mtd, loff_t from,
{ {
struct ms02nv_private *mp = mtd->priv; struct ms02nv_private *mp = mtd->priv;
if (from + len > mtd->size)
return -EINVAL;
memcpy(buf, mp->uaddr + from, len); memcpy(buf, mp->uaddr + from, len);
*retlen = len; *retlen = len;
return 0; return 0;
} }
...@@ -73,12 +69,8 @@ static int ms02nv_write(struct mtd_info *mtd, loff_t to, ...@@ -73,12 +69,8 @@ static int ms02nv_write(struct mtd_info *mtd, loff_t to,
{ {
struct ms02nv_private *mp = mtd->priv; struct ms02nv_private *mp = mtd->priv;
if (to + len > mtd->size)
return -EINVAL;
memcpy(mp->uaddr + to, buf, len); memcpy(mp->uaddr + to, buf, len);
*retlen = len; *retlen = len;
return 0; return 0;
} }
......
...@@ -164,9 +164,6 @@ static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr) ...@@ -164,9 +164,6 @@ static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr)
dev_name(&spi->dev), (long long)instr->addr, dev_name(&spi->dev), (long long)instr->addr,
(long long)instr->len); (long long)instr->len);
/* Sanity checks */
if (instr->addr + instr->len > mtd->size)
return -EINVAL;
div_u64_rem(instr->len, priv->page_size, &rem); div_u64_rem(instr->len, priv->page_size, &rem);
if (rem) if (rem)
return -EINVAL; return -EINVAL;
...@@ -257,8 +254,6 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -257,8 +254,6 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len,
/* Sanity checks */ /* Sanity checks */
if (!len) if (!len)
return 0; return 0;
if (from + len > mtd->size)
return -EINVAL;
/* Calculate flash page/byte address */ /* Calculate flash page/byte address */
addr = (((unsigned)from / priv->page_size) << priv->page_offset) addr = (((unsigned)from / priv->page_size) << priv->page_offset)
...@@ -333,8 +328,6 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -333,8 +328,6 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
/* Sanity checks */ /* Sanity checks */
if (!len) if (!len)
return 0; return 0;
if ((to + len) > mtd->size)
return -EINVAL;
spi_message_init(&msg); spi_message_init(&msg);
......
...@@ -34,27 +34,18 @@ static struct mtd_info *mtd_info; ...@@ -34,27 +34,18 @@ static struct mtd_info *mtd_info;
static int ram_erase(struct mtd_info *mtd, struct erase_info *instr) static int ram_erase(struct mtd_info *mtd, struct erase_info *instr)
{ {
if (instr->addr + instr->len > mtd->size)
return -EINVAL;
memset((char *)mtd->priv + instr->addr, 0xff, instr->len); memset((char *)mtd->priv + instr->addr, 0xff, instr->len);
instr->state = MTD_ERASE_DONE; instr->state = MTD_ERASE_DONE;
mtd_erase_callback(instr); mtd_erase_callback(instr);
return 0; return 0;
} }
static int ram_point(struct mtd_info *mtd, loff_t from, size_t len, static int ram_point(struct mtd_info *mtd, loff_t from, size_t len,
size_t *retlen, void **virt, resource_size_t *phys) size_t *retlen, void **virt, resource_size_t *phys)
{ {
if (from + len > mtd->size)
return -EINVAL;
/* can we return a physical address with this driver? */ /* can we return a physical address with this driver? */
if (phys) if (phys)
return -EINVAL; return -EINVAL;
*virt = mtd->priv + from; *virt = mtd->priv + from;
*retlen = len; *retlen = len;
return 0; return 0;
...@@ -81,11 +72,7 @@ static unsigned long ram_get_unmapped_area(struct mtd_info *mtd, ...@@ -81,11 +72,7 @@ static unsigned long ram_get_unmapped_area(struct mtd_info *mtd,
static int ram_read(struct mtd_info *mtd, loff_t from, size_t len, static int ram_read(struct mtd_info *mtd, loff_t from, size_t len,
size_t *retlen, u_char *buf) size_t *retlen, u_char *buf)
{ {
if (from + len > mtd->size)
return -EINVAL;
memcpy(buf, mtd->priv + from, len); memcpy(buf, mtd->priv + from, len);
*retlen = len; *retlen = len;
return 0; return 0;
} }
...@@ -93,11 +80,7 @@ static int ram_read(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -93,11 +80,7 @@ static int ram_read(struct mtd_info *mtd, loff_t from, size_t len,
static int ram_write(struct mtd_info *mtd, loff_t to, size_t len, static int ram_write(struct mtd_info *mtd, loff_t to, size_t len,
size_t *retlen, const u_char *buf) size_t *retlen, const u_char *buf)
{ {
if (to + len > mtd->size)
return -EINVAL;
memcpy((char *)mtd->priv + to, buf, len); memcpy((char *)mtd->priv + to, buf, len);
*retlen = len; *retlen = len;
return 0; return 0;
} }
......
...@@ -38,29 +38,20 @@ static int phram_erase(struct mtd_info *mtd, struct erase_info *instr) ...@@ -38,29 +38,20 @@ static int phram_erase(struct mtd_info *mtd, struct erase_info *instr)
{ {
u_char *start = mtd->priv; u_char *start = mtd->priv;
if (instr->addr + instr->len > mtd->size)
return -EINVAL;
memset(start + instr->addr, 0xff, instr->len); memset(start + instr->addr, 0xff, instr->len);
/* This'll catch a few races. Free the thing before returning :) /* This'll catch a few races. Free the thing before returning :)
* I don't feel at all ashamed. This kind of thing is possible anyway * I don't feel at all ashamed. This kind of thing is possible anyway
* with flash, but unlikely. * with flash, but unlikely.
*/ */
instr->state = MTD_ERASE_DONE; instr->state = MTD_ERASE_DONE;
mtd_erase_callback(instr); mtd_erase_callback(instr);
return 0; return 0;
} }
static int phram_point(struct mtd_info *mtd, loff_t from, size_t len, static int phram_point(struct mtd_info *mtd, loff_t from, size_t len,
size_t *retlen, void **virt, resource_size_t *phys) size_t *retlen, void **virt, resource_size_t *phys)
{ {
if (from + len > mtd->size)
return -EINVAL;
/* can we return a physical address with this driver? */ /* can we return a physical address with this driver? */
if (phys) if (phys)
return -EINVAL; return -EINVAL;
...@@ -80,14 +71,7 @@ static int phram_read(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -80,14 +71,7 @@ static int phram_read(struct mtd_info *mtd, loff_t from, size_t len,
{ {
u_char *start = mtd->priv; u_char *start = mtd->priv;
if (from >= mtd->size)
return -EINVAL;
if (len > mtd->size - from)
len = mtd->size - from;
memcpy(buf, start + from, len); memcpy(buf, start + from, len);
*retlen = len; *retlen = len;
return 0; return 0;
} }
...@@ -97,14 +81,7 @@ static int phram_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -97,14 +81,7 @@ static int phram_write(struct mtd_info *mtd, loff_t to, size_t len,
{ {
u_char *start = mtd->priv; u_char *start = mtd->priv;
if (to >= mtd->size)
return -EINVAL;
if (len > mtd->size - to)
len = mtd->size - to;
memcpy(start + to, buf, len); memcpy(start + to, buf, len);
*retlen = len; *retlen = len;
return 0; return 0;
} }
......
...@@ -116,16 +116,6 @@ static int pmc551_erase(struct mtd_info *mtd, struct erase_info *instr) ...@@ -116,16 +116,6 @@ static int pmc551_erase(struct mtd_info *mtd, struct erase_info *instr)
#endif #endif
end = instr->addr + instr->len - 1; end = instr->addr + instr->len - 1;
/* Is it past the end? */
if (end > mtd->size) {
#ifdef CONFIG_MTD_PMC551_DEBUG
printk(KERN_DEBUG "pmc551_erase() out of bounds (%ld > %ld)\n",
(long)end, (long)mtd->size);
#endif
return -EINVAL;
}
eoff_hi = end & ~(priv->asize - 1); eoff_hi = end & ~(priv->asize - 1);
soff_hi = instr->addr & ~(priv->asize - 1); soff_hi = instr->addr & ~(priv->asize - 1);
eoff_lo = end & (priv->asize - 1); eoff_lo = end & (priv->asize - 1);
...@@ -179,14 +169,6 @@ static int pmc551_point(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -179,14 +169,6 @@ static int pmc551_point(struct mtd_info *mtd, loff_t from, size_t len,
printk(KERN_DEBUG "pmc551_point(%ld, %ld)\n", (long)from, (long)len); printk(KERN_DEBUG "pmc551_point(%ld, %ld)\n", (long)from, (long)len);
#endif #endif
if (from + len > mtd->size) {
#ifdef CONFIG_MTD_PMC551_DEBUG
printk(KERN_DEBUG "pmc551_point() out of bounds (%ld > %ld)\n",
(long)from + len, (long)mtd->size);
#endif
return -EINVAL;
}
/* can we return a physical address with this driver? */ /* can we return a physical address with this driver? */
if (phys) if (phys)
return -EINVAL; return -EINVAL;
...@@ -230,16 +212,6 @@ static int pmc551_read(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -230,16 +212,6 @@ static int pmc551_read(struct mtd_info *mtd, loff_t from, size_t len,
#endif #endif
end = from + len - 1; end = from + len - 1;
/* Is it past the end? */
if (end > mtd->size) {
#ifdef CONFIG_MTD_PMC551_DEBUG
printk(KERN_DEBUG "pmc551_read() out of bounds (%ld > %ld)\n",
(long)end, (long)mtd->size);
#endif
return -EINVAL;
}
soff_hi = from & ~(priv->asize - 1); soff_hi = from & ~(priv->asize - 1);
eoff_hi = end & ~(priv->asize - 1); eoff_hi = end & ~(priv->asize - 1);
soff_lo = from & (priv->asize - 1); soff_lo = from & (priv->asize - 1);
...@@ -297,16 +269,6 @@ static int pmc551_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -297,16 +269,6 @@ static int pmc551_write(struct mtd_info *mtd, loff_t to, size_t len,
#endif #endif
end = to + len - 1; end = to + len - 1;
/* Is it past the end? or did the u32 wrap? */
if (end > mtd->size) {
#ifdef CONFIG_MTD_PMC551_DEBUG
printk(KERN_DEBUG "pmc551_write() out of bounds (end: %ld, "
"size: %ld, to: %ld)\n", (long)end, (long)mtd->size,
(long)to);
#endif
return -EINVAL;
}
soff_hi = to & ~(priv->asize - 1); soff_hi = to & ~(priv->asize - 1);
eoff_hi = end & ~(priv->asize - 1); eoff_hi = end & ~(priv->asize - 1);
soff_lo = to & (priv->asize - 1); soff_lo = to & (priv->asize - 1);
......
...@@ -84,21 +84,13 @@ static int slram_erase(struct mtd_info *mtd, struct erase_info *instr) ...@@ -84,21 +84,13 @@ static int slram_erase(struct mtd_info *mtd, struct erase_info *instr)
{ {
slram_priv_t *priv = mtd->priv; slram_priv_t *priv = mtd->priv;
if (instr->addr + instr->len > mtd->size) {
return(-EINVAL);
}
memset(priv->start + instr->addr, 0xff, instr->len); memset(priv->start + instr->addr, 0xff, instr->len);
/* This'll catch a few races. Free the thing before returning :) /* This'll catch a few races. Free the thing before returning :)
* I don't feel at all ashamed. This kind of thing is possible anyway * I don't feel at all ashamed. This kind of thing is possible anyway
* with flash, but unlikely. * with flash, but unlikely.
*/ */
instr->state = MTD_ERASE_DONE; instr->state = MTD_ERASE_DONE;
mtd_erase_callback(instr); mtd_erase_callback(instr);
return(0); return(0);
} }
...@@ -110,10 +102,6 @@ static int slram_point(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -110,10 +102,6 @@ static int slram_point(struct mtd_info *mtd, loff_t from, size_t len,
/* can we return a physical address with this driver? */ /* can we return a physical address with this driver? */
if (phys) if (phys)
return -EINVAL; return -EINVAL;
if (from + len > mtd->size)
return -EINVAL;
*virt = priv->start + from; *virt = priv->start + from;
*retlen = len; *retlen = len;
return(0); return(0);
...@@ -129,14 +117,7 @@ static int slram_read(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -129,14 +117,7 @@ static int slram_read(struct mtd_info *mtd, loff_t from, size_t len,
{ {
slram_priv_t *priv = mtd->priv; slram_priv_t *priv = mtd->priv;
if (from > mtd->size)
return -EINVAL;
if (from + len > mtd->size)
len = mtd->size - from;
memcpy(buf, priv->start + from, len); memcpy(buf, priv->start + from, len);
*retlen = len; *retlen = len;
return(0); return(0);
} }
...@@ -146,11 +127,7 @@ static int slram_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -146,11 +127,7 @@ static int slram_write(struct mtd_info *mtd, loff_t to, size_t len,
{ {
slram_priv_t *priv = mtd->priv; slram_priv_t *priv = mtd->priv;
if (to + len > mtd->size)
return -EINVAL;
memcpy(priv->start + to, buf, len); memcpy(priv->start + to, buf, len);
*retlen = len; *retlen = len;
return(0); return(0);
} }
......
...@@ -510,10 +510,6 @@ static int spear_mtd_erase(struct mtd_info *mtd, struct erase_info *e_info) ...@@ -510,10 +510,6 @@ static int spear_mtd_erase(struct mtd_info *mtd, struct erase_info *e_info)
if (!flash || !dev) if (!flash || !dev)
return -ENODEV; return -ENODEV;
/* do not allow erase past end of device */
if (e_info->addr + e_info->len > flash->mtd.size)
return -EINVAL;
bank = flash->bank; bank = flash->bank;
if (bank > dev->num_flashes - 1) { if (bank > dev->num_flashes - 1) {
dev_err(&dev->pdev->dev, "Invalid Bank Num"); dev_err(&dev->pdev->dev, "Invalid Bank Num");
...@@ -573,10 +569,6 @@ static int spear_mtd_read(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -573,10 +569,6 @@ static int spear_mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
if (!flash || !dev) if (!flash || !dev)
return -ENODEV; return -ENODEV;
/* do not allow reads past end of device */
if (from + len > flash->mtd.size)
return -EINVAL;
if (flash->bank > dev->num_flashes - 1) { if (flash->bank > dev->num_flashes - 1) {
dev_err(&dev->pdev->dev, "Invalid Bank Num"); dev_err(&dev->pdev->dev, "Invalid Bank Num");
return -EINVAL; return -EINVAL;
...@@ -678,10 +670,6 @@ static int spear_mtd_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -678,10 +670,6 @@ static int spear_mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
if (!len) if (!len)
return 0; return 0;
/* do not allow write past end of page */
if (to + len > flash->mtd.size)
return -EINVAL;
if (flash->bank > dev->num_flashes - 1) { if (flash->bank > dev->num_flashes - 1) {
dev_err(&dev->pdev->dev, "Invalid Bank Num"); dev_err(&dev->pdev->dev, "Invalid Bank Num");
return -EINVAL; return -EINVAL;
......
...@@ -175,9 +175,6 @@ static int sst25l_erase(struct mtd_info *mtd, struct erase_info *instr) ...@@ -175,9 +175,6 @@ static int sst25l_erase(struct mtd_info *mtd, struct erase_info *instr)
int err; int err;
/* Sanity checks */ /* Sanity checks */
if (instr->addr + instr->len > flash->mtd.size)
return -EINVAL;
if ((uint32_t)instr->len % mtd->erasesize) if ((uint32_t)instr->len % mtd->erasesize)
return -EINVAL; return -EINVAL;
...@@ -227,9 +224,6 @@ static int sst25l_read(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -227,9 +224,6 @@ static int sst25l_read(struct mtd_info *mtd, loff_t from, size_t len,
if (len == 0) if (len == 0)
return 0; return 0;
if (from + len > flash->mtd.size)
return -EINVAL;
if (retlen) if (retlen)
*retlen = 0; *retlen = 0;
...@@ -278,9 +272,6 @@ static int sst25l_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -278,9 +272,6 @@ static int sst25l_write(struct mtd_info *mtd, loff_t to, size_t len,
if (!len) if (!len)
return 0; return 0;
if (to + len > flash->mtd.size)
return -EINVAL;
if ((uint32_t)to % mtd->writesize) if ((uint32_t)to % mtd->writesize)
return -EINVAL; return -EINVAL;
......
...@@ -530,7 +530,7 @@ static int lpddr_point(struct mtd_info *mtd, loff_t adr, size_t len, ...@@ -530,7 +530,7 @@ static int lpddr_point(struct mtd_info *mtd, loff_t adr, size_t len,
struct flchip *chip = &lpddr->chips[chipnum]; struct flchip *chip = &lpddr->chips[chipnum];
int ret = 0; int ret = 0;
if (!map->virt || (adr + len > mtd->size)) if (!map->virt)
return -EINVAL; return -EINVAL;
/* ofs: offset within the first chip that the first read should start */ /* ofs: offset within the first chip that the first read should start */
...@@ -692,9 +692,6 @@ static int lpddr_erase(struct mtd_info *mtd, struct erase_info *instr) ...@@ -692,9 +692,6 @@ static int lpddr_erase(struct mtd_info *mtd, struct erase_info *instr)
ofs = instr->addr; ofs = instr->addr;
len = instr->len; len = instr->len;
if (ofs > mtd->size || (len + ofs) > mtd->size)
return -EINVAL;
while (len > 0) { while (len > 0) {
ret = do_erase_oneblock(mtd, ofs); ret = do_erase_oneblock(mtd, ofs);
if (ret) if (ret)
......
...@@ -185,10 +185,6 @@ concat_writev(struct mtd_info *mtd, const struct kvec *vecs, ...@@ -185,10 +185,6 @@ concat_writev(struct mtd_info *mtd, const struct kvec *vecs,
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
total_len += vecs[i].iov_len; total_len += vecs[i].iov_len;
/* Do not allow write past end of device */
if ((to + total_len) > mtd->size)
return -EINVAL;
/* Check alignment */ /* Check alignment */
if (mtd->writesize > 1) { if (mtd->writesize > 1) {
uint64_t __to = to; uint64_t __to = to;
...@@ -406,12 +402,6 @@ static int concat_erase(struct mtd_info *mtd, struct erase_info *instr) ...@@ -406,12 +402,6 @@ static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
if (!(mtd->flags & MTD_WRITEABLE)) if (!(mtd->flags & MTD_WRITEABLE))
return -EROFS; return -EROFS;
if (instr->addr > concat->mtd.size)
return -EINVAL;
if (instr->len + instr->addr > concat->mtd.size)
return -EINVAL;
/* /*
* Check for proper erase block alignment of the to-be-erased area. * Check for proper erase block alignment of the to-be-erased area.
* It is easier to do this based on the super device's erase * It is easier to do this based on the super device's erase
...@@ -538,9 +528,6 @@ static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) ...@@ -538,9 +528,6 @@ static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
struct mtd_concat *concat = CONCAT(mtd); struct mtd_concat *concat = CONCAT(mtd);
int i, err = -EINVAL; int i, err = -EINVAL;
if ((len + ofs) > mtd->size)
return -EINVAL;
for (i = 0; i < concat->num_subdev; i++) { for (i = 0; i < concat->num_subdev; i++) {
struct mtd_info *subdev = concat->subdev[i]; struct mtd_info *subdev = concat->subdev[i];
uint64_t size; uint64_t size;
...@@ -575,9 +562,6 @@ static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) ...@@ -575,9 +562,6 @@ static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
struct mtd_concat *concat = CONCAT(mtd); struct mtd_concat *concat = CONCAT(mtd);
int i, err = 0; int i, err = 0;
if ((len + ofs) > mtd->size)
return -EINVAL;
for (i = 0; i < concat->num_subdev; i++) { for (i = 0; i < concat->num_subdev; i++) {
struct mtd_info *subdev = concat->subdev[i]; struct mtd_info *subdev = concat->subdev[i];
uint64_t size; uint64_t size;
...@@ -650,9 +634,6 @@ static int concat_block_isbad(struct mtd_info *mtd, loff_t ofs) ...@@ -650,9 +634,6 @@ static int concat_block_isbad(struct mtd_info *mtd, loff_t ofs)
if (!mtd_can_have_bb(concat->subdev[0])) if (!mtd_can_have_bb(concat->subdev[0]))
return res; return res;
if (ofs > mtd->size)
return -EINVAL;
for (i = 0; i < concat->num_subdev; i++) { for (i = 0; i < concat->num_subdev; i++) {
struct mtd_info *subdev = concat->subdev[i]; struct mtd_info *subdev = concat->subdev[i];
...@@ -673,9 +654,6 @@ static int concat_block_markbad(struct mtd_info *mtd, loff_t ofs) ...@@ -673,9 +654,6 @@ static int concat_block_markbad(struct mtd_info *mtd, loff_t ofs)
struct mtd_concat *concat = CONCAT(mtd); struct mtd_concat *concat = CONCAT(mtd);
int i, err = -EINVAL; int i, err = -EINVAL;
if (ofs > mtd->size)
return -EINVAL;
for (i = 0; i < concat->num_subdev; i++) { for (i = 0; i < concat->num_subdev; i++) {
struct mtd_info *subdev = concat->subdev[i]; struct mtd_info *subdev = concat->subdev[i];
...@@ -713,10 +691,6 @@ static unsigned long concat_get_unmapped_area(struct mtd_info *mtd, ...@@ -713,10 +691,6 @@ static unsigned long concat_get_unmapped_area(struct mtd_info *mtd,
continue; continue;
} }
/* we've found the subdev over which the mapping will reside */
if (offset + len > subdev->size)
return (unsigned long) -EINVAL;
return mtd_get_unmapped_area(subdev, len, offset, flags); return mtd_get_unmapped_area(subdev, len, offset, flags);
} }
......
...@@ -65,11 +65,6 @@ static int part_read(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -65,11 +65,6 @@ static int part_read(struct mtd_info *mtd, loff_t from, size_t len,
int res; int res;
stats = part->master->ecc_stats; stats = part->master->ecc_stats;
if (from >= mtd->size)
len = 0;
else if (from + len > mtd->size)
len = mtd->size - from;
res = mtd_read(part->master, from + part->offset, len, retlen, buf); res = mtd_read(part->master, from + part->offset, len, retlen, buf);
if (unlikely(res)) { if (unlikely(res)) {
if (mtd_is_bitflip(res)) if (mtd_is_bitflip(res))
...@@ -84,10 +79,7 @@ static int part_point(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -84,10 +79,7 @@ static int part_point(struct mtd_info *mtd, loff_t from, size_t len,
size_t *retlen, void **virt, resource_size_t *phys) size_t *retlen, void **virt, resource_size_t *phys)
{ {
struct mtd_part *part = PART(mtd); struct mtd_part *part = PART(mtd);
if (from >= mtd->size)
len = 0;
else if (from + len > mtd->size)
len = mtd->size - from;
return mtd_point(part->master, from + part->offset, len, retlen, return mtd_point(part->master, from + part->offset, len, retlen,
virt, phys); virt, phys);
} }
...@@ -182,10 +174,6 @@ static int part_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -182,10 +174,6 @@ static int part_write(struct mtd_info *mtd, loff_t to, size_t len,
struct mtd_part *part = PART(mtd); struct mtd_part *part = PART(mtd);
if (!(mtd->flags & MTD_WRITEABLE)) if (!(mtd->flags & MTD_WRITEABLE))
return -EROFS; return -EROFS;
if (to >= mtd->size)
len = 0;
else if (to + len > mtd->size)
len = mtd->size - to;
return mtd_write(part->master, to + part->offset, len, retlen, buf); return mtd_write(part->master, to + part->offset, len, retlen, buf);
} }
...@@ -195,10 +183,6 @@ static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -195,10 +183,6 @@ static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
struct mtd_part *part = PART(mtd); struct mtd_part *part = PART(mtd);
if (!(mtd->flags & MTD_WRITEABLE)) if (!(mtd->flags & MTD_WRITEABLE))
return -EROFS; return -EROFS;
if (to >= mtd->size)
len = 0;
else if (to + len > mtd->size)
len = mtd->size - to;
return mtd_panic_write(part->master, to + part->offset, len, retlen, return mtd_panic_write(part->master, to + part->offset, len, retlen,
buf); buf);
} }
...@@ -248,8 +232,6 @@ static int part_erase(struct mtd_info *mtd, struct erase_info *instr) ...@@ -248,8 +232,6 @@ static int part_erase(struct mtd_info *mtd, struct erase_info *instr)
int ret; int ret;
if (!(mtd->flags & MTD_WRITEABLE)) if (!(mtd->flags & MTD_WRITEABLE))
return -EROFS; return -EROFS;
if (instr->addr >= mtd->size)
return -EINVAL;
instr->addr += part->offset; instr->addr += part->offset;
ret = mtd_erase(part->master, instr); ret = mtd_erase(part->master, instr);
if (ret) { if (ret) {
...@@ -277,24 +259,18 @@ EXPORT_SYMBOL_GPL(mtd_erase_callback); ...@@ -277,24 +259,18 @@ EXPORT_SYMBOL_GPL(mtd_erase_callback);
static int part_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) static int part_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
{ {
struct mtd_part *part = PART(mtd); struct mtd_part *part = PART(mtd);
if ((len + ofs) > mtd->size)
return -EINVAL;
return mtd_lock(part->master, ofs + part->offset, len); return mtd_lock(part->master, ofs + part->offset, len);
} }
static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
{ {
struct mtd_part *part = PART(mtd); struct mtd_part *part = PART(mtd);
if ((len + ofs) > mtd->size)
return -EINVAL;
return mtd_unlock(part->master, ofs + part->offset, len); return mtd_unlock(part->master, ofs + part->offset, len);
} }
static int part_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len) static int part_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
{ {
struct mtd_part *part = PART(mtd); struct mtd_part *part = PART(mtd);
if ((len + ofs) > mtd->size)
return -EINVAL;
return mtd_is_locked(part->master, ofs + part->offset, len); return mtd_is_locked(part->master, ofs + part->offset, len);
} }
...@@ -319,8 +295,6 @@ static void part_resume(struct mtd_info *mtd) ...@@ -319,8 +295,6 @@ static void part_resume(struct mtd_info *mtd)
static int part_block_isbad(struct mtd_info *mtd, loff_t ofs) static int part_block_isbad(struct mtd_info *mtd, loff_t ofs)
{ {
struct mtd_part *part = PART(mtd); struct mtd_part *part = PART(mtd);
if (ofs >= mtd->size)
return -EINVAL;
ofs += part->offset; ofs += part->offset;
return mtd_block_isbad(part->master, ofs); return mtd_block_isbad(part->master, ofs);
} }
...@@ -332,8 +306,6 @@ static int part_block_markbad(struct mtd_info *mtd, loff_t ofs) ...@@ -332,8 +306,6 @@ static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)
if (!(mtd->flags & MTD_WRITEABLE)) if (!(mtd->flags & MTD_WRITEABLE))
return -EROFS; return -EROFS;
if (ofs >= mtd->size)
return -EINVAL;
ofs += part->offset; ofs += part->offset;
res = mtd_block_markbad(part->master, ofs); res = mtd_block_markbad(part->master, ofs);
if (!res) if (!res)
......
...@@ -123,12 +123,6 @@ static int check_offs_len(struct mtd_info *mtd, ...@@ -123,12 +123,6 @@ static int check_offs_len(struct mtd_info *mtd,
ret = -EINVAL; ret = -EINVAL;
} }
/* Do not allow past end of device */
if (ofs + len > mtd->size) {
pr_debug("%s: past end of device\n", __func__);
ret = -EINVAL;
}
return ret; return ret;
} }
...@@ -1620,25 +1614,17 @@ static int nand_read(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -1620,25 +1614,17 @@ static int nand_read(struct mtd_info *mtd, loff_t from, size_t len,
struct mtd_oob_ops ops; struct mtd_oob_ops ops;
int ret; int ret;
/* Do not allow reads past end of device */
if ((from + len) > mtd->size)
return -EINVAL;
if (!len) if (!len)
return 0; return 0;
nand_get_device(chip, mtd, FL_READING); nand_get_device(chip, mtd, FL_READING);
ops.len = len; ops.len = len;
ops.datbuf = buf; ops.datbuf = buf;
ops.oobbuf = NULL; ops.oobbuf = NULL;
ops.mode = 0; ops.mode = 0;
ret = nand_do_read_ops(mtd, from, &ops); ret = nand_do_read_ops(mtd, from, &ops);
*retlen = ops.retlen; *retlen = ops.retlen;
nand_release_device(mtd); nand_release_device(mtd);
return ret; return ret;
} }
...@@ -2328,8 +2314,6 @@ static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -2328,8 +2314,6 @@ static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len,
int ret; int ret;
/* Do not allow reads past end of device */ /* Do not allow reads past end of device */
if ((to + len) > mtd->size)
return -EINVAL;
if (!len) if (!len)
return 0; return 0;
...@@ -2367,25 +2351,17 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -2367,25 +2351,17 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,
struct mtd_oob_ops ops; struct mtd_oob_ops ops;
int ret; int ret;
/* Do not allow reads past end of device */
if ((to + len) > mtd->size)
return -EINVAL;
if (!len) if (!len)
return 0; return 0;
nand_get_device(chip, mtd, FL_WRITING); nand_get_device(chip, mtd, FL_WRITING);
ops.len = len; ops.len = len;
ops.datbuf = (uint8_t *)buf; ops.datbuf = (uint8_t *)buf;
ops.oobbuf = NULL; ops.oobbuf = NULL;
ops.mode = 0; ops.mode = 0;
ret = nand_do_write_ops(mtd, to, &ops); ret = nand_do_write_ops(mtd, to, &ops);
*retlen = ops.retlen; *retlen = ops.retlen;
nand_release_device(mtd); nand_release_device(mtd);
return ret; return ret;
} }
...@@ -2749,10 +2725,6 @@ static void nand_sync(struct mtd_info *mtd) ...@@ -2749,10 +2725,6 @@ static void nand_sync(struct mtd_info *mtd)
*/ */
static int nand_block_isbad(struct mtd_info *mtd, loff_t offs) static int nand_block_isbad(struct mtd_info *mtd, loff_t offs)
{ {
/* Check for invalid offset */
if (offs > mtd->size)
return -EINVAL;
return nand_block_checkbad(mtd, offs, 1, 0); return nand_block_checkbad(mtd, offs, 1, 0);
} }
......
...@@ -1756,13 +1756,6 @@ static int onenand_panic_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -1756,13 +1756,6 @@ static int onenand_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
/* Initialize retlen, in case of early exit */ /* Initialize retlen, in case of early exit */
*retlen = 0; *retlen = 0;
/* Do not allow writes past end of device */
if (unlikely((to + len) > mtd->size)) {
printk(KERN_ERR "%s: Attempt write to past end of device\n",
__func__);
return -EINVAL;
}
/* Reject writes, which are not page aligned */ /* Reject writes, which are not page aligned */
if (unlikely(NOTALIGNED(to) || NOTALIGNED(len))) { if (unlikely(NOTALIGNED(to) || NOTALIGNED(len))) {
printk(KERN_ERR "%s: Attempt to write not page aligned data\n", printk(KERN_ERR "%s: Attempt to write not page aligned data\n",
...@@ -1890,13 +1883,6 @@ static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to, ...@@ -1890,13 +1883,6 @@ static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to,
ops->retlen = 0; ops->retlen = 0;
ops->oobretlen = 0; ops->oobretlen = 0;
/* Do not allow writes past end of device */
if (unlikely((to + len) > mtd->size)) {
printk(KERN_ERR "%s: Attempt write to past end of device\n",
__func__);
return -EINVAL;
}
/* Reject writes, which are not page aligned */ /* Reject writes, which are not page aligned */
if (unlikely(NOTALIGNED(to) || NOTALIGNED(len))) { if (unlikely(NOTALIGNED(to) || NOTALIGNED(len))) {
printk(KERN_ERR "%s: Attempt to write not page aligned data\n", printk(KERN_ERR "%s: Attempt to write not page aligned data\n",
...@@ -2493,12 +2479,6 @@ static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr) ...@@ -2493,12 +2479,6 @@ static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr)
(unsigned long long)instr->addr, (unsigned long long)instr->addr,
(unsigned long long)instr->len); (unsigned long long)instr->len);
/* Do not allow erase past end of device */
if (unlikely((len + addr) > mtd->size)) {
printk(KERN_ERR "%s: Erase past end of device\n", __func__);
return -EINVAL;
}
if (FLEXONENAND(this)) { if (FLEXONENAND(this)) {
/* Find the eraseregion of this address */ /* Find the eraseregion of this address */
int i = flexonenand_region(mtd, addr); int i = flexonenand_region(mtd, addr);
......
...@@ -174,11 +174,7 @@ static int gluebi_read(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -174,11 +174,7 @@ static int gluebi_read(struct mtd_info *mtd, loff_t from, size_t len,
int err = 0, lnum, offs, total_read; int err = 0, lnum, offs, total_read;
struct gluebi_device *gluebi; struct gluebi_device *gluebi;
if (len < 0 || from < 0 || from + len > mtd->size)
return -EINVAL;
gluebi = container_of(mtd, struct gluebi_device, mtd); gluebi = container_of(mtd, struct gluebi_device, mtd);
lnum = div_u64_rem(from, mtd->erasesize, &offs); lnum = div_u64_rem(from, mtd->erasesize, &offs);
total_read = len; total_read = len;
while (total_read) { while (total_read) {
...@@ -218,9 +214,6 @@ static int gluebi_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -218,9 +214,6 @@ static int gluebi_write(struct mtd_info *mtd, loff_t to, size_t len,
int err = 0, lnum, offs, total_written; int err = 0, lnum, offs, total_written;
struct gluebi_device *gluebi; struct gluebi_device *gluebi;
if (len < 0 || to < 0 || len + to > mtd->size)
return -EINVAL;
gluebi = container_of(mtd, struct gluebi_device, mtd); gluebi = container_of(mtd, struct gluebi_device, mtd);
if (!(mtd->flags & MTD_WRITEABLE)) if (!(mtd->flags & MTD_WRITEABLE))
...@@ -265,10 +258,6 @@ static int gluebi_erase(struct mtd_info *mtd, struct erase_info *instr) ...@@ -265,10 +258,6 @@ static int gluebi_erase(struct mtd_info *mtd, struct erase_info *instr)
int err, i, lnum, count; int err, i, lnum, count;
struct gluebi_device *gluebi; struct gluebi_device *gluebi;
if (instr->addr < 0 || instr->addr > mtd->size - mtd->erasesize)
return -EINVAL;
if (instr->len < 0 || instr->addr + instr->len > mtd->size)
return -EINVAL;
if (mtd_mod_by_ws(instr->addr, mtd) || mtd_mod_by_ws(instr->len, mtd)) if (mtd_mod_by_ws(instr->addr, mtd) || mtd_mod_by_ws(instr->len, mtd))
return -EINVAL; return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment