Re: [PATCH v8 2/8] mtd: rawnand: rockchip: NFC drivers for RK3308, RK2928 and others
From: Miquel Raynal <miquel.raynal@bootlin.com>
Date: 2020-09-15 09:23:28
Also in:
linux-devicetree, linux-rockchip, lkml
Miquel Raynal [off-list ref] wrote on Tue, 15 Sep 2020 10:07:28 +0200:
Hi Yifeng, I am very sorry for the delay it took me to review this driver, but there are still some small incoherences IMHO, see below.
One last important comment below
quoted
+static int rk_nfc_attach_chip(struct nand_chip *chip) +{ + struct mtd_info *mtd = nand_to_mtd(chip); + struct device *dev = mtd->dev.parent; + struct rk_nfc *nfc = nand_get_controller_data(chip); + struct rk_nfc_nand_chip *rknand = to_rknand(chip); + struct nand_ecc_ctrl *ecc = &chip->ecc; + int len; + int ret; + + if (chip->options & NAND_BUSWIDTH_16) { + dev_err(dev, "16 bits bus width not supported"); + return -EINVAL; + } + + if (ecc->mode != NAND_ECC_HW) + return 0; + + ret = rk_nfc_ecc_init(dev, mtd); + if (ret) + return ret; + rknand->spare_per_sector = ecc->bytes + NFC_SYS_DATA_SIZE; + 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; + } + /* Check buffer first, avoid duplicate alloc buffer. */ + if (nfc->buffer) + return 0;You can't do that this way: what if the first mtd to be registered uses a smaller page size than the second?quoted
+ + len = mtd->writesize + mtd->oobsize; + nfc->buffer = devm_kzalloc(dev, len, GFP_KERNEL | GFP_DMA);
I don't think this fits your purpose. You should probably allocate with kzalloc or perhaps dma_alloc*. Then, you'll also have to free this memory.
quoted
+ if (!nfc->buffer) + return -ENOMEM; + + nfc->page_buf = nfc->buffer; + len = ecc->steps * NFC_MAX_OOB_PER_STEP; + nfc->oob_buf = devm_kzalloc(dev, len, GFP_KERNEL | GFP_DMA); + if (!nfc->oob_buf) { + nfc->buffer = NULL; + nfc->oob_buf = NULL;I don't think this is neededquoted
+ return -ENOMEM; + } + + chip->ecc.write_page_raw = rk_nfc_write_page_raw; + chip->ecc.write_page = rk_nfc_write_page_hwecc; + chip->ecc.write_oob_raw = rk_nfc_write_oob_std; + chip->ecc.write_oob = rk_nfc_write_oob_std; + + chip->ecc.read_page_raw = rk_nfc_read_page_raw; + chip->ecc.read_page = rk_nfc_read_page_hwecc; + chip->ecc.read_oob_raw = rk_nfc_read_oob_std; + chip->ecc.read_oob = rk_nfc_read_oob_std;I don't like the _std prefix, but it should be gone when splitting the functions as advised.quoted
+ + return 0; +}
Thanks, Miquèl _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel