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

mtd: nand: don't select chip in nand_chip's block_bad op

One of the arguments passed to struct nand_chip's block_bad op is
'getchip', which, if true, is supposed to get and select the nand device,
and later unselect and release the device.

This op is intended to be replaceable by drivers. The drivers shouldn't
be responsible for selecting/unselecting chip. Like other ops, the chip
should already be selected before the block_bad op is called.

Remove the getchip argument from the block_bad op and
nand_block_checkbad. Move the chip selection to nand_block_isbad, since it
is the only caller to nand_block_checkbad which requires chip selection.

Modify nand_block_bad (the default function for the op) such that it
doesn't select the chip.

Remove the getchip argument from the bad_block funcs in cafe_nand,
diskonchip and docg4 drivers.

Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Archit Taneja <architt@codeaurora.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>

authored by

Archit Taneja and committed by
Brian Norris
9f3e0429 9648388f

+23 -26
+1 -1
drivers/mtd/nand/cafe_nand.c
··· 537 537 return 0; 538 538 } 539 539 540 - static int cafe_nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) 540 + static int cafe_nand_block_bad(struct mtd_info *mtd, loff_t ofs) 541 541 { 542 542 return 0; 543 543 }
+1 -1
drivers/mtd/nand/diskonchip.c
··· 794 794 } 795 795 } 796 796 797 - static int doc200x_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) 797 + static int doc200x_block_bad(struct mtd_info *mtd, loff_t ofs) 798 798 { 799 799 /* This is our last resort if we couldn't find or create a BBT. Just 800 800 pretend all blocks are good. */
+1 -1
drivers/mtd/nand/docg4.c
··· 1120 1120 return ret; 1121 1121 } 1122 1122 1123 - static int docg4_block_neverbad(struct mtd_info *mtd, loff_t ofs, int getchip) 1123 + static int docg4_block_neverbad(struct mtd_info *mtd, loff_t ofs) 1124 1124 { 1125 1125 /* only called when module_param ignore_badblocks is set */ 1126 1126 return 0;
+19 -22
drivers/mtd/nand/nand_base.c
··· 317 317 * 318 318 * Check, if the block is bad. 319 319 */ 320 - static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) 320 + static int nand_block_bad(struct mtd_info *mtd, loff_t ofs) 321 321 { 322 - int page, chipnr, res = 0, i = 0; 322 + int page, res = 0, i = 0; 323 323 struct nand_chip *chip = mtd_to_nand(mtd); 324 324 u16 bad; 325 325 ··· 327 327 ofs += mtd->erasesize - mtd->writesize; 328 328 329 329 page = (int)(ofs >> chip->page_shift) & chip->pagemask; 330 - 331 - if (getchip) { 332 - chipnr = (int)(ofs >> chip->chip_shift); 333 - 334 - nand_get_device(mtd, FL_READING); 335 - 336 - /* Select the NAND device */ 337 - chip->select_chip(mtd, chipnr); 338 - } 339 330 340 331 do { 341 332 if (chip->options & NAND_BUSWIDTH_16) { ··· 351 360 page = (int)(ofs >> chip->page_shift) & chip->pagemask; 352 361 i++; 353 362 } while (!res && i < 2 && (chip->bbt_options & NAND_BBT_SCAN2NDPAGE)); 354 - 355 - if (getchip) { 356 - chip->select_chip(mtd, -1); 357 - nand_release_device(mtd); 358 - } 359 363 360 364 return res; 361 365 } ··· 489 503 * nand_block_checkbad - [GENERIC] Check if a block is marked bad 490 504 * @mtd: MTD device structure 491 505 * @ofs: offset from device start 492 - * @getchip: 0, if the chip is already selected 493 506 * @allowbbt: 1, if its allowed to access the bbt area 494 507 * 495 508 * Check, if the block is bad. Either by reading the bad block table or 496 509 * calling of the scan function. 497 510 */ 498 - static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int getchip, 499 - int allowbbt) 511 + static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int allowbbt) 500 512 { 501 513 struct nand_chip *chip = mtd_to_nand(mtd); 502 514 503 515 if (!chip->bbt) 504 - return chip->block_bad(mtd, ofs, getchip); 516 + return chip->block_bad(mtd, ofs); 505 517 506 518 /* Return info from the table */ 507 519 return nand_isbad_bbt(mtd, ofs, allowbbt); ··· 2933 2949 while (len) { 2934 2950 /* Check if we have a bad block, we do not erase bad blocks! */ 2935 2951 if (nand_block_checkbad(mtd, ((loff_t) page) << 2936 - chip->page_shift, 0, allowbbt)) { 2952 + chip->page_shift, allowbbt)) { 2937 2953 pr_warn("%s: attempt to erase a bad block at page 0x%08x\n", 2938 2954 __func__, page); 2939 2955 instr->state = MTD_ERASE_FAILED; ··· 3020 3036 */ 3021 3037 static int nand_block_isbad(struct mtd_info *mtd, loff_t offs) 3022 3038 { 3023 - return nand_block_checkbad(mtd, offs, 1, 0); 3039 + struct nand_chip *chip = mtd_to_nand(mtd); 3040 + int chipnr = (int)(offs >> chip->chip_shift); 3041 + int ret; 3042 + 3043 + /* Select the NAND device */ 3044 + nand_get_device(mtd, FL_READING); 3045 + chip->select_chip(mtd, chipnr); 3046 + 3047 + ret = nand_block_checkbad(mtd, offs, 0); 3048 + 3049 + chip->select_chip(mtd, -1); 3050 + nand_release_device(mtd); 3051 + 3052 + return ret; 3024 3053 } 3025 3054 3026 3055 /**
+1 -1
include/linux/mtd/nand.h
··· 672 672 void (*write_buf)(struct mtd_info *mtd, const uint8_t *buf, int len); 673 673 void (*read_buf)(struct mtd_info *mtd, uint8_t *buf, int len); 674 674 void (*select_chip)(struct mtd_info *mtd, int chip); 675 - int (*block_bad)(struct mtd_info *mtd, loff_t ofs, int getchip); 675 + int (*block_bad)(struct mtd_info *mtd, loff_t ofs); 676 676 int (*block_markbad)(struct mtd_info *mtd, loff_t ofs); 677 677 void (*cmd_ctrl)(struct mtd_info *mtd, int dat, unsigned int ctrl); 678 678 int (*dev_ready)(struct mtd_info *mtd);