Skip to content

Commit 8f461a7

Browse files
dedekindDavid Woodhouse
authored andcommitted
mtd: introduce mtd_can_have_bb helper
This patch introduces new 'mtd_can_have_bb()' helper function which checks whether the flash can have bad eraseblocks. Then it changes all the direct 'mtd->block_isbad' use cases with 'mtd_can_have_bb()'. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent 079c985 commit 8f461a7

12 files changed

Lines changed: 21 additions & 20 deletions

File tree

‎drivers/mtd/mtdchar.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -867,10 +867,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
867867

868868
if (copy_from_user(&offs, argp, sizeof(loff_t)))
869869
return -EFAULT;
870-
if (!mtd->block_isbad)
871-
ret = -EOPNOTSUPP;
872-
else
873-
return mtd_block_isbad(mtd, offs);
870+
return mtd_block_isbad(mtd, offs);
874871
break;
875872
}
876873

‎drivers/mtd/mtdconcat.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ static int concat_block_isbad(struct mtd_info *mtd, loff_t ofs)
647647
struct mtd_concat *concat = CONCAT(mtd);
648648
int i, res = 0;
649649

650-
if (!concat->subdev[0]->block_isbad)
650+
if (!mtd_can_have_bb(concat->subdev[0]))
651651
return res;
652652

653653
if (ofs > mtd->size)

‎drivers/mtd/mtdoops.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static void mtdoops_workfunc_erase(struct work_struct *work)
169169
cxt->nextpage = 0;
170170
}
171171

172-
while (mtd->block_isbad) {
172+
while (mtd_can_have_bb(mtd)) {
173173
ret = mtd_block_isbad(mtd, cxt->nextpage * record_size);
174174
if (!ret)
175175
break;
@@ -257,7 +257,7 @@ static void find_next_position(struct mtdoops_context *cxt)
257257
size_t retlen;
258258

259259
for (page = 0; page < cxt->oops_pages; page++) {
260-
if (mtd->block_isbad &&
260+
if (mtd_can_have_bb(mtd) &&
261261
mtd_block_isbad(mtd, page * record_size))
262262
continue;
263263
/* Assume the page is used */

‎drivers/mtd/mtdswap.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ static int mtdswap_read_markers(struct mtdswap_dev *d, struct swap_eb *eb)
343343
offset = mtdswap_eb_offset(d, eb);
344344

345345
/* Check first if the block is bad. */
346-
if (d->mtd->block_isbad && mtd_block_isbad(d->mtd, offset))
346+
if (mtd_can_have_bb(d->mtd) && mtd_block_isbad(d->mtd, offset))
347347
return MTDSWAP_SCANNED_BAD;
348348

349349
ops.ooblen = 2 * d->mtd->ecclayout->oobavail;
@@ -1058,7 +1058,7 @@ static unsigned int mtdswap_badblocks(struct mtd_info *mtd, uint64_t size)
10581058

10591059
badcnt = 0;
10601060

1061-
if (mtd->block_isbad)
1061+
if (mtd_can_have_bb(mtd))
10621062
for (offset = 0; offset < size; offset += mtd->erasesize)
10631063
if (mtd_block_isbad(mtd, offset))
10641064
badcnt++;

‎drivers/mtd/nftlcore.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static void nftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
5656
if (memcmp(mtd->name, "DiskOnChip", 10))
5757
return;
5858

59-
if (!mtd->block_isbad) {
59+
if (!mtd_can_have_bb(mtd)) {
6060
printk(KERN_ERR
6161
"NFTL no longer supports the old DiskOnChip drivers loaded via docprobe.\n"
6262
"Please use the new diskonchip driver under the NAND subsystem.\n");

‎drivers/mtd/redboot.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static int parse_redboot_partitions(struct mtd_info *master,
7878

7979
if ( directory < 0 ) {
8080
offset = master->size + directory * master->erasesize;
81-
while (master->block_isbad &&
81+
while (mtd_can_have_bb(master) &&
8282
mtd_block_isbad(master, offset)) {
8383
if (!offset) {
8484
nogood:
@@ -89,7 +89,7 @@ static int parse_redboot_partitions(struct mtd_info *master,
8989
}
9090
} else {
9191
offset = directory * master->erasesize;
92-
while (master->block_isbad &&
92+
while (mtd_can_have_bb(master) &&
9393
mtd_block_isbad(master, offset)) {
9494
offset += master->erasesize;
9595
if (offset == master->size)

‎drivers/mtd/tests/mtd_readtest.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ static int scan_for_bad_eraseblocks(void)
148148
return -ENOMEM;
149149
}
150150

151-
/* NOR flash does not implement block_isbad */
152-
if (mtd->block_isbad == NULL)
151+
if (!mtd_can_have_bb(mtd))
153152
return 0;
154153

155154
printk(PRINT_PREF "scanning for bad eraseblocks\n");

‎drivers/mtd/tests/mtd_speedtest.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,7 @@ static int scan_for_bad_eraseblocks(void)
336336
return -ENOMEM;
337337
}
338338

339-
/* NOR flash does not implement block_isbad */
340-
if (mtd->block_isbad == NULL)
339+
if (!mtd_can_have_bb(mtd))
341340
goto out;
342341

343342
printk(PRINT_PREF "scanning for bad eraseblocks\n");

‎drivers/mtd/tests/mtd_stresstest.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,7 @@ static int scan_for_bad_eraseblocks(void)
227227
return -ENOMEM;
228228
}
229229

230-
/* NOR flash does not implement block_isbad */
231-
if (mtd->block_isbad == NULL)
230+
if (!mtd_can_have_bb(mtd))
232231
return 0;
233232

234233
printk(PRINT_PREF "scanning for bad eraseblocks\n");

‎drivers/mtd/tests/mtd_torturetest.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ static int __init tort_init(void)
290290
* Check if there is a bad eraseblock among those we are going to test.
291291
*/
292292
memset(&bad_ebs[0], 0, sizeof(int) * ebcnt);
293-
if (mtd->block_isbad) {
293+
if (mtd_can_have_bb(mtd)) {
294294
for (i = eb; i < eb + ebcnt; i++) {
295295
err = mtd_block_isbad(mtd, (loff_t)i * mtd->erasesize);
296296

0 commit comments

Comments
 (0)