[PATCH v8 2/8] mtd: rawnand: rockchip: NFC drivers for RK3308, RK2928 and others

Miquel Raynal miquel.raynal at bootlin.com
Tue Sep 15 05:23:15 EDT 2020


Miquel Raynal <miquel.raynal at bootlin.com> 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

> > +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?
> 
> > +
> > +	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.

> > +	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 needed
> 
> > +		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.
> 
> > +
> > +	return 0;
> > +}

Thanks,
Miquèl



More information about the linux-arm-kernel mailing list