Skip to content

Commit f4a43cf

Browse files
author
Thomas Gleixner
committed
[MTD] Remove silly MTD_WRITE/READ macros
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>
1 parent 5bd34c0 commit f4a43cf

9 files changed

Lines changed: 195 additions & 179 deletions

File tree

‎drivers/mtd/inftlcore.c‎

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,11 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
197197
u16 BlockMap[MAX_SECTORS_PER_UNIT];
198198
unsigned char BlockDeleted[MAX_SECTORS_PER_UNIT];
199199
unsigned int thisEUN, prevEUN, status;
200+
struct mtd_info *mtd = inftl->mbd.mtd;
200201
int block, silly;
201202
unsigned int targetEUN;
202203
struct inftl_oob oob;
203-
size_t retlen;
204+
size_t retlen;
204205

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

229-
if (MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize)
230-
+ (block * SECTORSIZE), 16 , &retlen,
231-
(char *)&oob) < 0)
230+
if (mtd->read_oob(mtd, (thisEUN * inftl->EraseSize)
231+
+ (block * SECTORSIZE), 16 , &retlen,
232+
(char *)&oob) < 0)
232233
status = SECTOR_IGNORE;
233234
else
234235
status = oob.b.Status | oob.b.Status1;
@@ -288,13 +289,14 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
288289
if (BlockMap[block] == BLOCK_NIL)
289290
continue;
290291

291-
ret = MTD_READ(inftl->mbd.mtd, (inftl->EraseSize *
292-
BlockMap[block]) + (block * SECTORSIZE), SECTORSIZE,
293-
&retlen, movebuf);
292+
ret = mtd->read(mtd, (inftl->EraseSize * BlockMap[block]) +
293+
(block * SECTORSIZE), SECTORSIZE, &retlen,
294+
movebuf);
294295
if (ret < 0) {
295-
ret = MTD_READ(inftl->mbd.mtd, (inftl->EraseSize *
296-
BlockMap[block]) + (block * SECTORSIZE),
297-
SECTORSIZE, &retlen, movebuf);
296+
ret = mtd->read(mtd,
297+
(inftl->EraseSize * BlockMap[block]) +
298+
(block * SECTORSIZE), SECTORSIZE,
299+
&retlen, movebuf);
298300
if (ret != -EIO)
299301
DEBUG(MTD_DEBUG_LEVEL1, "INFTL: error went "
300302
"away on retry?\n");
@@ -415,6 +417,7 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
415417
unsigned int thisVUC = block / (inftl->EraseSize / SECTORSIZE);
416418
unsigned int thisEUN, writeEUN, prev_block, status;
417419
unsigned long blockofs = (block * SECTORSIZE) & (inftl->EraseSize -1);
420+
struct mtd_info *mtd = inftl->mbd.mtd;
418421
struct inftl_oob oob;
419422
struct inftl_bci bci;
420423
unsigned char anac, nacs, parity;
@@ -434,8 +437,8 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
434437
silly = MAX_LOOPS;
435438

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

440443
status = bci.Status | bci.Status1;
441444
DEBUG(MTD_DEBUG_LEVEL3, "INFTL: status of block %d in "
@@ -522,8 +525,8 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
522525
nacs = 0;
523526
thisEUN = inftl->VUtable[thisVUC];
524527
if (thisEUN != BLOCK_NIL) {
525-
MTD_READOOB(inftl->mbd.mtd, thisEUN * inftl->EraseSize
526-
+ 8, 8, &retlen, (char *)&oob.u);
528+
mtd->read_oob(mtd, thisEUN * inftl->EraseSize
529+
+ 8, 8, &retlen, (char *)&oob.u);
527530
anac = oob.u.a.ANAC + 1;
528531
nacs = oob.u.a.NACs + 1;
529532
}
@@ -544,8 +547,8 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
544547
oob.u.a.parityPerField = parity;
545548
oob.u.a.discarded = 0xaa;
546549

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

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

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

561564
inftl->PUtable[writeEUN] = inftl->VUtable[thisVUC];
562565
inftl->VUtable[thisVUC] = writeEUN;
@@ -576,6 +579,7 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
576579
*/
577580
static void INFTL_trydeletechain(struct INFTLrecord *inftl, unsigned thisVUC)
578581
{
582+
struct mtd_info *mtd = inftl->mbd.mtd;
579583
unsigned char BlockUsed[MAX_SECTORS_PER_UNIT];
580584
unsigned char BlockDeleted[MAX_SECTORS_PER_UNIT];
581585
unsigned int thisEUN, status;
@@ -606,9 +610,9 @@ static void INFTL_trydeletechain(struct INFTLrecord *inftl, unsigned thisVUC)
606610
if (BlockUsed[block] || BlockDeleted[block])
607611
continue;
608612

609-
if (MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize)
610-
+ (block * SECTORSIZE), 8 , &retlen,
611-
(char *)&bci) < 0)
613+
if (mtd->read_oob(mtd, (thisEUN * inftl->EraseSize)
614+
+ (block * SECTORSIZE), 8 , &retlen,
615+
(char *)&bci) < 0)
612616
status = SECTOR_IGNORE;
613617
else
614618
status = bci.Status | bci.Status1;
@@ -697,6 +701,7 @@ static int INFTL_deleteblock(struct INFTLrecord *inftl, unsigned block)
697701
{
698702
unsigned int thisEUN = inftl->VUtable[block / (inftl->EraseSize / SECTORSIZE)];
699703
unsigned long blockofs = (block * SECTORSIZE) & (inftl->EraseSize - 1);
704+
struct mtd_info *mtd = inftl->mbd.mtd;
700705
unsigned int status;
701706
int silly = MAX_LOOPS;
702707
size_t retlen;
@@ -706,8 +711,8 @@ static int INFTL_deleteblock(struct INFTLrecord *inftl, unsigned block)
706711
"block=%d)\n", inftl, block);
707712

708713
while (thisEUN < inftl->nb_blocks) {
709-
if (MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize) +
710-
blockofs, 8, &retlen, (char *)&bci) < 0)
714+
if (mtd->read_oob(mtd, (thisEUN * inftl->EraseSize) +
715+
blockofs, 8, &retlen, (char *)&bci) < 0)
711716
status = SECTOR_IGNORE;
712717
else
713718
status = bci.Status | bci.Status1;
@@ -741,10 +746,10 @@ static int INFTL_deleteblock(struct INFTLrecord *inftl, unsigned block)
741746
if (thisEUN != BLOCK_NIL) {
742747
loff_t ptr = (thisEUN * inftl->EraseSize) + blockofs;
743748

744-
if (MTD_READOOB(inftl->mbd.mtd, ptr, 8, &retlen, (char *)&bci) < 0)
749+
if (mtd->read_oob(mtd, ptr, 8, &retlen, (char *)&bci) < 0)
745750
return -EIO;
746751
bci.Status = bci.Status1 = SECTOR_DELETED;
747-
if (MTD_WRITEOOB(inftl->mbd.mtd, ptr, 8, &retlen, (char *)&bci) < 0)
752+
if (mtd->write_oob(mtd, ptr, 8, &retlen, (char *)&bci) < 0)
748753
return -EIO;
749754
INFTL_trydeletechain(inftl, block / (inftl->EraseSize / SECTORSIZE));
750755
}
@@ -805,6 +810,7 @@ static int inftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
805810
struct INFTLrecord *inftl = (void *)mbd;
806811
unsigned int thisEUN = inftl->VUtable[block / (inftl->EraseSize / SECTORSIZE)];
807812
unsigned long blockofs = (block * SECTORSIZE) & (inftl->EraseSize - 1);
813+
struct mtd_info *mtd = inftl->mbd.mtd;
808814
unsigned int status;
809815
int silly = MAX_LOOPS;
810816
struct inftl_bci bci;
@@ -814,8 +820,8 @@ static int inftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
814820
"buffer=%p)\n", inftl, block, buffer);
815821

816822
while (thisEUN < inftl->nb_blocks) {
817-
if (MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize) +
818-
blockofs, 8, &retlen, (char *)&bci) < 0)
823+
if (mtd->read_oob(mtd, (thisEUN * inftl->EraseSize) +
824+
blockofs, 8, &retlen, (char *)&bci) < 0)
819825
status = SECTOR_IGNORE;
820826
else
821827
status = bci.Status | bci.Status1;
@@ -853,8 +859,7 @@ static int inftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
853859
} else {
854860
size_t retlen;
855861
loff_t ptr = (thisEUN * inftl->EraseSize) + blockofs;
856-
if (MTD_READ(inftl->mbd.mtd, ptr, SECTORSIZE, &retlen,
857-
buffer))
862+
if (mtd->read(mtd, ptr, SECTORSIZE, &retlen, buffer))
858863
return -EIO;
859864
}
860865
return 0;

‎drivers/mtd/inftlmount.c‎

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static int find_boot_record(struct INFTLrecord *inftl)
5757
unsigned int i, block;
5858
u8 buf[SECTORSIZE];
5959
struct INFTLMediaHeader *mh = &inftl->MediaHdr;
60+
struct mtd_info *mtd = inftl->mbd.mtd;
6061
struct INFTLPartition *ip;
6162
size_t retlen;
6263

@@ -80,8 +81,8 @@ static int find_boot_record(struct INFTLrecord *inftl)
8081
* Check for BNAND header first. Then whinge if it's found
8182
* but later checks fail.
8283
*/
83-
ret = MTD_READ(inftl->mbd.mtd, block * inftl->EraseSize,
84-
SECTORSIZE, &retlen, buf);
84+
ret = mtd->read(mtd, block * inftl->EraseSize,
85+
SECTORSIZE, &retlen, buf);
8586
/* We ignore ret in case the ECC of the MediaHeader is invalid
8687
(which is apparently acceptable) */
8788
if (retlen != SECTORSIZE) {
@@ -106,8 +107,9 @@ static int find_boot_record(struct INFTLrecord *inftl)
106107
}
107108

108109
/* To be safer with BIOS, also use erase mark as discriminant */
109-
if ((ret = MTD_READOOB(inftl->mbd.mtd, block * inftl->EraseSize +
110-
SECTORSIZE + 8, 8, &retlen, (char *)&h1) < 0)) {
110+
if ((ret = mtd->read_oob(mtd, block * inftl->EraseSize +
111+
SECTORSIZE + 8, 8, &retlen,
112+
(char *)&h1) < 0)) {
111113
printk(KERN_WARNING "INFTL: ANAND header found at "
112114
"0x%x in mtd%d, but OOB data read failed "
113115
"(err %d)\n", block * inftl->EraseSize,
@@ -123,8 +125,8 @@ static int find_boot_record(struct INFTLrecord *inftl)
123125
memcpy(mh, buf, sizeof(struct INFTLMediaHeader));
124126

125127
/* Read the spare media header at offset 4096 */
126-
MTD_READ(inftl->mbd.mtd, block * inftl->EraseSize + 4096,
127-
SECTORSIZE, &retlen, buf);
128+
mtd->read(mtd, block * inftl->EraseSize + 4096,
129+
SECTORSIZE, &retlen, buf);
128130
if (retlen != SECTORSIZE) {
129131
printk(KERN_WARNING "INFTL: Unable to read spare "
130132
"Media Header\n");
@@ -233,7 +235,7 @@ static int find_boot_record(struct INFTLrecord *inftl)
233235
*/
234236
instr->addr = ip->Reserved0 * inftl->EraseSize;
235237
instr->len = inftl->EraseSize;
236-
MTD_ERASE(inftl->mbd.mtd, instr);
238+
mtd->erase(mtd, instr);
237239
}
238240
if ((ip->lastUnit - ip->firstUnit + 1) < ip->virtualUnits) {
239241
printk(KERN_WARNING "INFTL: Media Header "
@@ -387,6 +389,7 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block)
387389
size_t retlen;
388390
struct inftl_unittail uci;
389391
struct erase_info *instr = &inftl->instr;
392+
struct mtd_info *mtd = inftl->mbd.mtd;
390393
int physblock;
391394

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

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

416420
/*
417-
* Check the "freeness" of Erase Unit before updating metadata.
418-
* FixMe: is this check really necessary? Since we have check the
419-
* return code after the erase operation.
420-
*/
421+
* Check the "freeness" of Erase Unit before updating metadata.
422+
* FixMe: is this check really necessary? Since we have check
423+
* the return code after the erase operation.
424+
*/
421425
if (check_free_sectors(inftl, instr->addr, instr->len, 1) != 0)
422426
goto fail;
423427
}
@@ -429,8 +433,7 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block)
429433
uci.Reserved[2] = 0;
430434
uci.Reserved[3] = 0;
431435
instr->addr = block * inftl->EraseSize + SECTORSIZE * 2;
432-
if (MTD_WRITEOOB(inftl->mbd.mtd, instr->addr +
433-
8, 8, &retlen, (char *)&uci) < 0)
436+
if (mtd->write_oob(mtd, instr->addr + 8, 8, &retlen, (char *)&uci) < 0)
434437
goto fail;
435438
return 0;
436439
fail:
@@ -549,6 +552,7 @@ void INFTL_dumpVUchains(struct INFTLrecord *s)
549552

550553
int INFTL_mount(struct INFTLrecord *s)
551554
{
555+
struct mtd_info *mtd = s->mbd.mtd;
552556
unsigned int block, first_block, prev_block, last_block;
553557
unsigned int first_logical_block, logical_block, erase_mark;
554558
int chain_length, do_format_chain;
@@ -607,10 +611,11 @@ int INFTL_mount(struct INFTLrecord *s)
607611
break;
608612
}
609613

610-
if (MTD_READOOB(s->mbd.mtd, block * s->EraseSize + 8,
611-
8, &retlen, (char *)&h0) < 0 ||
612-
MTD_READOOB(s->mbd.mtd, block * s->EraseSize +
613-
2 * SECTORSIZE + 8, 8, &retlen, (char *)&h1) < 0) {
614+
if (mtd->read_oob(mtd, block * s->EraseSize + 8,
615+
8, &retlen, (char *)&h0) < 0 ||
616+
mtd->read_oob(mtd, block * s->EraseSize +
617+
2 * SECTORSIZE + 8, 8, &retlen,
618+
(char *)&h1) < 0) {
614619
/* Should never happen? */
615620
do_format_chain++;
616621
break;

‎drivers/mtd/maps/nettel.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ int nettel_eraseconfig(void)
190190
set_current_state(TASK_INTERRUPTIBLE);
191191
add_wait_queue(&wait_q, &wait);
192192

193-
ret = MTD_ERASE(mtd, &nettel_erase);
193+
ret = mtd->erase(mtd, &nettel_erase);
194194
if (ret) {
195195
set_current_state(TASK_RUNNING);
196196
remove_wait_queue(&wait_q, &wait);

‎drivers/mtd/mtdblock.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static int erase_write (struct mtd_info *mtd, unsigned long pos,
7171
set_current_state(TASK_INTERRUPTIBLE);
7272
add_wait_queue(&wait_q, &wait);
7373

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

91-
ret = MTD_WRITE (mtd, pos, len, &retlen, buf);
91+
ret = mtd->write(mtd, pos, len, &retlen, buf);
9292
if (ret)
9393
return ret;
9494
if (retlen != len)
@@ -138,7 +138,7 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
138138
mtd->name, pos, len);
139139

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

143143
while (len > 0) {
144144
unsigned long sect_start = (pos/sect_size)*sect_size;
@@ -170,7 +170,8 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
170170
mtdblk->cache_offset != sect_start) {
171171
/* fill the cache with the current sector */
172172
mtdblk->cache_state = STATE_EMPTY;
173-
ret = MTD_READ(mtd, sect_start, sect_size, &retlen, mtdblk->cache_data);
173+
ret = mtd->read(mtd, sect_start, sect_size,
174+
&retlen, mtdblk->cache_data);
174175
if (ret)
175176
return ret;
176177
if (retlen != sect_size)
@@ -207,7 +208,7 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
207208
mtd->name, pos, len);
208209

209210
if (!sect_size)
210-
return MTD_READ (mtd, pos, len, &retlen, buf);
211+
return mtd->read(mtd, pos, len, &retlen, buf);
211212

212213
while (len > 0) {
213214
unsigned long sect_start = (pos/sect_size)*sect_size;
@@ -226,7 +227,7 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
226227
mtdblk->cache_offset == sect_start) {
227228
memcpy (buf, mtdblk->cache_data + offset, size);
228229
} else {
229-
ret = MTD_READ (mtd, pos, size, &retlen, buf);
230+
ret = mtd->read(mtd, pos, size, &retlen, buf);
230231
if (ret)
231232
return ret;
232233
if (retlen != size)

‎drivers/mtd/mtdchar.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
194194
ret = mtd->read_user_prot_reg(mtd, *ppos, len, &retlen, kbuf);
195195
break;
196196
default:
197-
ret = MTD_READ(mtd, *ppos, len, &retlen, kbuf);
197+
ret = mtd->read(mtd, *ppos, len, &retlen, kbuf);
198198
}
199199
/* Nand returns -EBADMSG on ecc errors, but it returns
200200
* the data. For our userspace tools it is important
@@ -205,7 +205,7 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
205205
if (!ret || (ret == -EBADMSG)) {
206206
*ppos += retlen;
207207
if (copy_to_user(buf, kbuf, retlen)) {
208-
kfree(kbuf);
208+
kfree(kbuf);
209209
return -EFAULT;
210210
}
211211
else

0 commit comments

Comments
 (0)