Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Artem Bityutskiy and committed by
David Woodhouse
8f461a73 079c985e

+21 -20
+1 -4
drivers/mtd/mtdchar.c
··· 867 867 868 868 if (copy_from_user(&offs, argp, sizeof(loff_t))) 869 869 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); 874 871 break; 875 872 } 876 873
+1 -1
drivers/mtd/mtdconcat.c
··· 647 647 struct mtd_concat *concat = CONCAT(mtd); 648 648 int i, res = 0; 649 649 650 - if (!concat->subdev[0]->block_isbad) 650 + if (!mtd_can_have_bb(concat->subdev[0])) 651 651 return res; 652 652 653 653 if (ofs > mtd->size)
+2 -2
drivers/mtd/mtdoops.c
··· 169 169 cxt->nextpage = 0; 170 170 } 171 171 172 - while (mtd->block_isbad) { 172 + while (mtd_can_have_bb(mtd)) { 173 173 ret = mtd_block_isbad(mtd, cxt->nextpage * record_size); 174 174 if (!ret) 175 175 break; ··· 257 257 size_t retlen; 258 258 259 259 for (page = 0; page < cxt->oops_pages; page++) { 260 - if (mtd->block_isbad && 260 + if (mtd_can_have_bb(mtd) && 261 261 mtd_block_isbad(mtd, page * record_size)) 262 262 continue; 263 263 /* Assume the page is used */
+2 -2
drivers/mtd/mtdswap.c
··· 343 343 offset = mtdswap_eb_offset(d, eb); 344 344 345 345 /* 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)) 347 347 return MTDSWAP_SCANNED_BAD; 348 348 349 349 ops.ooblen = 2 * d->mtd->ecclayout->oobavail; ··· 1058 1058 1059 1059 badcnt = 0; 1060 1060 1061 - if (mtd->block_isbad) 1061 + if (mtd_can_have_bb(mtd)) 1062 1062 for (offset = 0; offset < size; offset += mtd->erasesize) 1063 1063 if (mtd_block_isbad(mtd, offset)) 1064 1064 badcnt++;
+1 -1
drivers/mtd/nftlcore.c
··· 56 56 if (memcmp(mtd->name, "DiskOnChip", 10)) 57 57 return; 58 58 59 - if (!mtd->block_isbad) { 59 + if (!mtd_can_have_bb(mtd)) { 60 60 printk(KERN_ERR 61 61 "NFTL no longer supports the old DiskOnChip drivers loaded via docprobe.\n" 62 62 "Please use the new diskonchip driver under the NAND subsystem.\n");
+2 -2
drivers/mtd/redboot.c
··· 78 78 79 79 if ( directory < 0 ) { 80 80 offset = master->size + directory * master->erasesize; 81 - while (master->block_isbad && 81 + while (mtd_can_have_bb(master) && 82 82 mtd_block_isbad(master, offset)) { 83 83 if (!offset) { 84 84 nogood: ··· 89 89 } 90 90 } else { 91 91 offset = directory * master->erasesize; 92 - while (master->block_isbad && 92 + while (mtd_can_have_bb(master) && 93 93 mtd_block_isbad(master, offset)) { 94 94 offset += master->erasesize; 95 95 if (offset == master->size)
+1 -2
drivers/mtd/tests/mtd_readtest.c
··· 148 148 return -ENOMEM; 149 149 } 150 150 151 - /* NOR flash does not implement block_isbad */ 152 - if (mtd->block_isbad == NULL) 151 + if (!mtd_can_have_bb(mtd)) 153 152 return 0; 154 153 155 154 printk(PRINT_PREF "scanning for bad eraseblocks\n");
+1 -2
drivers/mtd/tests/mtd_speedtest.c
··· 336 336 return -ENOMEM; 337 337 } 338 338 339 - /* NOR flash does not implement block_isbad */ 340 - if (mtd->block_isbad == NULL) 339 + if (!mtd_can_have_bb(mtd)) 341 340 goto out; 342 341 343 342 printk(PRINT_PREF "scanning for bad eraseblocks\n");
+1 -2
drivers/mtd/tests/mtd_stresstest.c
··· 227 227 return -ENOMEM; 228 228 } 229 229 230 - /* NOR flash does not implement block_isbad */ 231 - if (mtd->block_isbad == NULL) 230 + if (!mtd_can_have_bb(mtd)) 232 231 return 0; 233 232 234 233 printk(PRINT_PREF "scanning for bad eraseblocks\n");
+1 -1
drivers/mtd/tests/mtd_torturetest.c
··· 290 290 * Check if there is a bad eraseblock among those we are going to test. 291 291 */ 292 292 memset(&bad_ebs[0], 0, sizeof(int) * ebcnt); 293 - if (mtd->block_isbad) { 293 + if (mtd_can_have_bb(mtd)) { 294 294 for (i = eb; i < eb + ebcnt; i++) { 295 295 err = mtd_block_isbad(mtd, (loff_t)i * mtd->erasesize); 296 296
+1 -1
drivers/mtd/ubi/build.c
··· 664 664 ubi->peb_count = mtd_div_by_eb(ubi->mtd->size, ubi->mtd); 665 665 ubi->flash_size = ubi->mtd->size; 666 666 667 - if (ubi->mtd->block_isbad && ubi->mtd->block_markbad) 667 + if (mtd_can_have_bb(ubi->mtd)) 668 668 ubi->bad_allowed = 1; 669 669 670 670 if (ubi->mtd->type == MTD_NORFLASH) {
+7
include/linux/mtd/mtd.h
··· 440 440 441 441 static inline int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs) 442 442 { 443 + if (!mtd->block_isbad) 444 + return -EOPNOTSUPP; 443 445 return mtd->block_isbad(mtd, ofs); 444 446 } 445 447 ··· 483 481 static inline int mtd_has_oob(const struct mtd_info *mtd) 484 482 { 485 483 return mtd->read_oob && mtd->write_oob; 484 + } 485 + 486 + static inline int mtd_can_have_bb(const struct mtd_info *mtd) 487 + { 488 + return !!mtd->block_isbad; 486 489 } 487 490 488 491 /* Kernel-side ioctl definitions */