Skip to content

Commit

Permalink
mtd: remove retlen zeroing duplication
Browse files Browse the repository at this point in the history
The MTD API function now zero the 'retlen' parameter before calling
the driver's method — do not do this again in drivers. This removes
duplicated '*retlen = 0' assignent from the following methods:

    'mtd_point()'
    'mtd_read()'
    'mtd_write()'
    'mtd_writev()'
    'mtd_panic_write()'

Signed-off-by: Artem Bityutskiy <[email protected]>
Signed-off-by: David Woodhouse <[email protected]>
  • Loading branch information
dedekind authored and David Woodhouse committed Mar 26, 2012
1 parent 664addc commit 834247e
Show file tree
Hide file tree
Showing 18 changed files with 1 addition and 73 deletions.
5 changes: 0 additions & 5 deletions drivers/mtd/chips/cfi_cmdset_0001.c
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,6 @@ static int cfi_intelext_point(struct mtd_info *mtd, loff_t from, size_t len,
ofs = from - (chipnum << cfi->chipshift);

*virt = map->virt + cfi->chips[chipnum].start + ofs;
*retlen = 0;
if (phys)
*phys = map->phys + cfi->chips[chipnum].start + ofs;

Expand Down Expand Up @@ -1460,8 +1459,6 @@ static int cfi_intelext_read (struct mtd_info *mtd, loff_t from, size_t len, siz
chipnum = (from >> cfi->chipshift);
ofs = from - (chipnum << cfi->chipshift);

*retlen = 0;

while (len) {
unsigned long thislen;

Expand Down Expand Up @@ -1569,7 +1566,6 @@ static int cfi_intelext_write_words (struct mtd_info *mtd, loff_t to , size_t le
int chipnum;
unsigned long ofs;

*retlen = 0;
if (!len)
return 0;

Expand Down Expand Up @@ -1817,7 +1813,6 @@ static int cfi_intelext_writev (struct mtd_info *mtd, const struct kvec *vecs,
for (i = 0; i < count; i++)
len += vecs[i].iov_len;

*retlen = 0;
if (!len)
return 0;

Expand Down
12 changes: 0 additions & 12 deletions drivers/mtd/chips/cfi_cmdset_0002.c
Original file line number Diff line number Diff line change
Expand Up @@ -1017,13 +1017,9 @@ static int cfi_amdstd_read (struct mtd_info *mtd, loff_t from, size_t len, size_
int ret = 0;

/* ofs: offset within the first chip that the first read should start */

chipnum = (from >> cfi->chipshift);
ofs = from - (chipnum << cfi->chipshift);


*retlen = 0;

while (len) {
unsigned long thislen;

Expand Down Expand Up @@ -1101,16 +1097,11 @@ static int cfi_amdstd_secsi_read (struct mtd_info *mtd, loff_t from, size_t len,
int chipnum;
int ret = 0;


/* ofs: offset within the first chip that the first read should start */

/* 8 secsi bytes per chip */
chipnum=from>>3;
ofs=from & 7;


*retlen = 0;

while (len) {
unsigned long thislen;

Expand Down Expand Up @@ -1255,7 +1246,6 @@ static int cfi_amdstd_write_words(struct mtd_info *mtd, loff_t to, size_t len,
unsigned long ofs, chipstart;
DECLARE_WAITQUEUE(wait, current);

*retlen = 0;
if (!len)
return 0;

Expand Down Expand Up @@ -1497,7 +1487,6 @@ static int cfi_amdstd_write_buffers(struct mtd_info *mtd, loff_t to, size_t len,
int chipnum;
unsigned long ofs;

*retlen = 0;
if (!len)
return 0;

Expand Down Expand Up @@ -1708,7 +1697,6 @@ static int cfi_amdstd_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
int ret = 0;
int chipnum;

*retlen = 0;
if (!len)
return 0;

Expand Down
3 changes: 0 additions & 3 deletions drivers/mtd/chips/cfi_cmdset_0020.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,6 @@ static int cfi_staa_read (struct mtd_info *mtd, loff_t from, size_t len, size_t
chipnum = (from >> cfi->chipshift);
ofs = from - (chipnum << cfi->chipshift);

*retlen = 0;

while (len) {
unsigned long thislen;

Expand Down Expand Up @@ -617,7 +615,6 @@ static int cfi_staa_write_buffers (struct mtd_info *mtd, loff_t to,
int chipnum;
unsigned long ofs;

*retlen = 0;
if (!len)
return 0;

Expand Down
2 changes: 0 additions & 2 deletions drivers/mtd/chips/map_absent.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,11 @@ static struct mtd_info *map_absent_probe(struct map_info *map)

static int map_absent_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
{
*retlen = 0;
return -ENODEV;
}

static int map_absent_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
{
*retlen = 0;
return -ENODEV;
}

Expand Down
5 changes: 0 additions & 5 deletions drivers/mtd/devices/block2mtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ static int block2mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
int offset = from & (PAGE_SIZE-1);
int cpylen;

if (retlen)
*retlen = 0;

while (len) {
if ((offset + len) > PAGE_SIZE)
cpylen = PAGE_SIZE - offset; // multiple pages
Expand Down Expand Up @@ -143,8 +140,6 @@ static int _block2mtd_write(struct block2mtd_dev *dev, const u_char *buf,
int offset = to & ~PAGE_MASK; // page offset
int cpylen;

if (retlen)
*retlen = 0;
while (len) {
if ((offset+len) > PAGE_SIZE)
cpylen = PAGE_SIZE - offset; // multiple pages
Expand Down
4 changes: 0 additions & 4 deletions drivers/mtd/devices/doc2000.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,6 @@ static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
size_t left = len;

mutex_lock(&this->lock);

*retlen = 0;
while (left) {
len = left;

Expand Down Expand Up @@ -745,8 +743,6 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
int status;

mutex_lock(&this->lock);

*retlen = 0;
while (left) {
len = left;

Expand Down
1 change: 0 additions & 1 deletion drivers/mtd/devices/doc2001.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,6 @@ static int doc_write (struct mtd_info *mtd, loff_t to, size_t len,
printk("Error programming flash\n");
/* Error in programming
FIXME: implement Bad Block Replacement (in nftl.c ??) */
*retlen = 0;
ret = -EIO;
}
dummy = ReadDOC(docptr, LastDataRead);
Expand Down
1 change: 0 additions & 1 deletion drivers/mtd/devices/doc2001plus.c
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,6 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
printk("MTD: Error 0x%x programming at 0x%x\n", dummy, (int)to);
/* Error in programming
FIXME: implement Bad Block Replacement (in nftl.c ??) */
*retlen = 0;
ret = -EIO;
}
dummy = ReadDOC(docptr, Mplus_LastDataRead);
Expand Down
2 changes: 0 additions & 2 deletions drivers/mtd/devices/lart.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,6 @@ static int flash_write (struct mtd_info *mtd,loff_t to,size_t len,size_t *retlen
printk (KERN_DEBUG "%s(to = 0x%.8x, len = %d)\n", __func__, (__u32)to, len);
#endif

*retlen = 0;

/* sanity checks */
if (!len) return (0);

Expand Down
7 changes: 0 additions & 7 deletions drivers/mtd/devices/m25p80.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,6 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len,
t[1].len = len;
spi_message_add_tail(&t[1], &m);

/* Byte count starts at zero. */
*retlen = 0;

mutex_lock(&flash->lock);

/* Wait till previous write/erase is done. */
Expand Down Expand Up @@ -411,8 +408,6 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
pr_debug("%s: %s to 0x%08x, len %zd\n", dev_name(&flash->spi->dev),
__func__, (u32)to, len);

*retlen = 0;

/* sanity checks */
if (!len)
return(0);
Expand Down Expand Up @@ -500,8 +495,6 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
pr_debug("%s: %s to 0x%08x, len %zd\n", dev_name(&flash->spi->dev),
__func__, (u32)to, len);

*retlen = 0;

/* sanity checks */
if (!len)
return 0;
Expand Down
4 changes: 0 additions & 4 deletions drivers/mtd/devices/mtd_dataflash.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,6 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len,
pr_debug("%s: read 0x%x..0x%x\n", dev_name(&priv->spi->dev),
(unsigned)from, (unsigned)(from + len));

*retlen = 0;

/* Sanity checks */
if (!len)
return 0;
Expand Down Expand Up @@ -323,8 +321,6 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
pr_debug("%s: write 0x%x..0x%x\n",
dev_name(&spi->dev), (unsigned)to, (unsigned)(to + len));

*retlen = 0;

/* Sanity checks */
if (!len)
return 0;
Expand Down
2 changes: 0 additions & 2 deletions drivers/mtd/devices/phram.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ static int phram_write(struct mtd_info *mtd, loff_t to, size_t len,
return 0;
}



static void unregister_devices(void)
{
struct phram_mtd_list *this, *safe;
Expand Down
10 changes: 0 additions & 10 deletions drivers/mtd/devices/spear_smi.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,11 +574,6 @@ static int spear_mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
return -EINVAL;
}

if (!retlen)
return -EINVAL;
else
*retlen = 0;

/* select address as per bank number */
src = flash->base_addr + from;

Expand Down Expand Up @@ -675,11 +670,6 @@ static int spear_mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
return -EINVAL;
}

if (!retlen)
return -EINVAL;
else
*retlen = 0;

/* select address as per bank number */
dest = flash->base_addr + to;
mutex_lock(&flash->lock);
Expand Down
3 changes: 0 additions & 3 deletions drivers/mtd/devices/sst25l.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,6 @@ static int sst25l_read(struct mtd_info *mtd, loff_t from, size_t len,
if (len == 0)
return 0;

if (retlen)
*retlen = 0;

spi_message_init(&message);
memset(&transfer, 0, sizeof(transfer));

Expand Down
3 changes: 0 additions & 3 deletions drivers/mtd/lpddr/lpddr_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,7 @@ static int lpddr_point(struct mtd_info *mtd, loff_t adr, size_t len,

/* ofs: offset within the first chip that the first read should start */
ofs = adr - (chipnum << lpddr->chipshift);

*mtdbuf = (void *)map->virt + chip->start + ofs;
*retlen = 0;

while (len) {
unsigned long thislen;
Expand Down Expand Up @@ -647,7 +645,6 @@ static int lpddr_writev(struct mtd_info *mtd, const struct kvec *vecs,
for (i = 0; i < count; i++)
len += vecs[i].iov_len;

*retlen = 0;
if (!len)
return 0;

Expand Down
6 changes: 0 additions & 6 deletions drivers/mtd/mtdconcat.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ concat_read(struct mtd_info *mtd, loff_t from, size_t len,
int ret = 0, err;
int i;

*retlen = 0;

for (i = 0; i < concat->num_subdev; i++) {
struct mtd_info *subdev = concat->subdev[i];
size_t size, retsize;
Expand Down Expand Up @@ -126,8 +124,6 @@ concat_write(struct mtd_info *mtd, loff_t to, size_t len,
int err = -EINVAL;
int i;

*retlen = 0;

for (i = 0; i < concat->num_subdev; i++) {
struct mtd_info *subdev = concat->subdev[i];
size_t size, retsize;
Expand Down Expand Up @@ -169,8 +165,6 @@ concat_writev(struct mtd_info *mtd, const struct kvec *vecs,
int i;
int err = -EINVAL;

*retlen = 0;

/* Calculate total length of data */
for (i = 0; i < count; i++)
total_len += vecs[i].iov_len;
Expand Down
1 change: 1 addition & 0 deletions drivers/mtd/mtdcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ EXPORT_SYMBOL_GPL(mtd_get_unmapped_area);
int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
u_char *buf)
{
*retlen = 0;
if (from < 0 || from > mtd->size || len > mtd->size - from)
return -EINVAL;
return mtd->_read(mtd, from, len, retlen, buf);
Expand Down
3 changes: 0 additions & 3 deletions drivers/mtd/onenand/onenand_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -1753,9 +1753,6 @@ static int onenand_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
pr_debug("%s: to = 0x%08x, len = %i\n", __func__, (unsigned int)to,
(int)len);

/* Initialize retlen, in case of early exit */
*retlen = 0;

/* Reject writes, which are not page aligned */
if (unlikely(NOTALIGNED(to) || NOTALIGNED(len))) {
printk(KERN_ERR "%s: Attempt to write not page aligned data\n",
Expand Down

0 comments on commit 834247e

Please sign in to comment.