public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v6 1/2] mtd: spi-nor: Delay the initialization of bank_size
@ 2023-03-31 19:46 Miquel Raynal
  2023-03-31 19:46 ` [PATCH v6 2/2] mtd: spi-nor: macronix: Add support for mx25uw51245g with RWW Miquel Raynal
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Miquel Raynal @ 2023-03-31 19:46 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
	Pratyush Yadav, Michael Walle, linux-mtd
  Cc: Julien Su, Jaime Liao, Jaime Liao, Alvin Zhou, Thomas Petazzoni,
	Miquel Raynal

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;
 	params->page_size = info->page_size;
 
 	if (!(info->flags & SPI_NOR_NO_FR)) {
-- 
2.34.1


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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-04-04  6:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2023-04-03 15:59     ` Tudor Ambarus
2023-04-04  6:46 ` Tudor Ambarus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox