Skip to content

Commit 4a78cc6

Browse files
author
Boris Brezillon
committed
mtd: nand: Make sure drivers not supporting SET/GET_FEATURES return -ENOTSUPP
A lot of drivers are providing their own ->cmdfunc(), and most of the time this implementation does not support all possible NAND operations. But since ->cmdfunc() cannot return an error code, the core has no way to know that the operation it requested is not supported. This is a problem we cannot address for all kind of operations with the current design, but we can prevent these silent failures for the GET/SET FEATURES operation by overloading the default ->onfi_{set,get}_features() methods with one returning -ENOTSUPP. Reported-by: Chris Packham <Chris.Packham@alliedtelesis.co.nz> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Tested-by: Chris Packham <Chris.Packham@alliedtelesis.co.nz>
1 parent cc0f51e commit 4a78cc6

15 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ int bcm47xxnflash_ops_bcm4706_init(struct bcm47xxnflash *b47n)
392392
b47n->nand_chip.read_byte = bcm47xxnflash_ops_bcm4706_read_byte;
393393
b47n->nand_chip.read_buf = bcm47xxnflash_ops_bcm4706_read_buf;
394394
b47n->nand_chip.write_buf = bcm47xxnflash_ops_bcm4706_write_buf;
395+
b47n->nand_chip.onfi_set_features = nand_onfi_get_set_features_notsupp;
396+
b47n->nand_chip.onfi_get_features = nand_onfi_get_set_features_notsupp;
395397

396398
nand_chip->chip_delay = 50;
397399
b47n->nand_chip.bbt_options = NAND_BBT_USE_FLASH;

‎drivers/mtd/nand/cafe_nand.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,8 @@ static int cafe_nand_probe(struct pci_dev *pdev,
654654
cafe->nand.read_buf = cafe_read_buf;
655655
cafe->nand.write_buf = cafe_write_buf;
656656
cafe->nand.select_chip = cafe_select_chip;
657+
cafe->nand.onfi_set_features = nand_onfi_get_set_features_notsupp;
658+
cafe->nand.onfi_get_features = nand_onfi_get_set_features_notsupp;
657659

658660
cafe->nand.chip_delay = 0;
659661

‎drivers/mtd/nand/denali.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,8 @@ int denali_init(struct denali_nand_info *denali)
15311531
chip->cmdfunc = denali_cmdfunc;
15321532
chip->read_byte = denali_read_byte;
15331533
chip->waitfunc = denali_waitfunc;
1534+
chip->onfi_set_features = nand_onfi_get_set_features_notsupp;
1535+
chip->onfi_get_features = nand_onfi_get_set_features_notsupp;
15341536

15351537
/*
15361538
* scan for NAND devices attached to the controller

‎drivers/mtd/nand/docg4.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,8 @@ static void __init init_mtd_structs(struct mtd_info *mtd)
12601260
nand->read_buf = docg4_read_buf;
12611261
nand->write_buf = docg4_write_buf16;
12621262
nand->erase = docg4_erase_block;
1263+
nand->onfi_set_features = nand_onfi_get_set_features_notsupp;
1264+
nand->onfi_get_features = nand_onfi_get_set_features_notsupp;
12631265
nand->ecc.read_page = docg4_read_page;
12641266
nand->ecc.write_page = docg4_write_page;
12651267
nand->ecc.read_page_raw = docg4_read_page_raw;

‎drivers/mtd/nand/fsl_elbc_nand.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,8 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
775775
chip->select_chip = fsl_elbc_select_chip;
776776
chip->cmdfunc = fsl_elbc_cmdfunc;
777777
chip->waitfunc = fsl_elbc_wait;
778+
chip->onfi_set_features = nand_onfi_get_set_features_notsupp;
779+
chip->onfi_get_features = nand_onfi_get_set_features_notsupp;
778780

779781
chip->bbt_td = &bbt_main_descr;
780782
chip->bbt_md = &bbt_mirror_descr;

‎drivers/mtd/nand/fsl_ifc_nand.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,8 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)
831831
chip->select_chip = fsl_ifc_select_chip;
832832
chip->cmdfunc = fsl_ifc_cmdfunc;
833833
chip->waitfunc = fsl_ifc_wait;
834+
chip->onfi_set_features = nand_onfi_get_set_features_notsupp;
835+
chip->onfi_get_features = nand_onfi_get_set_features_notsupp;
834836

835837
chip->bbt_td = &bbt_main_descr;
836838
chip->bbt_md = &bbt_mirror_descr;

‎drivers/mtd/nand/hisi504_nand.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static int hisi_nfc_probe(struct platform_device *pdev)
764764
chip->write_buf = hisi_nfc_write_buf;
765765
chip->read_buf = hisi_nfc_read_buf;
766766
chip->chip_delay = HINFC504_CHIP_DELAY;
767+
chip->onfi_set_features = nand_onfi_get_set_features_notsupp;
768+
chip->onfi_get_features = nand_onfi_get_set_features_notsupp;
767769

768770
hisi_nfc_host_init(host);
769771

‎drivers/mtd/nand/mpc5121_nfc.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,8 @@ static int mpc5121_nfc_probe(struct platform_device *op)
708708
chip->read_buf = mpc5121_nfc_read_buf;
709709
chip->write_buf = mpc5121_nfc_write_buf;
710710
chip->select_chip = mpc5121_nfc_select_chip;
711+
chip->onfi_set_features = nand_onfi_get_set_features_notsupp;
712+
chip->onfi_get_features = nand_onfi_get_set_features_notsupp;
711713
chip->bbt_options = NAND_BBT_USE_FLASH;
712714
chip->ecc.mode = NAND_ECC_SOFT;
713715
chip->ecc.algo = NAND_ECC_HAMMING;

‎drivers/mtd/nand/nand_base.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3420,6 +3420,25 @@ static int nand_onfi_get_features(struct mtd_info *mtd, struct nand_chip *chip,
34203420
return 0;
34213421
}
34223422

3423+
/**
3424+
* nand_onfi_get_set_features_notsupp - set/get features stub returning
3425+
* -ENOTSUPP
3426+
* @mtd: MTD device structure
3427+
* @chip: nand chip info structure
3428+
* @addr: feature address.
3429+
* @subfeature_param: the subfeature parameters, a four bytes array.
3430+
*
3431+
* Should be used by NAND controller drivers that do not support the SET/GET
3432+
* FEATURES operations.
3433+
*/
3434+
int nand_onfi_get_set_features_notsupp(struct mtd_info *mtd,
3435+
struct nand_chip *chip, int addr,
3436+
u8 *subfeature_param)
3437+
{
3438+
return -ENOTSUPP;
3439+
}
3440+
EXPORT_SYMBOL(nand_onfi_get_set_features_notsupp);
3441+
34233442
/**
34243443
* nand_suspend - [MTD Interface] Suspend the NAND flash
34253444
* @mtd: MTD device structure

‎drivers/mtd/nand/pxa3xx_nand.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,8 @@ static int alloc_nand_resource(struct platform_device *pdev)
18121812
chip->write_buf = pxa3xx_nand_write_buf;
18131813
chip->options |= NAND_NO_SUBPAGE_WRITE;
18141814
chip->cmdfunc = nand_cmdfunc;
1815+
chip->onfi_set_features = nand_onfi_get_set_features_notsupp;
1816+
chip->onfi_get_features = nand_onfi_get_set_features_notsupp;
18151817
}
18161818

18171819
nand_hw_control_init(chip->controller);

0 commit comments

Comments
 (0)