mtd: spi-nor: Cleanup patches
Subsystems (2)
v2 cover mtd: spi-nor: Cleanup patches
Various cleanup patches done while reviewing contributions.
Tudor Ambarus (5):
mtd: spi-nor: core: Advance erase after the erase cmd has been
completed
mtd: spi-nor: core: Add vdbg msg for spi_nor_erase_multi_sectors()
mtd: spi-nor: Get rid of duplicated argument in spi_nor_parse_sfdp()
mtd: spi-nor: Move Software Write Protection logic out of the core
mtd: spi-nor: swp: Drop 'else' after 'return'
drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 432 ++------------------------------- drivers/mtd/spi-nor/core.h | 10 +- drivers/mtd/spi-nor/issi.c | 3 +- drivers/mtd/spi-nor/macronix.c | 3 +- drivers/mtd/spi-nor/sfdp.c | 72 +++--- drivers/mtd/spi-nor/sfdp.h | 3 +- drivers/mtd/spi-nor/spansion.c | 12 +- drivers/mtd/spi-nor/swp.c | 419 ++++++++++++++++++++++++++++++++ drivers/mtd/spi-nor/winbond.c | 3 +- 10 files changed, 479 insertions(+), 480 deletions(-) create mode 100644 drivers/mtd/spi-nor/swp.c
Signature · 1 line
2.25.1
PATCH v2 1/5 mtd: spi-nor: core: Advance erase after the erase cmd has been completed
addr and len were gratuitously updated even when spi_nor_wait_till_ready() failed. Wait for the erase cmd to complete and then advance the erase.
---
v2:
- update commit message
- Add R-b tag
drivers/mtd/spi-nor/core.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/mtd/spi-nor/core.c +6 -6
@@ -1618,12 +1618,12 @@ static int spi_nor_erase_multi_sectors(struct spi_nor *nor, u64 addr, u32 len)if (ret) goto destroy_erase_cmd_list; - addr += cmd->size; - cmd->count--; - ret =spi_nor_wait_till_ready (nor);if (ret) goto destroy_erase_cmd_list; + + addr += cmd->size; + cmd->count--; }list_del (&cmd->list);kfree (cmd);
@@ -1704,12 +1704,12 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)if (ret) goto erase_err; - addr += mtd->erasesize; - len -= mtd->erasesize; - ret =spi_nor_wait_till_ready (nor);if (ret) goto erase_err; + + addr += mtd->erasesize; + len -= mtd->erasesize; }/* erase multiple sectors */
Signature · 1 line
2.25.1
PATCH v2 2/5 mtd: spi-nor: core: Add vdbg msg for spi_nor_erase_multi_sectors()
In reply to Tudor AmbarusUseful when debugging non-uniform erase.
---
v2:
- s/dev_dbg/dev_vdb
- move vdbg message the first thing in the while
drivers/mtd/spi-nor/core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mtd/spi-nor/core.c +3 -0
@@ -1610,6 +1610,9 @@ static int spi_nor_erase_multi_sectors(struct spi_nor *nor, u64 addr, u32 len)list_for_each_entry_safe (cmd, next, &erase_list, list) { nor->erase_opcode = cmd->opcode;while (cmd->count) { +dev_vdbg (nor->dev,"erase_cmd->size = 0x%08x, erase_cmd->opcode = 0x%02x, erase_cmd->count = %d\n" , + cmd->size, cmd->opcode, cmd->count); + ret =spi_nor_write_enable (nor);if (ret) goto destroy_erase_cmd_list;
Signature · 1 line
2.25.1
Re: [PATCH v2 2/5] mtd: spi-nor: core: Add vdbg msg for spi_nor_erase_multi_sectors()
Quoted 16 lines · Tudor Ambarus
Useful when debugging non-uniform erase.
Signed-off-by Tudor Ambarus <[email protected]>---
v2:
- s/dev_dbg/dev_vdb
- move vdbg message the first thing in the whiledrivers/mtd/spi-nor/core.c | 3 +++ 1 file changed, 3 insertions(+)drivers/mtd/spi-nor/core.c +0
-0
drivers/mtd/spi-nor/core.c static int spi_nor_erase_multi_sectors(struct spi_nor *nor, u64 addr, u32 len) · line 1613
Quoted 4 lines
drivers/mtd/spi-nor/core.c +1
-0@@ -1610,6 +1610,9 @@ static int spi_nor_erase_multi_sectors(struct spi_nor *nor, u64 addr, u32 len)list_for_each_entry_safe (cmd, next, &erase_list, list) { nor->erase_opcode = cmd->opcode;while (cmd->count) { + dev_vdbg(nor->dev, "erase_cmd->size = 0x%08x, erase_cmd->opcode = 0x%02x, erase_cmd->count = %d\n",
erase_cmd->count is an unsigned value (u32) so it should be %u instead of %d.
Other than this,
Quoted 8 lines
drivers/mtd/spi-nor/core.c +2
-0+ cmd->size, cmd->opcode, cmd->count); + ret =spi_nor_write_enable (nor);if (ret) goto destroy_erase_cmd_list;Signature · 1 line
2.25.1
Signature · 7 lines
Regards, Pratyush Yadav Texas Instruments Inc. ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 3/5 mtd: spi-nor: Get rid of duplicated argument in spi_nor_parse_sfdp()
In reply to Tudor Ambarusspi_nor_parse_sfdp(nor, nor->params);
passes for the second argument a member within the first argument. Drop the second argument and obtain it directly from the first, and do it across all the children functions. This is a follow up for 'commit 69a8eed58cc0 ("mtd: spi-nor: Don't copy self-pointing struct around")'
---
v2: Add params local variable in spi_nor_parse_4bait(), because params is used in multiple locations.
drivers/mtd/spi-nor/core.c | 10 ++--- drivers/mtd/spi-nor/core.h | 6 +-- drivers/mtd/spi-nor/issi.c | 3 +- drivers/mtd/spi-nor/macronix.c | 3 +- drivers/mtd/spi-nor/sfdp.c | 72 +++++++++++++--------------------- drivers/mtd/spi-nor/sfdp.h | 3 +- drivers/mtd/spi-nor/spansion.c | 12 +++--- drivers/mtd/spi-nor/winbond.c | 3 +- 8 files changed, 42 insertions(+), 70 deletions(-)
drivers/mtd/spi-nor/core.c +4 -6
@@ -2629,22 +2629,20 @@ void spi_nor_init_uniform_erase_map(struct spi_nor_erase_map *map,int spi_nor_post_bfpt_fixups (struct spi_nor *nor,const struct sfdp_parameter_header *bfpt_header, -const struct sfdp_bfpt *bfpt, -struct spi_nor_flash_parameter *params) +const struct sfdp_bfpt *bfpt) {int ret;if (nor->manufacturer && nor->manufacturer->fixups && nor->manufacturer->fixups->post_bfpt) { ret = nor->manufacturer->fixups->post_bfpt (nor, bfpt_header, - bfpt, params); + bfpt);if (ret)return ret; }if (nor->info->fixups && nor->info->fixups->post_bfpt) -return nor->info->fixups->post_bfpt (nor, bfpt_header, bfpt, - params); +return nor->info->fixups->post_bfpt (nor, bfpt_header, bfpt);return 0 ; }
@@ -2899,7 +2897,7 @@ 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, nor->params)) { +if (spi_nor_parse_sfdp (nor)) {memcpy (nor->params, &sfdp_params,sizeof (*nor->params)); nor->addr_width =0 ; nor->flags &= ~SNOR_F_4B_OPCODES ;
drivers/mtd/spi-nor/core.h +2 -4
@@ -261,8 +261,7 @@ struct spi_nor_fixups {void (*default_init)(struct spi_nor *nor);int (*post_bfpt)(struct spi_nor *nor,const struct sfdp_parameter_header *bfpt_header, -const struct sfdp_bfpt *bfpt, -struct spi_nor_flash_parameter *params); +const struct sfdp_bfpt *bfpt);void (*post_sfdp)(struct spi_nor *nor); };
@@ -470,8 +469,7 @@ void spi_nor_init_uniform_erase_map(struct spi_nor_erase_map *map,int spi_nor_post_bfpt_fixups (struct spi_nor *nor,const struct sfdp_parameter_header *bfpt_header, -const struct sfdp_bfpt *bfpt, -struct spi_nor_flash_parameter *params); +const struct sfdp_bfpt *bfpt);static struct spi_nor __maybe_unused *mtd_to_spi_nor (struct mtd_info *mtd) {
drivers/mtd/spi-nor/issi.c +1 -2
@@ -11,8 +11,7 @@static int is25lp256_post_bfpt_fixups (struct spi_nor *nor,const struct sfdp_parameter_header *bfpt_header, -const struct sfdp_bfpt *bfpt, -struct spi_nor_flash_parameter *params) +const struct sfdp_bfpt *bfpt) {/* * IS25LP256 supports 4B opcodes, but the BFPT advertises a
drivers/mtd/spi-nor/macronix.c +1 -2
@@ -11,8 +11,7 @@static int mx25l25635_post_bfpt_fixups (struct spi_nor *nor,const struct sfdp_parameter_header *bfpt_header, -const struct sfdp_bfpt *bfpt, -struct spi_nor_flash_parameter *params) +const struct sfdp_bfpt *bfpt) {/* * MX25L25635F supports 4B opcodes but MX25L25635E does not.
drivers/mtd/spi-nor/sfdp.c +27 -45
220 lines not on this page · raw message
drivers/mtd/spi-nor/sfdp.h +1 -2
@@ -107,7 +107,6 @@ struct sfdp_parameter_header { u8 id_msb; }; -int spi_nor_parse_sfdp (struct spi_nor *nor, -struct spi_nor_flash_parameter *params); +int spi_nor_parse_sfdp (struct spi_nor *nor);#endif /* __LINUX_MTD_SFDP_H */
drivers/mtd/spi-nor/spansion.c +5 -7
@@ -142,8 +142,7 @@ static void s28hs512t_post_sfdp_fixup(struct spi_nor *nor)static int s28hs512t_post_bfpt_fixup (struct spi_nor *nor,const struct sfdp_parameter_header *bfpt_header, -const struct sfdp_bfpt *bfpt, -struct spi_nor_flash_parameter *params) +const struct sfdp_bfpt *bfpt) {/* * The BFPT table advertises a 512B page size but the page size is
@@ -162,9 +161,9 @@ static int s28hs512t_post_bfpt_fixup(struct spi_nor *nor,return ret;if (nor->bouncebuf[0 ] &SPINOR_REG_CYPRESS_CFR3V_PGSZ ) - params->page_size =512 ; + nor->params->page_size =512 ;else - params->page_size =256 ; + nor->params->page_size =256 ;return 0 ; }
@@ -178,8 +177,7 @@ static struct spi_nor_fixups s28hs512t_fixups = {static int s25fs_s_post_bfpt_fixups (struct spi_nor *nor,const struct sfdp_parameter_header *bfpt_header, -const struct sfdp_bfpt *bfpt, -struct spi_nor_flash_parameter *params) +const struct sfdp_bfpt *bfpt) {/* * The S25FS-S chip family reports 512-byte pages in BFPT but
@@ -187,7 +185,7 @@ s25fs_s_post_bfpt_fixups(struct spi_nor *nor,* of 256 bytes. Overwrite the page size advertised by BFPT * to get the writes working. */ - params->page_size =256 ; + nor->params->page_size =256 ;return 0 ; }
drivers/mtd/spi-nor/winbond.c +1 -2
@@ -11,8 +11,7 @@static int w25q256_post_bfpt_fixups (struct spi_nor *nor,const struct sfdp_parameter_header *bfpt_header, -const struct sfdp_bfpt *bfpt, -struct spi_nor_flash_parameter *params) +const struct sfdp_bfpt *bfpt) {/* * W25Q256JV supports 4B opcodes but W25Q256FV does not.
Signature · 1 line
2.25.1
Re: [PATCH v2 3/5] mtd: spi-nor: Get rid of duplicated argument in spi_nor_parse_sfdp()
Quoted 7 lines · Tudor Ambarus
spi_nor_parse_sfdp(nor, nor->params);
passes for the second argument a member within the first argument. Drop the second argument and obtain it directly from the first, and do it across all the children functions. This is a follow up for 'commit69a8eed58cc0("mtd: spi-nor: Don't copy self-pointing struct around")'Signed-off-by Tudor Ambarus <[email protected]>
Signature · 7 lines
Regards, Pratyush Yadav Texas Instruments Inc. ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 4/5 mtd: spi-nor: Move Software Write Protection logic out of the core
In reply to Tudor AmbarusIt makes the core file a bit smaller and provides better separation between the Software Write Protection features and the core logic. All the next generic software write protection features (e.g. Individual Block Protection) will reside in swp.c.
--- drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 407 +--------------------------------- drivers/mtd/spi-nor/core.h | 4 + drivers/mtd/spi-nor/swp.c | 419 +++++++++++++++++++++++++++++++++++ 4 files changed, 428 insertions(+), 404 deletions(-) create mode 100644 drivers/mtd/spi-nor/swp.c
drivers/mtd/spi-nor/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 -spi-nor-objs := core.o sfdp.o +spi-nor-objs := core.o sfdp.o swp.o spi-nor-objs += atmel.o spi-nor-objs += catalyst.o spi-nor-objs += eon.o
drivers/mtd/spi-nor/core.c +4 -403
437 lines not on this page · raw message
drivers/mtd/spi-nor/core.h +4 -0
@@ -471,6 +471,10 @@ int spi_nor_post_bfpt_fixups(struct spi_nor *nor,const struct sfdp_parameter_header *bfpt_header, const struct sfdp_bfpt *bfpt); +void spi_nor_init_default_locking_ops (struct spi_nor *nor); +void spi_nor_try_unlock_all (struct spi_nor *nor); +void spi_nor_register_locking_ops (struct spi_nor *nor); +static struct spi_nor __maybe_unused *mtd_to_spi_nor (struct mtd_info *mtd) {return mtd->priv;
drivers/mtd/spi-nor/swp.c new file +419 -0
419 lines not on this page · raw message
Signature · 6 lines
2.25.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 4/5] mtd: spi-nor: Move Software Write Protection logic out of the core
Am 2021-03-06 10:50, schrieb Tudor Ambarus:
Quoted 7 lines
It makes the core file a bit smaller and provides better separation between the Software Write Protection features and the core logic. All the next generic software write protection features (e.g. Individual Block Protection) will reside in
swp.c.Signed-off-by Tudor Ambarus <[email protected]>---
[..]
drivers/mtd/spi-nor/core.c int spi_nor_scan(struct spi_nor *nor, const char · line 3156
Quoted 6 lines
drivers/mtd/spi-nor/core.c +1
-0@@ -3554,6 +3152,9 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, if (ret)return ret; +if (nor->params->locking_ops)
Should this be in spi_nor_register_locking_ops(), too? I.e.
void spi_nor_register_locking_ops() {
if (!nor->params->locking_ops)
return;..
}
I don't have a strong opinion on that so far. I just noticed because I put the check into spi_nor_otp_init() for my OTP series. They should be the same though.
drivers/mtd/spi-nor/core.c int spi_nor_scan(struct spi_nor *nor, const char *name, · line 3156
Quoted 1 line
drivers/mtd/spi-nor/core.c +1
-0+spi_nor_register_locking_ops (nor);
-michael
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 4/5] mtd: spi-nor: Move Software Write Protection logic out of the core
Quoted 23 lines · Michael Walle
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Am 2021-03-06 10:50, schrieb Tudor Ambarus:
Quoted 8 lines
It makes the core file a bit smaller and provides better separation between the Software Write Protection features and the core logic. All the next generic software write protection features (e.g. Individual
Block Protection) will reside inswp.c.Signed-off-by Tudor Ambarus <[email protected]>---
[..]
drivers/mtd/spi-nor/core.c int spi_nor_scan(struct spi_nor *nor, const char · line 3156
Quoted 6 lines
drivers/mtd/spi-nor/core.c +1
-0@@ -3554,6 +3152,9 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, if (ret) return ret; + if (nor->params->locking_ops)Should this be in
spi_nor_register_locking_ops(), too? I.e.
Quoted 5 lines
void
spi_nor_register_locking_ops(){
if (!nor->params->locking_ops)
return;
..
}
Yes, the checking should be done inside spi_nor_register_locking_ops, will move it.
Btw, what do you find a better name, spi_nor_register_locking_ops or spi_nor_init_locking_ops? Applies to OTP as well.
Thanks,
ta
Quoted 8 lines
I don't have a strong opinion on that so far. I just noticed because I put the check into
spi_nor_otp_init()for my OTP series. They should be the same though.drivers/mtd/spi-nor/core.c int spi_nor_scan(struct spi_nor *nor, const char *name, · line 3156
Quoted 1 line
drivers/mtd/spi-nor/core.c +1
-0+ spi_nor_register_locking_ops(nor);-michael
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 4/5] mtd: spi-nor: Move Software Write Protection logic out of the core
Quoted 30 lines · On 15/03/21 06:09AM, [email protected] wrote:
Quoted 23 lines · Michael Walle
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Am 2021-03-06 10:50, schrieb Tudor Ambarus:
Quoted 8 lines
It makes the core file a bit smaller and provides better separation between the Software Write Protection features and the core logic. All the next generic software write protection features (e.g. Individual
Block Protection) will reside inswp.c.Signed-off-by Tudor Ambarus <[email protected]>---
[..]
drivers/mtd/spi-nor/core.c int spi_nor_scan(struct spi_nor *nor, const char · line 3156
Quoted 6 lines
drivers/mtd/spi-nor/core.c +1
-0@@ -3554,6 +3152,9 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, if (ret) return ret; + if (nor->params->locking_ops)Should this be in
spi_nor_register_locking_ops(), too? I.e.Quoted 5 lines
void
spi_nor_register_locking_ops(){
if (!nor->params->locking_ops)
return;
..
}
Quoted 5 lines
Yes, the checking should be done inside
spi_nor_register_locking_ops, will move it.Btw, what do you find a better name,
spi_nor_register_locking_opsorspi_nor_init_locking_ops? Applies to OTP as well.
On a quick glance, spi_nor_register_locking_ops() can be mistaken to mean "Register locking ops". That is, ops to lock/unlock flash registers. If you do want to keep using "register", IMO spi_nor_locking_ops_register() would be better.
Quoted 13 lines
Thanks,
taQuoted 8 lines
I don't have a strong opinion on that so far. I just noticed because I put the check into
spi_nor_otp_init()for my OTP series. They should be the same though.drivers/mtd/spi-nor/core.c int spi_nor_scan(struct spi_nor *nor, const char *name, · line 3156
Quoted 1 line
drivers/mtd/spi-nor/core.c +1
-0+ spi_nor_register_locking_ops(nor);-michael
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments Inc.
Re: [PATCH v2 4/5] mtd: spi-nor: Move Software Write Protection logic out of the core
In reply to [email protected]Am 2021-03-15 07:09, schrieb [email protected]:
Quoted 31 lines · Michael Walle
Quoted 24 lines
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Am 2021-03-06 10:50, schrieb Tudor Ambarus:
Quoted 8 lines
It makes the core file a bit smaller and provides better separation between the Software Write Protection features and the core logic. All the next generic software write protection features (e.g. Individual
Block Protection) will reside inswp.c.Signed-off-by Tudor Ambarus <[email protected]>---
[..]
Quoted 7 lines
(quoted diff) +0
-0@@ -3554,6 +3152,9 @@ int spi_nor_scan(struct spi_nor *nor, constchar
*name,
if (ret)
return ret;+ if (
nor->params->locking_ops)Should this be in
spi_nor_register_locking_ops(), too? I.e.Quoted 5 lines
void
spi_nor_register_locking_ops(){
if (!nor->params->locking_ops)
return;
..
}
Quoted 5 lines
Yes, the checking should be done inside
spi_nor_register_locking_ops, will move it.Btw, what do you find a better name,
spi_nor_register_locking_opsorspi_nor_init_locking_ops? Applies to OTP as well.
probably register_locking_ops(), as long as the function just does that.
For OTP, I want to provide nvmem support, too. Thus it will not only register the mtd ops and thus spi_nor_otp_init() will be better for my case.
-michael
Vignesh Raghavendra
maintainerRe: [PATCH v2 4/5] mtd: spi-nor: Move Software Write Protection logic out of the core
In reply to Tudor AmbarusQuoted 11 lines · Tudor Ambarus
It makes the core file a bit smaller and provides better separation between the Software Write Protection features and the core logic. All the next generic software write protection features (e.g. Individual Block Protection) will reside in
swp.c.Signed-off-by Tudor Ambarus <[email protected]>--- drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 407 +--------------------------------- drivers/mtd/spi-nor/core.h | 4 + drivers/mtd/spi-nor/swp.c | 419 +++++++++++++++++++++++++++++++++++
Hmmm, name swp.c does not seem intuitive to me. How about expanding it a bit:
soft-wr-protect.c or software-write-protect.c ?
Regards
Vignesh
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 4/5] mtd: spi-nor: Move Software Write Protection logic out of the core
Quoted 15 lines · Vignesh Raghavendra
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 11 lines · Tudor Ambarus
It makes the core file a bit smaller and provides better separation between the Software Write Protection features and the core logic. All the next generic software write protection features (e.g. Individual Block Protection) will reside in
swp.c.Signed-off-by Tudor Ambarus <[email protected]>--- drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 407 +--------------------------------- drivers/mtd/spi-nor/core.h | 4 + drivers/mtd/spi-nor/swp.c | 419 +++++++++++++++++++++++++++++++++++
Quoted 5 lines
Hmmm, name
swp.cdoes not seem intuitive to me. How about expanding it a bit:
soft-wr-protect.corsoftware-write-protect.c?
I thought about the SWP configs that we have.
How about keeping swp.c and rename configs to:
s/MTD_SPI_NOR_SWP_DISABLE/MTD_SPI_NOR_DISABLE_BOOT_SWP s/MTD_SPI_NOR_SWP_DISABLE_ON_VOLATILE/MTD_SPI_DISABLE_BOOT_SWP_ON_VOLATILE s/MTD_SPI_NOR_SWP_KEEP/MTD_SPI_NOR_KEEP_BOOT_SWP
The renamed configs should better indicate that the software write protection is disabled just at boot time, while the locking support is still enabled. Otherwise one may think that with a MTD_SPI_NOR_SWP_DISABLE, all the software write protection features are stripped/not available.
Cheers,
ta
Vignesh Raghavendra
maintainerRe: [PATCH v2 4/5] mtd: spi-nor: Move Software Write Protection logic out of the core
Quoted 29 lines · On 3/9/21 12:58 PM, [email protected] wrote:
Quoted 15 lines · Vignesh Raghavendra
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 11 lines · Tudor Ambarus
It makes the core file a bit smaller and provides better separation between the Software Write Protection features and the core logic. All the next generic software write protection features (e.g. Individual Block Protection) will reside in
swp.c.Signed-off-by Tudor Ambarus <[email protected]>--- drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 407 +--------------------------------- drivers/mtd/spi-nor/core.h | 4 + drivers/mtd/spi-nor/swp.c | 419 +++++++++++++++++++++++++++++++++++Quoted 5 lines
Hmmm, name
swp.cdoes not seem intuitive to me. How about expanding it a bit:
soft-wr-protect.corsoftware-write-protect.c?I thought about the SWP configs that we have.
How about keeping
swp.cand rename configs to:
s/MTD_SPI_NOR_SWP_DISABLE/MTD_SPI_NOR_DISABLE_BOOT_SWP s/MTD_SPI_NOR_SWP_DISABLE_ON_VOLATILE/MTD_SPI_DISABLE_BOOT_SWP_ON_VOLATILE s/MTD_SPI_NOR_SWP_KEEP/MTD_SPI_NOR_KEEP_BOOT_SWP
Quoted 5 lines
The renamed configs should better indicate that the software write protection is disabled just at boot time, while the locking support is still enabled. Otherwise one may think that with a
MTD_SPI_NOR_SWP_DISABLE, all the software write protection features are stripped/not available.
I am not a fan of renaming Kconfig options as it breaks make olddefconfig flow which many developers rely on.
Regards
Vignesh
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 4/5] mtd: spi-nor: Move Software Write Protection logic out of the core
Quoted 23 lines · Vignesh Raghavendra
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 20 lines · On 3/9/21 12:58 PM, [email protected] wrote:
Quoted 19 lines · Vignesh Raghavendra
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 11 lines · Tudor Ambarus
It makes the core file a bit smaller and provides better separation between the Software Write Protection features and the core logic. All the next generic software write protection features (e.g. Individual Block Protection) will reside in
swp.c.Signed-off-by Tudor Ambarus <[email protected]>--- drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 407 +--------------------------------- drivers/mtd/spi-nor/core.h | 4 + drivers/mtd/spi-nor/swp.c | 419 +++++++++++++++++++++++++++++++++++Hmmm, name
swp.cdoes not seem intuitive to me. How about expanding it a bit:
soft-wr-protect.corsoftware-write-protect.c?
Having in mind that we have the SWP configs, I think I prefer swp.c. But let's see what majority thinks, we'll do as majority prefers. Michael, Pratyush?
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
cut
Quoted 4 lines
I am not a fan of renaming
Kconfigoptions as it breaks make olddefconfig flow which many developers rely on.
I'm fine keeping them as they are for now. If someone else screams we will reconsider.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 4/5] mtd: spi-nor: Move Software Write Protection logic out of the core
Am 2021-03-17 07:09, schrieb [email protected]:
Quoted 22 lines · Vignesh Raghavendra
Quoted 21 lines
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 18 lines · On 3/9/21 12:58 PM, [email protected] wrote:
Quoted 17 lines · Vignesh Raghavendra
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 13 lines · Tudor Ambarus
It makes the core file a bit smaller and provides better separation between the Software Write Protection features and the core logic. All the next generic software write protection features (e.g. Individual Block Protection) will reside in
swp.c.Signed-off-by Tudor Ambarus <[email protected]>--- drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 407 +--------------------------------- drivers/mtd/spi-nor/core.h | 4 + drivers/mtd/spi-nor/swp.c | 419+++++++++++++++++++++++++++++++++++
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Hmmm, name
swp.cdoes not seem intuitive to me. How about expanding it a bit:
soft-wr-protect.corsoftware-write-protect.c?Having in mind that we have the SWP configs, I think I prefer
swp.c. But let's see what majority thinks, we'll do as majority prefers. Michael, Pratyush?
It's just an internal name, thus as long as it remotely makes sense, I'm fine. It's just a matter of taste, isn't it?
But here's one technical reason that would bother me more: name clashes between the core modules: core, sfdp, otp, swp and the vendor names. It is very unlikely, but there is a non-zero chance ;)
-michael
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 4/5] mtd: spi-nor: Move Software Write Protection logic out of the core
Quoted 32 lines · Michael Walle
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Am 2021-03-17 07:09, schrieb [email protected]:
Quoted 29 lines · Vignesh Raghavendra
Quoted 28 lines
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 24 lines · On 3/9/21 12:58 PM, [email protected] wrote:
Quoted 23 lines · Vignesh Raghavendra
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 6 lines · Tudor Ambarus
It makes the core file a bit smaller and provides better separation between the Software Write Protection features and the core logic. All the next generic software write protection features (e.g. Individual
Block Protection) will reside inswp.c.Quoted 8 lines
Signed-off-by Tudor Ambarus <[email protected]>---
drivers/mtd/spi-nor/Makefile | 2 +-
drivers/mtd/spi-nor/core.c | 407+--------------------------------- drivers/mtd/spi-nor/core.h | 4 + drivers/mtd/spi-nor/swp.c | 419+++++++++++++++++++++++++++++++++++
Hmmm, name
swp.cdoes not seem intuitive to me. How about expanding it a
bit:
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
soft-wr-protect.corsoftware-write-protect.c?Having in mind that we have the SWP configs, I think I prefer
swp.c. But let's see what majority thinks, we'll do as majority prefers. Michael, Pratyush?It's just an internal name, thus as long as it remotely makes sense, I'm fine. It's just a matter of taste, isn't it?
Sure, it's a matter of preference. What's yours?
Quoted 5 lines
But here's one technical reason that would bother me more: name clashes between the core modules: core, sfdp, otp, swp and the vendor names. It is very unlikely, but there is a non-zero chance ;)
We can move all manufacturers to a manufacturers/ folder. Each manufacturer driver will have to #include "../core.h", about what I have some mixed feelings.
Re: [PATCH v2 4/5] mtd: spi-nor: Move Software Write Protection logic out of the core
Am 2021-03-17 10:30, schrieb [email protected]:
Quoted 10 lines
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
soft-wr-protect.corsoftware-write-protect.c?Having in mind that we have the SWP configs, I think I prefer
swp.c. But let's see what majority thinks, we'll do as majority prefers. Michael, Pratyush?It's just an internal name, thus as long as it remotely makes sense, I'm fine. It's just a matter of taste, isn't it?
Sure, it's a matter of preference. What's yours?
if i have to choose, swp.c
Quoted 8 lines
Quoted 4 lines
But here's one technical reason that would bother me more: name clashes between the core modules: core, sfdp, otp, swp and the vendor names. It is very unlikely, but there is a non-zero chance ;)
We can move all manufacturers to a manufacturers/ folder. Each manufacturer driver will have to #include "
../core.h", about what I have some mixed feelings.
I don't think it makes sense as long as there is no clash; or until there are many more core modules, so you can't keep them apart anymore. It will just make it harder to follow the git history.
-michael
Re: [PATCH v2 4/5] mtd: spi-nor: Move Software Write Protection logic out of the core
In reply to [email protected]Quoted 20 lines · On 17/03/21 06:09AM, [email protected] wrote:
Quoted 19 lines · Vignesh Raghavendra
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 16 lines · On 3/9/21 12:58 PM, [email protected] wrote:
Quoted 15 lines · Vignesh Raghavendra
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 11 lines · Tudor Ambarus
It makes the core file a bit smaller and provides better separation between the Software Write Protection features and the core logic. All the next generic software write protection features (e.g. Individual Block Protection) will reside in
swp.c.Signed-off-by Tudor Ambarus <[email protected]>--- drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 407 +--------------------------------- drivers/mtd/spi-nor/core.h | 4 + drivers/mtd/spi-nor/swp.c | 419 +++++++++++++++++++++++++++++++++++
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Hmmm, name
swp.cdoes not seem intuitive to me. How about expanding it a bit:
soft-wr-protect.corsoftware-write-protect.c?Having in mind that we have the SWP configs, I think I prefer
swp.c. But let's see what majority thinks, we'll do as majority prefers. Michael, Pratyush?
I don't have much of an opinion on this tbh. But I usually prefer short names so I'd go with swp.c here. Maybe also add a comment at the top of the file mentioning the full name "Software Write Protection logic" or something similar for clarification.
Quoted 13 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
cut
Quoted 4 lines
I am not a fan of renaming
Kconfigoptions as it breaks make olddefconfig flow which many developers rely on.I'm fine keeping them as they are for now. If someone else screams we will reconsider.
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments Inc.
Vignesh Raghavendra
maintainerRe: [PATCH v2 4/5] mtd: spi-nor: Move Software Write Protection logic out of the core
Quoted 26 lines · Pratyush Yadav
Quoted 25 lines · On 17/03/21 06:09AM, [email protected] wrote:
Quoted 23 lines · Vignesh Raghavendra
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 20 lines · On 3/9/21 12:58 PM, [email protected] wrote:
Quoted 19 lines · Vignesh Raghavendra
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 11 lines · Tudor Ambarus
It makes the core file a bit smaller and provides better separation between the Software Write Protection features and the core logic. All the next generic software write protection features (e.g. Individual Block Protection) will reside in
swp.c.Signed-off-by Tudor Ambarus <[email protected]>--- drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 407 +--------------------------------- drivers/mtd/spi-nor/core.h | 4 + drivers/mtd/spi-nor/swp.c | 419 +++++++++++++++++++++++++++++++++++Hmmm, name
swp.cdoes not seem intuitive to me. How about expanding it a bit:
soft-wr-protect.corsoftware-write-protect.c?
Quoted 9 lines
Quoted 3 lines
Having in mind that we have the SWP configs, I think I prefer
swp.c. But let's see what majority thinks, we'll do as majority prefers. Michael, Pratyush?I don't have much of an opinion on this tbh. But I usually prefer short names so I'd go with
swp.chere. Maybe also add a comment at the top of the file mentioning the full name "Software Write Protection logic" or something similar for clarification.
I don't have hard objection to swp.c. As Pratyush suggested, a comment at top of the file indicating the purpose would be good to have.
PATCH v2 5/5 mtd: spi-nor: swp: Drop 'else' after 'return'
In reply to Tudor Ambaruselse is not generally useful after a break or return.
--- drivers/mtd/spi-nor/swp.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/mtd/spi-nor/swp.c +7 -7
@@ -25,8 +25,8 @@ static u8 spi_nor_get_sr_tb_mask(struct spi_nor *nor) {if (nor->flags &SNOR_F_HAS_SR_TB_BIT6 )return SR_TB_BIT6 ; -else -return SR_TB_BIT5 ; + +return SR_TB_BIT5 ; }static u64 spi_nor_get_min_prot_length_sr (struct spi_nor *nor)
@@ -41,8 +41,8 @@ static u64 spi_nor_get_min_prot_length_sr(struct spi_nor *nor)if (bp_slots_needed > bp_slots)return nor->info->sector_size << (bp_slots_needed - bp_slots); -else -return nor->info->sector_size; + +return nor->info->sector_size; } static void spi_nor_get_locked_range_sr(struct spi_nor *nor, u8 sr, loff_t *ofs,
@@ -96,9 +96,9 @@ static int spi_nor_check_lock_status_sr(struct spi_nor *nor, loff_t ofs,if (locked)/* Requested range is a sub-range of locked range */ return (ofs + len <= lock_offs + lock_len) && (ofs >= lock_offs); -else -/* Requested range does not overlap with locked range */ -return (ofs >= lock_offs + lock_len) || (ofs + len <= lock_offs); + +/* Requested range does not overlap with locked range */ +return (ofs >= lock_offs + lock_len) || (ofs + len <= lock_offs); } static int spi_nor_is_locked_sr(struct spi_nor *nor, loff_t ofs, uint64_t len,
Signature · 6 lines
2.25.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 5/5] mtd: spi-nor: swp: Drop 'else' after 'return'
Quoted 3 lines · Tudor Ambarus
else is not generally useful after a break or return.
Signed-off-by Tudor Ambarus <[email protected]>
Signature · 7 lines
Regards, Pratyush Yadav Texas Instruments Inc. ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 5/5] mtd: spi-nor: swp: Drop 'else' after 'return'
Quoted 7 lines · Pratyush Yadav
Quoted 3 lines · Tudor Ambarus
else is not generally useful after a break or return.
Signed-off-by Tudor Ambarus <[email protected]>Reviewed-by Pratyush Yadav <[email protected]>
I don't think this improves the code.
Generally, checkpatch is a stupid little script.
This code uses a form like:
if (foo) return bar; else return baz;
which checkpatch recognizes as OK and so checkpatch does not emit any warning message, but this code just adds comments before each return which confuses checkpatch.
I think better would be to change the code to use temporaries and convert the functions to bool.
Something like:
--- drivers/mtd/spi-nor/core.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
drivers/mtd/spi-nor/core.c +15 -10
@@ -1798,36 +1798,41 @@ static void spi_nor_get_locked_range_sr(struct spi_nor *nor, u8 sr, loff_t *ofs, }/* -* Return 1 if the entire region is locked (if @locked is true) or unlocked (if -* @locked is false); 0 otherwise +* Return true if the entire region is locked +* (if @locked is true) or unlocked (if @locked is false); false otherwise */ -static int spi_nor_check_lock_status_sr (struct spi_nor *nor,loff_t ofs, +static bool spi_nor_check_lock_status_sr (struct spi_nor *nor,loff_t ofs,uint64_t len,u8 sr,bool locked) {loff_t lock_offs;uint64_t lock_len; +uint64_t lock_max; +uint64_t ofs_max;if (!len) -return 1 ; +return true;spi_nor_get_locked_range_sr (nor, sr, &lock_offs, &lock_len); + lock_max = lock_offs + lock_len; + ofs_max = ofs + len; +if (locked)/* Requested range is a sub-range of locked range */ -return (ofs + len <= lock_offs + lock_len) && (ofs >= lock_offs); +return (ofs_max <= lock_max) && (ofs >= lock_offs);else /* Requested range does not overlap with locked range */ -return (ofs >= lock_offs + lock_len) || (ofs + len <= lock_offs); +return (ofs >= lock_max) || (ofs_max <= lock_offs); } -static int spi_nor_is_locked_sr (struct spi_nor *nor,loff_t ofs,uint64_t len, -u8 sr) +static bool spi_nor_is_locked_sr (struct spi_nor *nor,loff_t ofs,uint64_t len, +u8 sr) {return spi_nor_check_lock_status_sr (nor, ofs, len, sr, true); } -static int spi_nor_is_unlocked_sr (struct spi_nor *nor,loff_t ofs,uint64_t len, -u8 sr) +static bool spi_nor_is_unlocked_sr (struct spi_nor *nor,loff_t ofs,uint64_t len, +u8 sr) {return spi_nor_check_lock_status_sr (nor, ofs, len, sr, false); }
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 5/5] mtd: spi-nor: swp: Drop 'else' after 'return'
Quoted 13 lines · Joe Perches
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 7 lines · Pratyush Yadav
Quoted 3 lines · Tudor Ambarus
else is not generally useful after a break or return.
Signed-off-by Tudor Ambarus <[email protected]>Reviewed-by Pratyush Yadav <[email protected]>I don't think this improves the code.
Quoted 7 lines
Generally, checkpatch is a stupid little script.
This code uses a form like:
if (foo) return bar; else return baz;
Isn't else redundant? What are the benefits of keeping the else?
Quoted 28 lines
which checkpatch recognizes as OK and so checkpatch does not emit any warning message, but this code just adds comments before each return which confuses checkpatch.
I think better would be to change the code to use temporaries and convert the functions to bool.
Something like:
--- drivers/mtd/spi-nor/core.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)drivers/mtd/spi-nor/core.c +3
-3@@ -1798,36 +1798,41 @@ static void spi_nor_get_locked_range_sr(struct spi_nor *nor, u8 sr, loff_t *ofs, }/* -* Return 1 if the entire region is locked (if @locked is true) or unlocked (if -* @locked is false); 0 otherwise +* Return true if the entire region is locked +* (if @locked is true) or unlocked (if @locked is false); false otherwise */ -static int spi_nor_check_lock_status_sr(struct spi_nor *nor, loff_t ofs, +static bool spi_nor_check_lock_status_sr(struct spi_nor *nor, loff_t ofs,
drivers/mtd/spi-nor/core.c static void spi_nor_get_locked_range_sr(struct spi_nor *nor, u8 sr, loff_t *ofs, · line 1813
Quoted 10 lines
drivers/mtd/spi-nor/core.c +3
-1uint64_t len, u8 sr, bool locked) { loff_t lock_offs;uint64_t lock_len; +uint64_t lock_max; +uint64_t ofs_max;if (!len) -return 1 ; +return true;
returning one is wrong indeed, would you submit a patch for the conversion of the functions to bool?
Quoted 4 lines
drivers/mtd/spi-nor/core.c +1
-0spi_nor_get_locked_range_sr (nor, sr, &lock_offs, &lock_len); + lock_max = lock_offs + lock_len;
drivers/mtd/spi-nor/core.c static void spi_nor_get_locked_range_sr(struct spi_nor *nor, u8 sr, loff_t *ofs, · line 1825
Quoted 10 lines
drivers/mtd/spi-nor/core.c +4
-2+ ofs_max = ofs + len; +if (locked)/* Requested range is a sub-range of locked range */ -return (ofs + len <= lock_offs + lock_len) && (ofs >= lock_offs); +return (ofs_max <= lock_max) && (ofs >= lock_offs);else /* Requested range does not overlap with locked range */ -return (ofs >= lock_offs + lock_len) || (ofs + len <= lock_offs); +return (ofs >= lock_max) || (ofs_max <= lock_offs);
This should be fine too.
Cheers,
ta
Re: [PATCH v2 5/5] mtd: spi-nor: swp: Drop 'else' after 'return'
Quoted 14 lines · On Mon, 2021-03-15 at 11:24 +0000, [email protected] wrote:
Quoted 13 lines · Joe Perches
Quoted 7 lines · Pratyush Yadav
Quoted 3 lines · Tudor Ambarus
else is not generally useful after a break or return.
Signed-off-by Tudor Ambarus <[email protected]>Reviewed-by Pratyush Yadav <[email protected]>I don't think this improves the code.
Generally, checkpatch is a stupid little script.
Quoted 7 lines
Quoted 5 lines
This code uses a form like:
if (foo)
return bar;
else
return baz;Isn't else redundant? What are the benefits of keeping the else?
Visual consistency and it's a widely used style.
A long time ago Al Viro wrote:
https://lore.kernel.org/lkml/[email protected]/
which resulted in the patch to checkpatch that tries to ignore that style.
https://lore.kernel.org/lkml/1411621434.4026.9.camel@joe-AO725/
Quoted 5 lines
Quoted 2 lines
I think better would be to change the code to use temporaries and convert the functions to bool.
returning one is wrong indeed, would you submit a patch for the conversion of the functions to bool?
Just a suggestion...
Re: (subset) [PATCH v2 0/5] mtd: spi-nor: Cleanup patches
In reply to Tudor AmbarusQuoted 11 lines · Tudor Ambarus
Various cleanup patches done while reviewing contributions.
Tudor Ambarus (5):
mtd: spi-nor: core: Advance erase after the erase cmd has been
completed
mtd: spi-nor: core: Add vdbg msg forspi_nor_erase_multi_sectors()
mtd: spi-nor: Get rid of duplicated argument inspi_nor_parse_sfdp()
mtd: spi-nor: Move Software Write Protection logic out of the core
mtd: spi-nor: swp: Drop 'else' after 'return'[...]
For 2/5: s/%d/%u and then applied to spi-nor/next 1/5, 2/5 and 3/5.
[1/5] mtd: spi-nor: core: Advance erase after the erase cmd has been completed
https://git.kernel.org/mtd/c/786a0a75d0f3 [2/5] mtd: spi-nor: core: Add vdbg msg for spi_nor_erase_multi_sectors() https://git.kernel.org/mtd/c/8758888c3d78 [3/5] mtd: spi-nor: Get rid of duplicated argument in spi_nor_parse_sfdp() https://git.kernel.org/mtd/c/a580293a19fc
Best regards,
Signature · 1 line
Tudor Ambarus <[email protected]>