]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
mtd: nand: raw: rockchip_nfc: fix oobfree length calculation
authorJohan Jonker <jbx6244@gmail.com>
Tue, 30 Jun 2026 13:32:46 +0000 (15:32 +0200)
committerQuentin Schulz <u-boot@0leil.net>
Thu, 9 Jul 2026 17:49:22 +0000 (19:49 +0200)
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.

Fixes: 1b3fcb3c0456 ("mtd: nand: raw: rockchip_nfc: add layout structure")
Signed-off-by: Johan Jonker <jbx6244@gmail.com>
Tested-by: Hüseyin BIYIK <boogiepop@gmx.com>
Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>
Link: https://patch.msgid.link/12b6e0d5-637e-446e-9e4b-82c82e6fad40@gmail.com
Signed-off-by: Quentin Schulz <u-boot@0leil.net>
drivers/mtd/nand/raw/rockchip_nfc.c

index f730e15d04107fd1c9571c9a992f0f8a1e3ec637..ea8e67d1a23ef1a85072ec6dd837fb25f8830559 100644 (file)
@@ -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) {