mtd: nand: raw: rockchip_nfc: fix oobfree length calculation
Subsystems (3)
PATCH 1/1 mtd: nand: raw: rockchip_nfc: fix oobfree length calculation
The oobfree[0].length calculation depends on the rknand->metadata_size value, but this is calculated after the function rk_nfc_ecc_init is called. Move this calculation to a location before it's value is required.
--- drivers/mtd/nand/raw/rockchip_nfc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/mtd/nand/raw/rockchip_nfc.c +9 -9
@@ -861,6 +861,15 @@ static int rk_nfc_ecc_init(struct rk_nfc *nfc, struct nand_chip *chip) ecc->steps = mtd->writesize / ecc->size; ecc->bytes =DIV_ROUND_UP (ecc->strength *fls (8 * chip->ecc.size),8 ); + rknand->metadata_size =NFC_SYS_DATA_SIZE * ecc->steps; + +if (rknand->metadata_size <NFC_SYS_DATA_SIZE +2 ) { +dev_err (nfc->dev, +"driver needs at least %d bytes of meta data\n" , +NFC_SYS_DATA_SIZE +2 ); +return -EIO ; + } +if (ecc->bytes * ecc->steps > mtd->oobsize - rknand->metadata_size)return -EINVAL ;
@@ -974,15 +983,6 @@ static int rk_nfc_nand_chip_init(ofnode node, struct rk_nfc *nfc, int devnum) ret =ofnode_read_u32 (node,"rockchip,boot-ecc-strength" , &tmp); rknand->boot_ecc = ret ? ecc->strength : tmp; - rknand->metadata_size =NFC_SYS_DATA_SIZE * ecc->steps; - -if (rknand->metadata_size <NFC_SYS_DATA_SIZE +2 ) { -dev_err (dev, -"driver needs at least %d bytes of meta data\n" , -NFC_SYS_DATA_SIZE +2 ); -return -EIO ; - } -if (!nfc->page_buf) { nfc->page_buf =kzalloc (NFC_MAX_PAGE_SIZE ,GFP_KERNEL );if (!nfc->page_buf) {
Signature · 1 line
2.39.5
Hi Johan,
Thanks for the patch, i have tested this patch on my Medion MD98486 tablet, and it successfully fixes the issue.
Quoted 47 lines · Johan Jonker
The oobfree[0].length calculation depends on the
rknand->metadata_sizevalue, but this is calculated after the functionrk_nfc_ecc_initis called. Move this calculation to a location before it's value is required.Fixes 1b3fcb3c0456 ("mtd: nand: raw: rockchip_nfc: add layout structure")Signed-off-by Johan Jonker <[email protected]>--- drivers/mtd/nand/raw/rockchip_nfc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)drivers/mtd/nand/raw/rockchip_nfc.c +9
-9@@ -861,6 +861,15 @@ static int rk_nfc_ecc_init(struct rk_nfc *nfc, struct nand_chip *chip) ecc->steps = mtd->writesize / ecc->size; ecc->bytes =DIV_ROUND_UP (ecc->strength *fls (8 * chip->ecc.size),8 ); + rknand->metadata_size =NFC_SYS_DATA_SIZE * ecc->steps; + +if (rknand->metadata_size <NFC_SYS_DATA_SIZE +2 ) { +dev_err (nfc->dev, +"driver needs at least %d bytes of meta data\n" , +NFC_SYS_DATA_SIZE +2 ); +return -EIO ; + } +if (ecc->bytes * ecc->steps > mtd->oobsize - rknand->metadata_size)return -EINVAL ;@@ -974,15 +983,6 @@ static int rk_nfc_nand_chip_init(ofnode node, struct rk_nfc *nfc, int devnum) ret =ofnode_read_u32 (node,"rockchip,boot-ecc-strength" , &tmp); rknand->boot_ecc = ret ? ecc->strength : tmp; - rknand->metadata_size =NFC_SYS_DATA_SIZE * ecc->steps; - -if (rknand->metadata_size <NFC_SYS_DATA_SIZE +2 ) { -dev_err (dev, -"driver needs at least %d bytes of meta data\n" , -NFC_SYS_DATA_SIZE +2 ); -return -EIO ; - } -if (!nfc->page_buf) { nfc->page_buf =kzalloc (NFC_MAX_PAGE_SIZE ,GFP_KERNEL );if (!nfc->page_buf) {
Hi Johan,
Quoted 1 line · Johan Jonker
The oobfree[0].length calculation depends on the
Not only that, but also ecc->layout->eccpos[i] just above.
Quoted 5 lines
rknand->metadata_sizevalue, but this is calculated after the functionrk_nfc_ecc_initis called. Move this calculation to a location before it's value is required.Fixes 1b3fcb3c0456 ("mtd: nand: raw: rockchip_nfc: add layout structure")
Thanks!
Quentin
Quoted 4 lines · Johan Jonker
The oobfree[0].length calculation depends on the
rknand->metadata_sizevalue, but this is calculated after the functionrk_nfc_ecc_initis called. Move this calculation to a location before it's value is required.
Applied to https://git.u-boot-project.org/u-boot/custodians/u-boot-rockchip (u-boot-rockchip-2026.10), thanks!
[1/1] mtd: nand: raw: rockchip_nfc: fix oobfree length calculation
https://git.u-boot-project.org/u-boot/custodians/u-boot-rockchip/-/commit/3f6d1416a89cc213ddf1f1f41dc0cda84b896b5c
Best regards,
Signature · 1 line
Quentin Schulz <[email protected]>