Skip to content

Commit

Permalink
[MTD] Remove silly MTD_WRITE/READ macros
Browse files Browse the repository at this point in the history
Most of those macros are unused and the used ones just obfuscate
the code. Remove them and fixup all users.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
  • Loading branch information
Thomas Gleixner committed May 29, 2006
1 parent 5bd34c0 commit f4a43cf
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 179 deletions.
63 changes: 34 additions & 29 deletions drivers/mtd/inftlcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,11 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
u16 BlockMap[MAX_SECTORS_PER_UNIT];
unsigned char BlockDeleted[MAX_SECTORS_PER_UNIT];
unsigned int thisEUN, prevEUN, status;
struct mtd_info *mtd = inftl->mbd.mtd;
int block, silly;
unsigned int targetEUN;
struct inftl_oob oob;
size_t retlen;
size_t retlen;

DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,"
"pending=%d)\n", inftl, thisVUC, pendingblock);
Expand All @@ -226,9 +227,9 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
if ((BlockMap[block] != 0xffff) || BlockDeleted[block])
continue;

if (MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize)
+ (block * SECTORSIZE), 16 , &retlen,
(char *)&oob) < 0)
if (mtd->read_oob(mtd, (thisEUN * inftl->EraseSize)
+ (block * SECTORSIZE), 16 , &retlen,
(char *)&oob) < 0)
status = SECTOR_IGNORE;
else
status = oob.b.Status | oob.b.Status1;
Expand Down Expand Up @@ -288,13 +289,14 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
if (BlockMap[block] == BLOCK_NIL)
continue;

ret = MTD_READ(inftl->mbd.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) {
ret = MTD_READ(inftl->mbd.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)
DEBUG(MTD_DEBUG_LEVEL1, "INFTL: error went "
"away on retry?\n");
Expand Down Expand Up @@ -415,6 +417,7 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
unsigned int thisVUC = block / (inftl->EraseSize / SECTORSIZE);
unsigned int thisEUN, writeEUN, prev_block, status;
unsigned long blockofs = (block * SECTORSIZE) & (inftl->EraseSize -1);
struct mtd_info *mtd = inftl->mbd.mtd;
struct inftl_oob oob;
struct inftl_bci bci;
unsigned char anac, nacs, parity;
Expand All @@ -434,8 +437,8 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
silly = MAX_LOOPS;

while (thisEUN <= inftl->lastEUN) {
MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize) +
blockofs, 8, &retlen, (char *)&bci);
mtd->read_oob(mtd, (thisEUN * inftl->EraseSize) +
blockofs, 8, &retlen, (char *)&bci);

status = bci.Status | bci.Status1;
DEBUG(MTD_DEBUG_LEVEL3, "INFTL: status of block %d in "
Expand Down Expand Up @@ -522,8 +525,8 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
nacs = 0;
thisEUN = inftl->VUtable[thisVUC];
if (thisEUN != BLOCK_NIL) {
MTD_READOOB(inftl->mbd.mtd, thisEUN * inftl->EraseSize
+ 8, 8, &retlen, (char *)&oob.u);
mtd->read_oob(mtd, thisEUN * inftl->EraseSize
+ 8, 8, &retlen, (char *)&oob.u);
anac = oob.u.a.ANAC + 1;
nacs = oob.u.a.NACs + 1;
}
Expand All @@ -544,8 +547,8 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
oob.u.a.parityPerField = parity;
oob.u.a.discarded = 0xaa;

MTD_WRITEOOB(inftl->mbd.mtd, writeEUN * inftl->EraseSize + 8, 8,
&retlen, (char *)&oob.u);
mtd->write_oob(mtd, writeEUN * inftl->EraseSize + 8, 8,
&retlen, (char *)&oob.u);

/* Also back up header... */
oob.u.b.virtualUnitNo = cpu_to_le16(thisVUC);
Expand All @@ -555,8 +558,8 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
oob.u.b.parityPerField = parity;
oob.u.b.discarded = 0xaa;

MTD_WRITEOOB(inftl->mbd.mtd, writeEUN * inftl->EraseSize +
SECTORSIZE * 4 + 8, 8, &retlen, (char *)&oob.u);
mtd->write_oob(mtd, writeEUN * inftl->EraseSize +
SECTORSIZE * 4 + 8, 8, &retlen, (char *)&oob.u);

inftl->PUtable[writeEUN] = inftl->VUtable[thisVUC];
inftl->VUtable[thisVUC] = writeEUN;
Expand All @@ -576,6 +579,7 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
*/
static void INFTL_trydeletechain(struct INFTLrecord *inftl, unsigned thisVUC)
{
struct mtd_info *mtd = inftl->mbd.mtd;
unsigned char BlockUsed[MAX_SECTORS_PER_UNIT];
unsigned char BlockDeleted[MAX_SECTORS_PER_UNIT];
unsigned int thisEUN, status;
Expand Down Expand Up @@ -606,9 +610,9 @@ static void INFTL_trydeletechain(struct INFTLrecord *inftl, unsigned thisVUC)
if (BlockUsed[block] || BlockDeleted[block])
continue;

if (MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize)
+ (block * SECTORSIZE), 8 , &retlen,
(char *)&bci) < 0)
if (mtd->read_oob(mtd, (thisEUN * inftl->EraseSize)
+ (block * SECTORSIZE), 8 , &retlen,
(char *)&bci) < 0)
status = SECTOR_IGNORE;
else
status = bci.Status | bci.Status1;
Expand Down Expand Up @@ -697,6 +701,7 @@ static int INFTL_deleteblock(struct INFTLrecord *inftl, unsigned block)
{
unsigned int thisEUN = inftl->VUtable[block / (inftl->EraseSize / SECTORSIZE)];
unsigned long blockofs = (block * SECTORSIZE) & (inftl->EraseSize - 1);
struct mtd_info *mtd = inftl->mbd.mtd;
unsigned int status;
int silly = MAX_LOOPS;
size_t retlen;
Expand All @@ -706,8 +711,8 @@ static int INFTL_deleteblock(struct INFTLrecord *inftl, unsigned block)
"block=%d)\n", inftl, block);

while (thisEUN < inftl->nb_blocks) {
if (MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize) +
blockofs, 8, &retlen, (char *)&bci) < 0)
if (mtd->read_oob(mtd, (thisEUN * inftl->EraseSize) +
blockofs, 8, &retlen, (char *)&bci) < 0)
status = SECTOR_IGNORE;
else
status = bci.Status | bci.Status1;
Expand Down Expand Up @@ -741,10 +746,10 @@ static int INFTL_deleteblock(struct INFTLrecord *inftl, unsigned block)
if (thisEUN != BLOCK_NIL) {
loff_t ptr = (thisEUN * inftl->EraseSize) + blockofs;

if (MTD_READOOB(inftl->mbd.mtd, ptr, 8, &retlen, (char *)&bci) < 0)
if (mtd->read_oob(mtd, ptr, 8, &retlen, (char *)&bci) < 0)
return -EIO;
bci.Status = bci.Status1 = SECTOR_DELETED;
if (MTD_WRITEOOB(inftl->mbd.mtd, ptr, 8, &retlen, (char *)&bci) < 0)
if (mtd->write_oob(mtd, ptr, 8, &retlen, (char *)&bci) < 0)
return -EIO;
INFTL_trydeletechain(inftl, block / (inftl->EraseSize / SECTORSIZE));
}
Expand Down Expand Up @@ -805,6 +810,7 @@ static int inftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
struct INFTLrecord *inftl = (void *)mbd;
unsigned int thisEUN = inftl->VUtable[block / (inftl->EraseSize / SECTORSIZE)];
unsigned long blockofs = (block * SECTORSIZE) & (inftl->EraseSize - 1);
struct mtd_info *mtd = inftl->mbd.mtd;
unsigned int status;
int silly = MAX_LOOPS;
struct inftl_bci bci;
Expand All @@ -814,8 +820,8 @@ static int inftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
"buffer=%p)\n", inftl, block, buffer);

while (thisEUN < inftl->nb_blocks) {
if (MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize) +
blockofs, 8, &retlen, (char *)&bci) < 0)
if (mtd->read_oob(mtd, (thisEUN * inftl->EraseSize) +
blockofs, 8, &retlen, (char *)&bci) < 0)
status = SECTOR_IGNORE;
else
status = bci.Status | bci.Status1;
Expand Down Expand Up @@ -853,8 +859,7 @@ static int inftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
} else {
size_t retlen;
loff_t ptr = (thisEUN * inftl->EraseSize) + blockofs;
if (MTD_READ(inftl->mbd.mtd, ptr, SECTORSIZE, &retlen,
buffer))
if (mtd->read(mtd, ptr, SECTORSIZE, &retlen, buffer))
return -EIO;
}
return 0;
Expand Down
43 changes: 24 additions & 19 deletions drivers/mtd/inftlmount.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static int find_boot_record(struct INFTLrecord *inftl)
unsigned int i, block;
u8 buf[SECTORSIZE];
struct INFTLMediaHeader *mh = &inftl->MediaHdr;
struct mtd_info *mtd = inftl->mbd.mtd;
struct INFTLPartition *ip;
size_t retlen;

Expand All @@ -80,8 +81,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(inftl->mbd.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 All @@ -106,8 +107,9 @@ static int find_boot_record(struct INFTLrecord *inftl)
}

/* To be safer with BIOS, also use erase mark as discriminant */
if ((ret = MTD_READOOB(inftl->mbd.mtd, block * inftl->EraseSize +
SECTORSIZE + 8, 8, &retlen, (char *)&h1) < 0)) {
if ((ret = mtd->read_oob(mtd, block * inftl->EraseSize +
SECTORSIZE + 8, 8, &retlen,
(char *)&h1) < 0)) {
printk(KERN_WARNING "INFTL: ANAND header found at "
"0x%x in mtd%d, but OOB data read failed "
"(err %d)\n", block * inftl->EraseSize,
Expand All @@ -123,8 +125,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(inftl->mbd.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 @@ -233,7 +235,7 @@ static int find_boot_record(struct INFTLrecord *inftl)
*/
instr->addr = ip->Reserved0 * inftl->EraseSize;
instr->len = inftl->EraseSize;
MTD_ERASE(inftl->mbd.mtd, instr);
mtd->erase(mtd, instr);
}
if ((ip->lastUnit - ip->firstUnit + 1) < ip->virtualUnits) {
printk(KERN_WARNING "INFTL: Media Header "
Expand Down Expand Up @@ -387,6 +389,7 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block)
size_t retlen;
struct inftl_unittail uci;
struct erase_info *instr = &inftl->instr;
struct mtd_info *mtd = inftl->mbd.mtd;
int physblock;

DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_formatblock(inftl=%p,"
Expand All @@ -404,8 +407,9 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block)
/* Erase one physical eraseblock at a time, even though the NAND api
allows us to group them. This way we if we have a failure, we can
mark only the failed block in the bbt. */
for (physblock = 0; physblock < inftl->EraseSize; physblock += instr->len, instr->addr += instr->len) {
MTD_ERASE(inftl->mbd.mtd, instr);
for (physblock = 0; physblock < inftl->EraseSize;
physblock += instr->len, instr->addr += instr->len) {
mtd->erase(inftl->mbd.mtd, instr);

if (instr->state == MTD_ERASE_FAILED) {
printk(KERN_WARNING "INFTL: error while formatting block %d\n",
Expand All @@ -414,10 +418,10 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block)
}

/*
* Check the "freeness" of Erase Unit before updating metadata.
* FixMe: is this check really necessary? Since we have check the
* return code after the erase operation.
*/
* Check the "freeness" of Erase Unit before updating metadata.
* FixMe: is this check really necessary? Since we have check
* the return code after the erase operation.
*/
if (check_free_sectors(inftl, instr->addr, instr->len, 1) != 0)
goto fail;
}
Expand All @@ -429,8 +433,7 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block)
uci.Reserved[2] = 0;
uci.Reserved[3] = 0;
instr->addr = block * inftl->EraseSize + SECTORSIZE * 2;
if (MTD_WRITEOOB(inftl->mbd.mtd, instr->addr +
8, 8, &retlen, (char *)&uci) < 0)
if (mtd->write_oob(mtd, instr->addr + 8, 8, &retlen, (char *)&uci) < 0)
goto fail;
return 0;
fail:
Expand Down Expand Up @@ -549,6 +552,7 @@ void INFTL_dumpVUchains(struct INFTLrecord *s)

int INFTL_mount(struct INFTLrecord *s)
{
struct mtd_info *mtd = s->mbd.mtd;
unsigned int block, first_block, prev_block, last_block;
unsigned int first_logical_block, logical_block, erase_mark;
int chain_length, do_format_chain;
Expand Down Expand Up @@ -607,10 +611,11 @@ int INFTL_mount(struct INFTLrecord *s)
break;
}

if (MTD_READOOB(s->mbd.mtd, block * s->EraseSize + 8,
8, &retlen, (char *)&h0) < 0 ||
MTD_READOOB(s->mbd.mtd, block * s->EraseSize +
2 * SECTORSIZE + 8, 8, &retlen, (char *)&h1) < 0) {
if (mtd->read_oob(mtd, block * s->EraseSize + 8,
8, &retlen, (char *)&h0) < 0 ||
mtd->read_oob(mtd, block * s->EraseSize +
2 * SECTORSIZE + 8, 8, &retlen,
(char *)&h1) < 0) {
/* Should never happen? */
do_format_chain++;
break;
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/maps/nettel.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ int nettel_eraseconfig(void)
set_current_state(TASK_INTERRUPTIBLE);
add_wait_queue(&wait_q, &wait);

ret = MTD_ERASE(mtd, &nettel_erase);
ret = mtd->erase(mtd, &nettel_erase);
if (ret) {
set_current_state(TASK_RUNNING);
remove_wait_queue(&wait_q, &wait);
Expand Down
13 changes: 7 additions & 6 deletions drivers/mtd/mtdblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static int erase_write (struct mtd_info *mtd, unsigned long pos,
set_current_state(TASK_INTERRUPTIBLE);
add_wait_queue(&wait_q, &wait);

ret = MTD_ERASE(mtd, &erase);
ret = mtd->erase(mtd, &erase);
if (ret) {
set_current_state(TASK_RUNNING);
remove_wait_queue(&wait_q, &wait);
Expand All @@ -88,7 +88,7 @@ static int erase_write (struct mtd_info *mtd, unsigned long pos,
* Next, writhe data to flash.
*/

ret = MTD_WRITE (mtd, pos, len, &retlen, buf);
ret = mtd->write(mtd, pos, len, &retlen, buf);
if (ret)
return ret;
if (retlen != len)
Expand Down Expand Up @@ -138,7 +138,7 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
mtd->name, pos, len);

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

while (len > 0) {
unsigned long sect_start = (pos/sect_size)*sect_size;
Expand Down Expand Up @@ -170,7 +170,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 @@ -207,7 +208,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 @@ -226,7 +227,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
4 changes: 2 additions & 2 deletions drivers/mtd/mtdchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
ret = mtd->read_user_prot_reg(mtd, *ppos, len, &retlen, kbuf);
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 All @@ -205,7 +205,7 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
if (!ret || (ret == -EBADMSG)) {
*ppos += retlen;
if (copy_to_user(buf, kbuf, retlen)) {
kfree(kbuf);
kfree(kbuf);
return -EFAULT;
}
else
Expand Down
Loading

0 comments on commit f4a43cf

Please sign in to comment.