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>
This commit is contained in:
parent
079c985e7a
commit
8f461a7302
|
@ -867,10 +867,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
|
||||||
|
|
||||||
if (copy_from_user(&offs, argp, sizeof(loff_t)))
|
if (copy_from_user(&offs, argp, sizeof(loff_t)))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
if (!mtd->block_isbad)
|
return mtd_block_isbad(mtd, offs);
|
||||||
ret = -EOPNOTSUPP;
|
|
||||||
else
|
|
||||||
return mtd_block_isbad(mtd, offs);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -647,7 +647,7 @@ static int concat_block_isbad(struct mtd_info *mtd, loff_t ofs)
|
||||||
struct mtd_concat *concat = CONCAT(mtd);
|
struct mtd_concat *concat = CONCAT(mtd);
|
||||||
int i, res = 0;
|
int i, res = 0;
|
||||||
|
|
||||||
if (!concat->subdev[0]->block_isbad)
|
if (!mtd_can_have_bb(concat->subdev[0]))
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
if (ofs > mtd->size)
|
if (ofs > mtd->size)
|
||||||
|
|
|
@ -169,7 +169,7 @@ static void mtdoops_workfunc_erase(struct work_struct *work)
|
||||||
cxt->nextpage = 0;
|
cxt->nextpage = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (mtd->block_isbad) {
|
while (mtd_can_have_bb(mtd)) {
|
||||||
ret = mtd_block_isbad(mtd, cxt->nextpage * record_size);
|
ret = mtd_block_isbad(mtd, cxt->nextpage * record_size);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
break;
|
break;
|
||||||
|
@ -257,7 +257,7 @@ static void find_next_position(struct mtdoops_context *cxt)
|
||||||
size_t retlen;
|
size_t retlen;
|
||||||
|
|
||||||
for (page = 0; page < cxt->oops_pages; page++) {
|
for (page = 0; page < cxt->oops_pages; page++) {
|
||||||
if (mtd->block_isbad &&
|
if (mtd_can_have_bb(mtd) &&
|
||||||
mtd_block_isbad(mtd, page * record_size))
|
mtd_block_isbad(mtd, page * record_size))
|
||||||
continue;
|
continue;
|
||||||
/* Assume the page is used */
|
/* Assume the page is used */
|
||||||
|
|
|
@ -343,7 +343,7 @@ static int mtdswap_read_markers(struct mtdswap_dev *d, struct swap_eb *eb)
|
||||||
offset = mtdswap_eb_offset(d, eb);
|
offset = mtdswap_eb_offset(d, eb);
|
||||||
|
|
||||||
/* Check first if the block is bad. */
|
/* Check first if the block is bad. */
|
||||||
if (d->mtd->block_isbad && mtd_block_isbad(d->mtd, offset))
|
if (mtd_can_have_bb(d->mtd) && mtd_block_isbad(d->mtd, offset))
|
||||||
return MTDSWAP_SCANNED_BAD;
|
return MTDSWAP_SCANNED_BAD;
|
||||||
|
|
||||||
ops.ooblen = 2 * d->mtd->ecclayout->oobavail;
|
ops.ooblen = 2 * d->mtd->ecclayout->oobavail;
|
||||||
|
@ -1058,7 +1058,7 @@ static unsigned int mtdswap_badblocks(struct mtd_info *mtd, uint64_t size)
|
||||||
|
|
||||||
badcnt = 0;
|
badcnt = 0;
|
||||||
|
|
||||||
if (mtd->block_isbad)
|
if (mtd_can_have_bb(mtd))
|
||||||
for (offset = 0; offset < size; offset += mtd->erasesize)
|
for (offset = 0; offset < size; offset += mtd->erasesize)
|
||||||
if (mtd_block_isbad(mtd, offset))
|
if (mtd_block_isbad(mtd, offset))
|
||||||
badcnt++;
|
badcnt++;
|
||||||
|
|
|
@ -56,7 +56,7 @@ static void nftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
|
||||||
if (memcmp(mtd->name, "DiskOnChip", 10))
|
if (memcmp(mtd->name, "DiskOnChip", 10))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!mtd->block_isbad) {
|
if (!mtd_can_have_bb(mtd)) {
|
||||||
printk(KERN_ERR
|
printk(KERN_ERR
|
||||||
"NFTL no longer supports the old DiskOnChip drivers loaded via docprobe.\n"
|
"NFTL no longer supports the old DiskOnChip drivers loaded via docprobe.\n"
|
||||||
"Please use the new diskonchip driver under the NAND subsystem.\n");
|
"Please use the new diskonchip driver under the NAND subsystem.\n");
|
||||||
|
|
|
@ -78,7 +78,7 @@ static int parse_redboot_partitions(struct mtd_info *master,
|
||||||
|
|
||||||
if ( directory < 0 ) {
|
if ( directory < 0 ) {
|
||||||
offset = master->size + directory * master->erasesize;
|
offset = master->size + directory * master->erasesize;
|
||||||
while (master->block_isbad &&
|
while (mtd_can_have_bb(master) &&
|
||||||
mtd_block_isbad(master, offset)) {
|
mtd_block_isbad(master, offset)) {
|
||||||
if (!offset) {
|
if (!offset) {
|
||||||
nogood:
|
nogood:
|
||||||
|
@ -89,7 +89,7 @@ static int parse_redboot_partitions(struct mtd_info *master,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
offset = directory * master->erasesize;
|
offset = directory * master->erasesize;
|
||||||
while (master->block_isbad &&
|
while (mtd_can_have_bb(master) &&
|
||||||
mtd_block_isbad(master, offset)) {
|
mtd_block_isbad(master, offset)) {
|
||||||
offset += master->erasesize;
|
offset += master->erasesize;
|
||||||
if (offset == master->size)
|
if (offset == master->size)
|
||||||
|
|
|
@ -148,8 +148,7 @@ static int scan_for_bad_eraseblocks(void)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NOR flash does not implement block_isbad */
|
if (!mtd_can_have_bb(mtd))
|
||||||
if (mtd->block_isbad == NULL)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
printk(PRINT_PREF "scanning for bad eraseblocks\n");
|
printk(PRINT_PREF "scanning for bad eraseblocks\n");
|
||||||
|
|
|
@ -336,8 +336,7 @@ static int scan_for_bad_eraseblocks(void)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NOR flash does not implement block_isbad */
|
if (!mtd_can_have_bb(mtd))
|
||||||
if (mtd->block_isbad == NULL)
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
printk(PRINT_PREF "scanning for bad eraseblocks\n");
|
printk(PRINT_PREF "scanning for bad eraseblocks\n");
|
||||||
|
|
|
@ -227,8 +227,7 @@ static int scan_for_bad_eraseblocks(void)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NOR flash does not implement block_isbad */
|
if (!mtd_can_have_bb(mtd))
|
||||||
if (mtd->block_isbad == NULL)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
printk(PRINT_PREF "scanning for bad eraseblocks\n");
|
printk(PRINT_PREF "scanning for bad eraseblocks\n");
|
||||||
|
|
|
@ -290,7 +290,7 @@ static int __init tort_init(void)
|
||||||
* Check if there is a bad eraseblock among those we are going to test.
|
* Check if there is a bad eraseblock among those we are going to test.
|
||||||
*/
|
*/
|
||||||
memset(&bad_ebs[0], 0, sizeof(int) * ebcnt);
|
memset(&bad_ebs[0], 0, sizeof(int) * ebcnt);
|
||||||
if (mtd->block_isbad) {
|
if (mtd_can_have_bb(mtd)) {
|
||||||
for (i = eb; i < eb + ebcnt; i++) {
|
for (i = eb; i < eb + ebcnt; i++) {
|
||||||
err = mtd_block_isbad(mtd, (loff_t)i * mtd->erasesize);
|
err = mtd_block_isbad(mtd, (loff_t)i * mtd->erasesize);
|
||||||
|
|
||||||
|
|
|
@ -664,7 +664,7 @@ static int io_init(struct ubi_device *ubi)
|
||||||
ubi->peb_count = mtd_div_by_eb(ubi->mtd->size, ubi->mtd);
|
ubi->peb_count = mtd_div_by_eb(ubi->mtd->size, ubi->mtd);
|
||||||
ubi->flash_size = ubi->mtd->size;
|
ubi->flash_size = ubi->mtd->size;
|
||||||
|
|
||||||
if (ubi->mtd->block_isbad && ubi->mtd->block_markbad)
|
if (mtd_can_have_bb(ubi->mtd))
|
||||||
ubi->bad_allowed = 1;
|
ubi->bad_allowed = 1;
|
||||||
|
|
||||||
if (ubi->mtd->type == MTD_NORFLASH) {
|
if (ubi->mtd->type == MTD_NORFLASH) {
|
||||||
|
|
|
@ -440,6 +440,8 @@ static inline void mtd_resume(struct mtd_info *mtd)
|
||||||
|
|
||||||
static inline int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs)
|
static inline int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs)
|
||||||
{
|
{
|
||||||
|
if (!mtd->block_isbad)
|
||||||
|
return -EOPNOTSUPP;
|
||||||
return mtd->block_isbad(mtd, ofs);
|
return mtd->block_isbad(mtd, ofs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -483,6 +485,11 @@ static inline int mtd_has_oob(const struct mtd_info *mtd)
|
||||||
return mtd->read_oob && mtd->write_oob;
|
return mtd->read_oob && mtd->write_oob;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int mtd_can_have_bb(const struct mtd_info *mtd)
|
||||||
|
{
|
||||||
|
return !!mtd->block_isbad;
|
||||||
|
}
|
||||||
|
|
||||||
/* Kernel-side ioctl definitions */
|
/* Kernel-side ioctl definitions */
|
||||||
|
|
||||||
struct mtd_partition;
|
struct mtd_partition;
|
||||||
|
|
Loading…
Reference in New Issue