From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Arseniy Krasnov <avkrasnov@sberdevices.ru>
Cc: Liang Yang <liang.yang@amlogic.com>,
Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>,
Neil Armstrong <neil.armstrong@linaro.org>,
Kevin Hilman <khilman@baylibre.com>,
Jerome Brunet <jbrunet@baylibre.com>,
Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
<oxffffaa@gmail.com>, <kernel@sberdevices.ru>,
<linux-mtd@lists.infradead.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-amlogic@lists.infradead.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v1] mtd: rawnand: meson: check buffer length
Date: Tue, 6 Jun 2023 09:50:23 +0200 [thread overview]
Message-ID: <20230606095023.26a056a3@xps-13> (raw)
In-Reply-To: <e31be327-b351-3a94-b2d8-0867f29bb9ec@sberdevices.ru>
Hi Arseniy,
avkrasnov@sberdevices.ru wrote on Tue, 6 Jun 2023 10:37:43 +0300:
> On 06.06.2023 10:16, Miquel Raynal wrote:
> > Hi Arseniy,
> >
> > AVKrasnov@sberdevices.ru wrote on Mon, 5 Jun 2023 22:10:46 +0300:
> >
> >> Meson NAND controller has limited buffer length, so check it before
> >> command execution to avoid length trim. Also check MTD write size on
> >> chip attach.
> >
> > Almost there :)
>
> Hello Miquel!
>
> You mean to rephrase it? :)
Not at all, I meant: there is something to change in this file (see
below) but the patch is close to be ready.
>
> Thanks, Arseniy
>
> >
> >>
> >> Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
> >> ---
> >> drivers/mtd/nand/raw/meson_nand.c | 22 +++++++++++++++++++---
> >> 1 file changed, 19 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c
> >> index 074e14225c06..bfb5363cac23 100644
> >> --- a/drivers/mtd/nand/raw/meson_nand.c
> >> +++ b/drivers/mtd/nand/raw/meson_nand.c
> >> @@ -108,6 +108,8 @@
> >>
> >> #define PER_INFO_BYTE 8
> >>
> >> +#define NFC_CMD_RAW_LEN GENMASK(13, 0)
> >> +
> >> struct meson_nfc_nand_chip {
> >> struct list_head node;
> >> struct nand_chip nand;
> >> @@ -280,7 +282,7 @@ static void meson_nfc_cmd_access(struct nand_chip *nand, int raw, bool dir,
> >>
> >> if (raw) {
> >> len = mtd->writesize + mtd->oobsize;
> >> - cmd = (len & GENMASK(13, 0)) | scrambler | DMA_DIR(dir);
> >> + cmd = len | scrambler | DMA_DIR(dir);
> >> writel(cmd, nfc->reg_base + NFC_REG_CMD);
> >> return;
> >> }
> >> @@ -544,7 +546,7 @@ static int meson_nfc_read_buf(struct nand_chip *nand, u8 *buf, int len)
> >> if (ret)
> >> goto out;
> >>
> >> - cmd = NFC_CMD_N2M | (len & GENMASK(13, 0));
> >> + cmd = NFC_CMD_N2M | len;
> >> writel(cmd, nfc->reg_base + NFC_REG_CMD);
> >>
> >> meson_nfc_drain_cmd(nfc);
> >> @@ -568,7 +570,7 @@ static int meson_nfc_write_buf(struct nand_chip *nand, u8 *buf, int len)
> >> if (ret)
> >> return ret;
> >>
> >> - cmd = NFC_CMD_M2N | (len & GENMASK(13, 0));
> >> + cmd = NFC_CMD_M2N | len;
> >> writel(cmd, nfc->reg_base + NFC_REG_CMD);
> >>
> >> meson_nfc_drain_cmd(nfc);
> >> @@ -936,6 +938,9 @@ static int meson_nfc_exec_op(struct nand_chip *nand,
> >> break;
> >>
> >> case NAND_OP_DATA_IN_INSTR:
> >> + if (instr->ctx.data.len > NFC_CMD_RAW_LEN)
> >> + return -EINVAL;
> >
> > You need to refuse the operation earlier. That's what the check_op
> > boolean is about. Maybe you can take inspiration from anfc_check_op()
> > in the arasan controller.
>
> Ok! Thanks!
>
> >
> >> +
> >> buf = meson_nand_op_get_dma_safe_input_buf(instr);
> >> if (!buf)
> >> return -ENOMEM;
> >> @@ -944,6 +949,9 @@ static int meson_nfc_exec_op(struct nand_chip *nand,
> >> break;
> >>
> >> case NAND_OP_DATA_OUT_INSTR:
> >> + if (instr->ctx.data.len > NFC_CMD_RAW_LEN)
> >> + return -EINVAL;
> >
> > Same.
> >
> >> +
> >> buf = meson_nand_op_get_dma_safe_output_buf(instr);
> >> if (!buf)
> >> return -ENOMEM;
> >> @@ -1181,6 +1189,7 @@ static int meson_nand_attach_chip(struct nand_chip *nand)
> >> struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand);
> >> struct mtd_info *mtd = nand_to_mtd(nand);
> >> int nsectors = mtd->writesize / 1024;
> >> + int raw_writesize;
> >> int ret;
> >>
> >> if (!mtd->name) {
> >> @@ -1192,6 +1201,13 @@ static int meson_nand_attach_chip(struct nand_chip *nand)
> >> return -ENOMEM;
> >> }
> >>
> >> + raw_writesize = mtd->writesize + mtd->oobsize;
> >> + if (raw_writesize > NFC_CMD_RAW_LEN) {
> >> + dev_err(nfc->dev, "too big write size in raw mode: %d > %ld\n",
> >> + raw_writesize, NFC_CMD_RAW_LEN);
> >> + return -EINVAL;
> >> + }
> >> +
> >> if (nand->bbt_options & NAND_BBT_USE_FLASH)
> >> nand->bbt_options |= NAND_BBT_NO_OOB;
> >>
> >
> >
> > Thanks,
> > Miquèl
Thanks,
Miquèl
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
prev parent reply other threads:[~2023-06-06 7:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-05 19:10 [PATCH v1] mtd: rawnand: meson: check buffer length Arseniy Krasnov
2023-06-06 7:16 ` Miquel Raynal
2023-06-06 7:37 ` Arseniy Krasnov
2023-06-06 7:50 ` Miquel Raynal [this message]
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=20230606095023.26a056a3@xps-13 \
--to=miquel.raynal@bootlin.com \
--cc=avkrasnov@sberdevices.ru \
--cc=jbrunet@baylibre.com \
--cc=kernel@sberdevices.ru \
--cc=khilman@baylibre.com \
--cc=liang.yang@amlogic.com \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=martin.blumenstingl@googlemail.com \
--cc=neil.armstrong@linaro.org \
--cc=oxffffaa@gmail.com \
--cc=richard@nod.at \
--cc=vigneshr@ti.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).