Skip to content

Commit

Permalink
mtd: introduce mtd_read interface
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Bityutskiy <[email protected]>
Signed-off-by: David Woodhouse <[email protected]>
  • Loading branch information
dedekind authored and David Woodhouse committed Jan 9, 2012
1 parent 04c601b commit 329ad39
Show file tree
Hide file tree
Showing 35 changed files with 152 additions and 135 deletions.
2 changes: 1 addition & 1 deletion arch/arm/mach-davinci/board-da850-evm.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static void da850_evm_m25p80_notify_add(struct mtd_info *mtd)
size_t retlen;

if (!strcmp(mtd->name, "MAC-Address")) {
mtd->read(mtd, 0, ETH_ALEN, &retlen, mac_addr);
mtd_read(mtd, 0, ETH_ALEN, &retlen, mac_addr);
if (retlen == ETH_ALEN)
pr_info("Read MAC addr from SPI Flash: %pM\n",
mac_addr);
Expand Down
4 changes: 2 additions & 2 deletions arch/cris/arch-v32/drivers/axisflashmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ static int __init init_axis_flash(void)
} while (blockstat && ptable_sector);
#endif
if (ptable_sector) {
main_mtd->read(main_mtd, ptable_sector, PAGESIZE,
&len, page);
mtd_read(main_mtd, ptable_sector, PAGESIZE, &len,
page);
ptable_head = &((struct partitiontable *) page)->head;
}

Expand Down
4 changes: 2 additions & 2 deletions drivers/mtd/afs.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ afs_read_footer(struct mtd_info *mtd, u_int *img_start, u_int *iis_start,
size_t sz;
int ret;

ret = mtd->read(mtd, ptr, sizeof(fs), &sz, (u_char *) &fs);
ret = mtd_read(mtd, ptr, sizeof(fs), &sz, (u_char *)&fs);
if (ret >= 0 && sz != sizeof(fs))
ret = -EINVAL;

Expand Down Expand Up @@ -132,7 +132,7 @@ afs_read_iis(struct mtd_info *mtd, struct image_info_struct *iis, u_int ptr)
int ret, i;

memset(iis, 0, sizeof(*iis));
ret = mtd->read(mtd, ptr, sizeof(*iis), &sz, (u_char *) iis);
ret = mtd_read(mtd, ptr, sizeof(*iis), &sz, (u_char *)iis);
if (ret < 0)
goto failed;

Expand Down
15 changes: 7 additions & 8 deletions drivers/mtd/ar7part.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ static int create_mtd_partitions(struct mtd_info *master,

do { /* Try 10 blocks starting from master->erasesize */
offset = pre_size;
master->read(master, offset,
sizeof(header), &len, (uint8_t *)&header);
mtd_read(master, offset, sizeof(header), &len,
(uint8_t *)&header);
if (!strncmp((char *)&header, "TIENV0.8", 8))
ar7_parts[1].offset = pre_size;
if (header.checksum == LOADER_MAGIC1)
Expand All @@ -95,16 +95,16 @@ static int create_mtd_partitions(struct mtd_info *master,
case LOADER_MAGIC1:
while (header.length) {
offset += sizeof(header) + header.length;
master->read(master, offset, sizeof(header),
&len, (uint8_t *)&header);
mtd_read(master, offset, sizeof(header), &len,
(uint8_t *)&header);
}
root_offset = offset + sizeof(header) + 4;
break;
case LOADER_MAGIC2:
while (header.length) {
offset += sizeof(header) + header.length;
master->read(master, offset, sizeof(header),
&len, (uint8_t *)&header);
mtd_read(master, offset, sizeof(header), &len,
(uint8_t *)&header);
}
root_offset = offset + sizeof(header) + 4 + 0xff;
root_offset &= ~(uint32_t)0xff;
Expand All @@ -114,8 +114,7 @@ static int create_mtd_partitions(struct mtd_info *master,
break;
}

master->read(master, root_offset,
sizeof(header), &len, (u8 *)&header);
mtd_read(master, root_offset, sizeof(header), &len, (u8 *)&header);
if (header.checksum != SQUASHFS_MAGIC) {
root_offset += master->erasesize - 1;
root_offset &= ~(master->erasesize - 1);
Expand Down
12 changes: 6 additions & 6 deletions drivers/mtd/bcm63xxpart.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ static int bcm63xx_detect_cfe(struct mtd_info *master)
int ret;
size_t retlen;

ret = master->read(master, BCM963XX_CFE_VERSION_OFFSET, 5, &retlen,
(void *)buf);
ret = mtd_read(master, BCM963XX_CFE_VERSION_OFFSET, 5, &retlen,
(void *)buf);
buf[retlen] = 0;

if (ret)
Expand All @@ -59,8 +59,8 @@ static int bcm63xx_detect_cfe(struct mtd_info *master)
return 0;

/* very old CFE's do not have the cfe-v string, so check for magic */
ret = master->read(master, BCM63XX_CFE_MAGIC_OFFSET, 8, &retlen,
(void *)buf);
ret = mtd_read(master, BCM63XX_CFE_MAGIC_OFFSET, 8, &retlen,
(void *)buf);
buf[retlen] = 0;

return strncmp("CFE1CFE1", buf, 8);
Expand Down Expand Up @@ -95,8 +95,8 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
return -ENOMEM;

/* Get the tag */
ret = master->read(master, cfelen, sizeof(struct bcm_tag), &retlen,
(void *)buf);
ret = mtd_read(master, cfelen, sizeof(struct bcm_tag), &retlen,
(void *)buf);

if (retlen != sizeof(struct bcm_tag)) {
vfree(buf);
Expand Down
41 changes: 21 additions & 20 deletions drivers/mtd/ftl.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ static int scan_header(partition_t *part)
(offset + sizeof(header)) < max_offset;
offset += part->mbd.mtd->erasesize ? : 0x2000) {

err = part->mbd.mtd->read(part->mbd.mtd, offset, sizeof(header), &ret,
(unsigned char *)&header);
err = mtd_read(part->mbd.mtd, offset, sizeof(header), &ret,
(unsigned char *)&header);

if (err)
return err;
Expand Down Expand Up @@ -224,8 +224,8 @@ static int build_maps(partition_t *part)
for (i = 0; i < le16_to_cpu(part->header.NumEraseUnits); i++) {
offset = ((i + le16_to_cpu(part->header.FirstPhysicalEUN))
<< part->header.EraseUnitSize);
ret = part->mbd.mtd->read(part->mbd.mtd, offset, sizeof(header), &retval,
(unsigned char *)&header);
ret = mtd_read(part->mbd.mtd, offset, sizeof(header), &retval,
(unsigned char *)&header);

if (ret)
goto out_XferInfo;
Expand Down Expand Up @@ -289,9 +289,9 @@ static int build_maps(partition_t *part)
part->EUNInfo[i].Deleted = 0;
offset = part->EUNInfo[i].Offset + le32_to_cpu(header.BAMOffset);

ret = part->mbd.mtd->read(part->mbd.mtd, offset,
part->BlocksPerUnit * sizeof(uint32_t), &retval,
(unsigned char *)part->bam_cache);
ret = mtd_read(part->mbd.mtd, offset,
part->BlocksPerUnit * sizeof(uint32_t), &retval,
(unsigned char *)part->bam_cache);

if (ret)
goto out_bam_cache;
Expand Down Expand Up @@ -485,9 +485,9 @@ static int copy_erase_unit(partition_t *part, uint16_t srcunit,

offset = eun->Offset + le32_to_cpu(part->header.BAMOffset);

ret = part->mbd.mtd->read(part->mbd.mtd, offset,
part->BlocksPerUnit * sizeof(uint32_t),
&retlen, (u_char *) (part->bam_cache));
ret = mtd_read(part->mbd.mtd, offset,
part->BlocksPerUnit * sizeof(uint32_t), &retlen,
(u_char *)(part->bam_cache));

/* mark the cache bad, in case we get an error later */
part->bam_index = 0xffff;
Expand Down Expand Up @@ -523,8 +523,8 @@ static int copy_erase_unit(partition_t *part, uint16_t srcunit,
break;
case BLOCK_DATA:
case BLOCK_REPLACEMENT:
ret = part->mbd.mtd->read(part->mbd.mtd, src, SECTOR_SIZE,
&retlen, (u_char *) buf);
ret = mtd_read(part->mbd.mtd, src, SECTOR_SIZE, &retlen,
(u_char *)buf);
if (ret) {
printk(KERN_WARNING "ftl: Error reading old xfer unit in copy_erase_unit\n");
return ret;
Expand Down Expand Up @@ -747,10 +747,11 @@ static uint32_t find_free(partition_t *part)
/* Invalidate cache */
part->bam_index = 0xffff;

ret = part->mbd.mtd->read(part->mbd.mtd,
part->EUNInfo[eun].Offset + le32_to_cpu(part->header.BAMOffset),
part->BlocksPerUnit * sizeof(uint32_t),
&retlen, (u_char *) (part->bam_cache));
ret = mtd_read(part->mbd.mtd,
part->EUNInfo[eun].Offset + le32_to_cpu(part->header.BAMOffset),
part->BlocksPerUnit * sizeof(uint32_t),
&retlen,
(u_char *)(part->bam_cache));

if (ret) {
printk(KERN_WARNING"ftl: Error reading BAM in find_free\n");
Expand Down Expand Up @@ -810,8 +811,8 @@ static int ftl_read(partition_t *part, caddr_t buffer,
else {
offset = (part->EUNInfo[log_addr / bsize].Offset
+ (log_addr % bsize));
ret = part->mbd.mtd->read(part->mbd.mtd, offset, SECTOR_SIZE,
&retlen, (u_char *) buffer);
ret = mtd_read(part->mbd.mtd, offset, SECTOR_SIZE, &retlen,
(u_char *)buffer);

if (ret) {
printk(KERN_WARNING "Error reading MTD device in ftl_read()\n");
Expand Down Expand Up @@ -849,8 +850,8 @@ static int set_bam_entry(partition_t *part, uint32_t log_addr,
le32_to_cpu(part->header.BAMOffset));

#ifdef PSYCHO_DEBUG
ret = part->mbd.mtd->read(part->mbd.mtd, offset, sizeof(uint32_t),
&retlen, (u_char *)&old_addr);
ret = mtd_read(part->mbd.mtd, offset, sizeof(uint32_t), &retlen,
(u_char *)&old_addr);
if (ret) {
printk(KERN_WARNING"ftl: Error reading old_addr in set_bam_entry: %d\n",ret);
return ret;
Expand Down
19 changes: 11 additions & 8 deletions drivers/mtd/inftlcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,17 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
if (BlockMap[block] == BLOCK_NIL)
continue;

ret = mtd->read(mtd, (inftl->EraseSize * BlockMap[block]) +
(block * SECTORSIZE), SECTORSIZE, &retlen,
movebuf);
ret = mtd_read(mtd,
(inftl->EraseSize * BlockMap[block]) + (block * SECTORSIZE),
SECTORSIZE,
&retlen,
movebuf);
if (ret < 0 && !mtd_is_bitflip(ret)) {
ret = mtd->read(mtd,
(inftl->EraseSize * BlockMap[block]) +
(block * SECTORSIZE), SECTORSIZE,
&retlen, movebuf);
ret = mtd_read(mtd,
(inftl->EraseSize * BlockMap[block]) + (block * SECTORSIZE),
SECTORSIZE,
&retlen,
movebuf);
if (ret != -EIO)
pr_debug("INFTL: error went away on retry?\n");
}
Expand Down Expand Up @@ -914,7 +917,7 @@ static int inftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
} else {
size_t retlen;
loff_t ptr = (thisEUN * inftl->EraseSize) + blockofs;
int ret = mtd->read(mtd, ptr, SECTORSIZE, &retlen, buffer);
int ret = mtd_read(mtd, ptr, SECTORSIZE, &retlen, buffer);

/* Handle corrected bit flips gracefully */
if (ret < 0 && !mtd_is_bitflip(ret))
Expand Down
10 changes: 5 additions & 5 deletions drivers/mtd/inftlmount.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ static int find_boot_record(struct INFTLrecord *inftl)
* Check for BNAND header first. Then whinge if it's found
* but later checks fail.
*/
ret = mtd->read(mtd, block * inftl->EraseSize,
SECTORSIZE, &retlen, buf);
ret = mtd_read(mtd, block * inftl->EraseSize, SECTORSIZE,
&retlen, buf);
/* We ignore ret in case the ECC of the MediaHeader is invalid
(which is apparently acceptable) */
if (retlen != SECTORSIZE) {
Expand Down Expand Up @@ -118,8 +118,8 @@ static int find_boot_record(struct INFTLrecord *inftl)
memcpy(mh, buf, sizeof(struct INFTLMediaHeader));

/* Read the spare media header at offset 4096 */
mtd->read(mtd, block * inftl->EraseSize + 4096,
SECTORSIZE, &retlen, buf);
mtd_read(mtd, block * inftl->EraseSize + 4096, SECTORSIZE,
&retlen, buf);
if (retlen != SECTORSIZE) {
printk(KERN_WARNING "INFTL: Unable to read spare "
"Media Header\n");
Expand Down Expand Up @@ -342,7 +342,7 @@ static int check_free_sectors(struct INFTLrecord *inftl, unsigned int address,
int i;

for (i = 0; i < len; i += SECTORSIZE) {
if (mtd->read(mtd, address, SECTORSIZE, &retlen, buf))
if (mtd_read(mtd, address, SECTORSIZE, &retlen, buf))
return -1;
if (memcmpb(buf, 0xff, SECTORSIZE) != 0)
return -1;
Expand Down
8 changes: 4 additions & 4 deletions drivers/mtd/mtdblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
mtdblk->cache_offset != sect_start) {
/* fill the cache with the current sector */
mtdblk->cache_state = STATE_EMPTY;
ret = mtd->read(mtd, sect_start, sect_size,
&retlen, mtdblk->cache_data);
ret = mtd_read(mtd, sect_start, sect_size,
&retlen, mtdblk->cache_data);
if (ret)
return ret;
if (retlen != sect_size)
Expand Down Expand Up @@ -222,7 +222,7 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
mtd->name, pos, len);

if (!sect_size)
return mtd->read(mtd, pos, len, &retlen, buf);
return mtd_read(mtd, pos, len, &retlen, buf);

while (len > 0) {
unsigned long sect_start = (pos/sect_size)*sect_size;
Expand All @@ -241,7 +241,7 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
mtdblk->cache_offset == sect_start) {
memcpy (buf, mtdblk->cache_data + offset, size);
} else {
ret = mtd->read(mtd, pos, size, &retlen, buf);
ret = mtd_read(mtd, pos, size, &retlen, buf);
if (ret)
return ret;
if (retlen != size)
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/mtdblock_ro.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static int mtdblock_readsect(struct mtd_blktrans_dev *dev,
{
size_t retlen;

if (dev->mtd->read(dev->mtd, (block * 512), 512, &retlen, buf))
if (mtd_read(dev->mtd, (block * 512), 512, &retlen, buf))
return 1;
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/mtdchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ static ssize_t mtdchar_read(struct file *file, char __user *buf, size_t count,
break;
}
default:
ret = mtd->read(mtd, *ppos, len, &retlen, kbuf);
ret = mtd_read(mtd, *ppos, len, &retlen, kbuf);
}
/* Nand returns -EBADMSG on ECC errors, but it returns
* the data. For our userspace tools it is important
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/mtdconcat.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ concat_read(struct mtd_info *mtd, loff_t from, size_t len,
/* Entire transaction goes into this subdev */
size = len;

err = subdev->read(subdev, from, size, &retsize, buf);
err = mtd_read(subdev, from, size, &retsize, buf);

/* Save information about bitflips! */
if (unlikely(err)) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/mtd/mtdoops.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ static void find_next_position(struct mtdoops_context *cxt)
continue;
/* Assume the page is used */
mark_page_used(cxt, page);
ret = mtd->read(mtd, page * record_size, MTDOOPS_HEADER_SIZE,
&retlen, (u_char *) &count[0]);
ret = mtd_read(mtd, page * record_size, MTDOOPS_HEADER_SIZE,
&retlen, (u_char *)&count[0]);
if (retlen != MTDOOPS_HEADER_SIZE ||
(ret < 0 && !mtd_is_bitflip(ret))) {
printk(KERN_ERR "mtdoops: read failure at %ld (%td of %d read), err %d\n",
Expand Down
3 changes: 1 addition & 2 deletions drivers/mtd/mtdpart.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ static int part_read(struct mtd_info *mtd, loff_t from, size_t len,
len = 0;
else if (from + len > mtd->size)
len = mtd->size - from;
res = part->master->read(part->master, from + part->offset,
len, retlen, buf);
res = mtd_read(part->master, from + part->offset, len, retlen, buf);
if (unlikely(res)) {
if (mtd_is_bitflip(res))
mtd->ecc_stats.corrected += part->master->ecc_stats.corrected - stats.corrected;
Expand Down
4 changes: 2 additions & 2 deletions drivers/mtd/mtdswap.c
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ static int mtdswap_move_block(struct mtdswap_dev *d, unsigned int oldblock,
retries = 0;

retry:
ret = mtd->read(mtd, readpos, PAGE_SIZE, &retlen, d->page_buf);
ret = mtd_read(mtd, readpos, PAGE_SIZE, &retlen, d->page_buf);

if (ret < 0 && !mtd_is_bitflip(ret)) {
oldeb = d->eb_data + oldblock / d->pages_per_eblk;
Expand Down Expand Up @@ -1161,7 +1161,7 @@ static int mtdswap_readsect(struct mtd_blktrans_dev *dev,
retries = 0;

retry:
ret = mtd->read(mtd, readpos, PAGE_SIZE, &retlen, buf);
ret = mtd_read(mtd, readpos, PAGE_SIZE, &retlen, buf);

d->mtd_read_count++;
if (mtd_is_bitflip(ret)) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/mtd/nand/diskonchip.c
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ static int __init find_media_headers(struct mtd_info *mtd, u_char *buf, const ch
size_t retlen;

for (offs = 0; offs < mtd->size; offs += mtd->erasesize) {
ret = mtd->read(mtd, offs, mtd->writesize, &retlen, buf);
ret = mtd_read(mtd, offs, mtd->writesize, &retlen, buf);
if (retlen != mtd->writesize)
continue;
if (ret) {
Expand All @@ -1097,7 +1097,7 @@ static int __init find_media_headers(struct mtd_info *mtd, u_char *buf, const ch
/* Only one mediaheader was found. We want buf to contain a
mediaheader on return, so we'll have to re-read the one we found. */
offs = doc->mh0_page << this->page_shift;
ret = mtd->read(mtd, offs, mtd->writesize, &retlen, buf);
ret = mtd_read(mtd, offs, mtd->writesize, &retlen, buf);
if (retlen != mtd->writesize) {
/* Insanity. Give up. */
printk(KERN_ERR "Read DiskOnChip Media Header once, but can't reread it???\n");
Expand Down
Loading

0 comments on commit 329ad39

Please sign in to comment.