linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Michael Walle <michael@walle.cc>
To: Tudor Ambarus <tudor.ambarus@microchip.com>
Cc: macromorgan@hotmail.com, vigneshr@ti.com, jaimeliao@mxic.com.tw,
	richard@nod.at, esben@geanix.com, linux@rasmusvillemoes.dk,
	knaerzche@gmail.com, linux-mtd@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org, code@reto-schneider.ch,
	miquel.raynal@bootlin.com, heiko.thiery@gmail.com, sr@denx.de,
	figgyc@figgyc.uk, p.yadav@ti.com, mail@david-bauer.net,
	zhengxunli@mxic.com.tw
Subject: Re: [PATCH v3 12/25] mtd: spi-nor: core: Call spi_nor_post_sfdp_fixups() only when SFDP is defined
Date: Tue, 09 Nov 2021 11:18:20 +0100	[thread overview]
Message-ID: <98fa357a140e7b6236838820fe5619d8@walle.cc> (raw)
In-Reply-To: <20211029172633.886453-13-tudor.ambarus@microchip.com>

Am 2021-10-29 19:26, schrieb Tudor Ambarus:
> spi_nor_post_sfdp_fixups() was called even when there were no SFDP
> tables defined. late_init() should be instead used for flashes that
> do not define SFDP tables.
> 
> Use spi_nor_post_sfdp_fixups() just to fix SFDP data. post_sfdp()
> hook is as of now used just by s28hs512t, mt35xu512aba, and both
> support SFDP, there's no functional change with this patch.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> ---
>  drivers/mtd/spi-nor/core.c | 56 ++++++++++++++++++--------------------
>  1 file changed, 26 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 4679298c5301..82cc56c9d09e 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -2508,6 +2508,25 @@ static void
> spi_nor_manufacturer_init_params(struct spi_nor *nor)
>  		nor->info->fixups->default_init(nor);
>  }
> 
> +/**
> + * spi_nor_post_sfdp_fixups() - Updates the flash's parameters and 
> settings
> + * after SFDP has been parsed. Called only for flashes that define 
> JESD216 SFDP
> + * tables.
> + * @nor:	pointer to a 'struct spi_nor'
> + *
> + * Used to tweak various flash parameters when information provided by 
> the SFDP
> + * tables are wrong.
> + */
> +static void spi_nor_post_sfdp_fixups(struct spi_nor *nor)
> +{
> +	if (nor->manufacturer && nor->manufacturer->fixups &&
> +	    nor->manufacturer->fixups->post_sfdp)
> +		nor->manufacturer->fixups->post_sfdp(nor);
> +
> +	if (nor->info->fixups && nor->info->fixups->post_sfdp)
> +		nor->info->fixups->post_sfdp(nor);
> +}
> +
>  /**
>   * spi_nor_sfdp_init_params() - Initialize the flash's parameters and 
> settings
>   * based on JESD216 SFDP standard.
> @@ -2522,7 +2541,9 @@ static void spi_nor_sfdp_init_params(struct 
> spi_nor *nor)
> 
>  	memcpy(&sfdp_params, nor->params, sizeof(sfdp_params));
> 
> -	if (spi_nor_parse_sfdp(nor)) {
> +	if (!spi_nor_parse_sfdp(nor)) {
> +		spi_nor_post_sfdp_fixups(nor);

I find this function particulary confusing. Why is it
copying the params around? I know the function doc
says rollback, but can't we make this better?

Either make spi_nor_parse_sfdp() commit the nor->params update
atomically, or pass a second parameter sfdp_params, which are
copied to nor->params here if spi_nor_parse_sfdp() was successful.

Also the control flow could be better.

ret = spi_nor_parse_sfdp(nor, &sfdp_params);
if (!ret) {
     /* clever comment, why is addr_width = 0 here */
     nor->addr_width = 0;
     nor->flags &= ~SNOR_F_4B_OPCODES;
     return 0;
}

memcpy(nor->params, &sfdp_params, sizeof(*nor->params));
spi_nor_post_sfdp_fixups(nor);

Having an even closer look, addr_width is set to 0 because
spi_nor_parse_sfdp() is also changing that. nor->flags
is also changed and not only the SNOR_F_4B_OPCODES bit. But
only that one is cleared?!

I think this deserves another cleanup series. Having the
rollback here makes no sense. You'd have to keep both in
sync.

IMHO best would be a second parameter and make sure all
code in sfdp.c don't change anything else. Which would
probably mean that addr_width and flags will move to
nor->params.

Anyway, for now:
Reviewed-by: Michael Walle <michael@walle.cc>

-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-11-09 10:19 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-29 17:26 [PATCH v3 00/25] mtd: spi-nor: Clean params init Tudor Ambarus
2021-10-29 17:26 ` [PATCH v3 01/25] mtd: spi-nor: core: Fix spi_nor_flash_parameter otp description Tudor Ambarus
2021-11-09  8:18   ` Michael Walle
2021-10-29 17:26 ` [PATCH v3 02/25] mtd: spi-nor: core: Use container_of to get the pointer to struct spi_nor Tudor Ambarus
2021-11-09  8:21   ` Michael Walle
2021-11-15 10:59   ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 03/25] mtd: spi-nor: Introduce spi_nor_set_mtd_info() Tudor Ambarus
2021-11-09  8:22   ` Michael Walle
2021-11-15 18:52   ` Pratyush Yadav
2021-11-16 14:25     ` Tudor.Ambarus
2021-11-16 18:11       ` Pratyush Yadav
2021-11-17 14:36         ` Tudor.Ambarus
2021-11-19 18:23           ` Pratyush Yadav
2021-11-22  8:38             ` Tudor.Ambarus
2021-10-29 17:26 ` [PATCH v3 04/25] mtd: spi-nor: Get rid of nor->page_size Tudor Ambarus
2021-11-09  8:24   ` Michael Walle
2021-11-09  8:34     ` Tudor.Ambarus
2021-10-29 17:26 ` [PATCH v3 05/25] mtd: spi-nor: core: Introduce the late_init() hook Tudor Ambarus
2021-11-09  9:31   ` Michael Walle
2021-11-15 18:56   ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 06/25] mtd: spi-nor: atmel: Use flash late_init() for locking Tudor Ambarus
2021-11-09  9:31   ` Michael Walle
2021-11-15 18:59   ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 07/25] mtd: spi-nor: sst: " Tudor Ambarus
2021-11-09  9:34   ` Michael Walle
2021-11-15 19:00   ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 08/25] mtd: spi-nor: winbond: Use manufacturer late_init() for OTP ops Tudor Ambarus
2021-11-09  9:36   ` Michael Walle
2021-11-15 19:00   ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 09/25] mtd: spi-nor: xilinx: Use manufacturer late_init() to set setup method Tudor Ambarus
2021-11-09  9:43   ` Michael Walle
2021-11-15 19:01   ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 10/25] mtd: spi-nor: sst: Use manufacturer late_init() to set _write() Tudor Ambarus
2021-11-09  9:47   ` Michael Walle
2021-11-09 10:22     ` Tudor.Ambarus
2021-11-09 10:23       ` Tudor.Ambarus
2021-11-09 10:24       ` Michael Walle
2021-11-15 19:03   ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 11/25] mtd: spi-nor: spansion: Use manufacturer late_init() Tudor Ambarus
2021-11-09  9:48   ` Michael Walle
2021-11-15 19:06   ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 12/25] mtd: spi-nor: core: Call spi_nor_post_sfdp_fixups() only when SFDP is defined Tudor Ambarus
2021-11-09 10:18   ` Michael Walle [this message]
2021-10-29 17:26 ` [PATCH v3 13/25] mtd: spi-nor: sst: Get rid of SST_WRITE flash_info flag Tudor Ambarus
2021-11-09 12:21   ` Michael Walle
2021-11-09 12:31     ` Tudor.Ambarus
2021-11-12 21:28       ` Michael Walle
2021-10-29 17:26 ` [PATCH v3 14/25] mtd: spi-nor: Introduce flash_info flags masks Tudor Ambarus
2021-11-12 21:50   ` Michael Walle
2021-11-15  4:55     ` Tudor.Ambarus
2021-10-29 17:26 ` [PATCH v3 15/25] mtd: spi-nor: Introduce spi_nor_nonsfdp_init_flags() Tudor Ambarus
2021-11-15 19:12   ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 16/25] mtd: spi-nor: Introduce spi_nor_init_fixup_flags() Tudor Ambarus
2021-11-16 10:57   ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 17/25] mtd: spi-nor: core: Introduce SPI_NOR_PARSE_SFDP Tudor Ambarus
2021-10-29 17:26 ` [PATCH v3 18/25] mtd: spi-nor: core: Init flash params based on SFDP first for new flash additions Tudor Ambarus
2021-11-16 11:07   ` Pratyush Yadav
2021-10-29 17:26 ` [PATCH v3 19/25] mtd: spi-nor: core: Move spi_nor_set_addr_width() in spi_nor_setup() Tudor Ambarus
2021-11-12 21:53   ` Michael Walle
2021-10-29 17:26 ` [PATCH v3 20/25] mtd: spi-nor: sst: sst26vf064b: Init flash based on SFDP Tudor Ambarus
2021-10-29 17:31   ` Tudor.Ambarus
2021-11-09 12:25     ` Michael Walle
2021-11-09 12:33       ` Tudor.Ambarus
2021-11-09 12:37         ` Michael Walle
2021-10-29 17:26 ` [PATCH v3 21/25] mtd: spi-nor: winbond: w25q256jvm: " Tudor Ambarus
2021-10-29 17:31   ` Tudor.Ambarus
2021-10-29 17:26 ` [PATCH v3 22/25] mtd: spi-nor: spansion: s25fl256s0: Skip SFDP parsing Tudor Ambarus
2021-10-29 17:26 ` [PATCH v3 23/25] mtd: spi-nor: gigadevice: gd25q256: Init flash based on SFDP Tudor Ambarus
2021-10-29 17:33   ` Tudor.Ambarus
2021-10-29 17:26 ` [PATCH v3 24/25] mtd: spi-nor: issi: is25lp256: " Tudor Ambarus
2021-10-29 17:33   ` Tudor.Ambarus
2021-10-29 17:26 ` [PATCH v3 25/25] mtd: spi-nor: macronix: mx25l25635e: " Tudor Ambarus
2021-10-29 17:34   ` Tudor.Ambarus
2021-11-08 10:15 ` [PATCH v3 00/25] mtd: spi-nor: Clean params init Tudor.Ambarus
2021-11-08 10:31   ` Michael Walle
2021-11-16 11:36 ` Pratyush Yadav
2021-11-16 11:56   ` Michael Walle
2021-11-17 13:17 ` (subset)[PATCH " 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=98fa357a140e7b6236838820fe5619d8@walle.cc \
    --to=michael@walle.cc \
    --cc=code@reto-schneider.ch \
    --cc=esben@geanix.com \
    --cc=figgyc@figgyc.uk \
    --cc=heiko.thiery@gmail.com \
    --cc=jaimeliao@mxic.com.tw \
    --cc=knaerzche@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=macromorgan@hotmail.com \
    --cc=mail@david-bauer.net \
    --cc=miquel.raynal@bootlin.com \
    --cc=p.yadav@ti.com \
    --cc=richard@nod.at \
    --cc=sr@denx.de \
    --cc=tudor.ambarus@microchip.com \
    --cc=vigneshr@ti.com \
    --cc=zhengxunli@mxic.com.tw \
    /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).