From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Tudor Ambarus <tudor.ambarus@linaro.org>
Cc: Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>,
Pratyush Yadav <pratyush@kernel.org>,
Michael Walle <michael@walle.cc>,
linux-mtd@lists.infradead.org, Julien Su <juliensu@mxic.com.tw>,
Jaime Liao <jaimeliao@mxic.com.tw>,
Jaime Liao <jaimeliao.tw@gmail.com>,
Alvin Zhou <alvinzhou@mxic.com.tw>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: Re: [PATCH v6 1/2] mtd: spi-nor: Delay the initialization of bank_size
Date: Mon, 3 Apr 2023 17:31:58 +0200 [thread overview]
Message-ID: <20230403173158.42426b9d@xps-13> (raw)
In-Reply-To: <5c851822-1e14-f002-3224-738e10d478d1@linaro.org>
Hi Tudor,
tudor.ambarus@linaro.org wrote on Mon, 3 Apr 2023 09:23:24 +0100:
> On 3/31/23 20:46, Miquel Raynal wrote:
> > Bank size is derived from the chip's size, which in
> > spi_nor_init_default_params() can still be zero if the size is not
> > hardcoded in a table (eg. sfdp parsing). We need to delay the
> > initialization of this field in the "late" helpers.
> >
> > Based on the fact that RWW compatible devices will use the bank_size to
> > derive in which bank an access is made, we absolutely want to avoid
> > divisions by 0. Right now there is no such opportunity between
> > spi_nor_init_default_params() and spi_nor_late_init_params() but it is
> > probably safer to enforce a default value (assuming 1 bank) as early as
> > possible, just in case some day code using this variable is moved
> > earlier than expected.
> >
> > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > ---
> > I made the choice to keep a default value, to be honest this is not
> > actually needed today, so feel free to drop the line if you don't like
> > it, both choices seem reasonable to me.
> > ---
> > drivers/mtd/spi-nor/core.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> > index 9e6a0730cdb8..f436395ca489 100644
> > --- a/drivers/mtd/spi-nor/core.c
> > +++ b/drivers/mtd/spi-nor/core.c
> > @@ -2882,6 +2882,8 @@ static void spi_nor_late_init_params(struct spi_nor *nor)
> > */
> > if (nor->flags & SNOR_F_HAS_LOCK && !nor->params->locking_ops)
> > spi_nor_init_default_locking_ops(nor);
> > +
> > + nor->params->bank_size = div64_u64(nor->params->size, nor->info->n_banks);
> > }
> >
> > /**
> > @@ -2948,7 +2950,7 @@ static void spi_nor_init_default_params(struct spi_nor *nor)
> > /* Set SPI NOR sizes. */
> > params->writesize = 1;
> > params->size = (u64)info->sector_size * info->n_sectors;
> > - params->bank_size = div64_u64(params->size, info->n_banks);
> > + params->bank_size = params->size;
>
> I'll get rid of this line entirely as you overwrite it anyway in
> late_init and it's not used in between.
Yes, as said above, I'm fine with both approaches. Shall I resend or
will you edit when applying?
>
> > params->page_size = info->page_size;
> >
> > if (!(info->flags & SPI_NOR_NO_FR)) {
Thanks,
Miquèl
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2023-04-03 15:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-31 19:46 [PATCH v6 1/2] mtd: spi-nor: Delay the initialization of bank_size Miquel Raynal
2023-03-31 19:46 ` [PATCH v6 2/2] mtd: spi-nor: macronix: Add support for mx25uw51245g with RWW Miquel Raynal
2023-04-03 8:24 ` Tudor Ambarus
2023-04-03 8:23 ` [PATCH v6 1/2] mtd: spi-nor: Delay the initialization of bank_size Tudor Ambarus
2023-04-03 15:31 ` Miquel Raynal [this message]
2023-04-03 15:59 ` Tudor Ambarus
2023-04-04 6:46 ` Tudor Ambarus
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=20230403173158.42426b9d@xps-13 \
--to=miquel.raynal@bootlin.com \
--cc=alvinzhou@mxic.com.tw \
--cc=jaimeliao.tw@gmail.com \
--cc=jaimeliao@mxic.com.tw \
--cc=juliensu@mxic.com.tw \
--cc=linux-mtd@lists.infradead.org \
--cc=michael@walle.cc \
--cc=pratyush@kernel.org \
--cc=richard@nod.at \
--cc=thomas.petazzoni@bootlin.com \
--cc=tudor.ambarus@linaro.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.