linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Yifeng Zhao <yifeng.zhao@rock-chips.com>
Cc: devicetree@vger.kernel.org, vigneshr@ti.com, richard@nod.at,
	linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org,
	robh+dt@kernel.org, linux-mtd@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org, heiko@sntech.de
Subject: Re: [PATCH v8 2/8] mtd: rawnand: rockchip: NFC drivers for RK3308, RK2928 and others
Date: Tue, 15 Sep 2020 11:23:15 +0200	[thread overview]
Message-ID: <20200915112315.310d89c8@xps13> (raw)
In-Reply-To: <20200915100728.5c866f89@xps13>


Miquel Raynal <miquel.raynal@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

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2020-09-15  9:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-17  9:24 [PATCH v8 0/8] Add Rockchip NFC drivers for RK3308 and others Yifeng Zhao
2020-07-17  9:24 ` [PATCH v8 1/8] dt-bindings: mtd: Describe Rockchip RK3xxx NAND flash controller Yifeng Zhao
2020-07-20 19:20   ` Rob Herring
2020-07-17  9:24 ` [PATCH v8 2/8] mtd: rawnand: rockchip: NFC drivers for RK3308, RK2928 and others Yifeng Zhao
2020-09-15  8:07   ` Miquel Raynal
2020-09-15  9:23     ` Miquel Raynal [this message]
2020-07-17  9:24 ` [PATCH v8 3/8] MAINTAINERS: add maintainers to ROCKCHIP NFC Yifeng Zhao
2020-07-17  9:24 ` [PATCH v8 4/8] arm64: dts: rockchip: Add NFC node for RK3308 SoC Yifeng Zhao
2020-07-17  9:25 ` [PATCH v8 5/8] arm64: dts: rockchip: Add NFC node for PX30 SoC Yifeng Zhao
2020-07-17  9:25   ` [PATCH v8 6/8] arm: dts: rockchip: Add NFC node for RV1108 SoC Yifeng Zhao
2020-07-17  9:25   ` [PATCH v8 7/8] arm: dts: rockchip: Add NFC node for RK2928 and other SoCs Yifeng Zhao
2020-07-17  9:25   ` [PATCH v8 8/8] arm: dts: rockchip: Add NFC node for RK3036 SoC Yifeng Zhao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200915112315.310d89c8@xps13 \
    --to=miquel.raynal@bootlin.com \
    --cc=devicetree@vger.kernel.org \
    --cc=heiko@sntech.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=richard@nod.at \
    --cc=robh+dt@kernel.org \
    --cc=vigneshr@ti.com \
    --cc=yifeng.zhao@rock-chips.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).