[PATCH v1] mtd: nand: raw: rockchip_nfc: fix oobfree length calculation

boogie boogiepop at gmx.com
Sun Jul 5 22:03:02 CEST 2026


Hi Johan,

Thanks for the patch, i have tested this patch on my Medion MD98486 
tablet, and it successfully fixes the issue.

Tested-by: Hüseyin BIYIK <boogiepop at gmx.com>

On 6/30/26 15:32, Johan Jonker wrote:
> 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 at gmail.com>
> ---
>   drivers/mtd/nand/raw/rockchip_nfc.c | 18 +++++++++---------
>   1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/rockchip_nfc.c b/drivers/mtd/nand/raw/rockchip_nfc.c
> index f730e15d0410..ea8e67d1a23e 100644
> --- a/drivers/mtd/nand/raw/rockchip_nfc.c
> +++ b/drivers/mtd/nand/raw/rockchip_nfc.c
> @@ -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) {



More information about the U-Boot mailing list