mtd: spi-nor: Cleanup patches
Subsystems (2)
v3 cover mtd: spi-nor: Cleanup patches
Various cleanup patches done while reviewing contributions.
Tudor Ambarus (2):
mtd: spi-nor: Move Software Write Protection logic out of the core
mtd: spi-nor: swp: Improve code around spi_nor_check_lock_status_sr()
drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 406 +-------------------------------- drivers/mtd/spi-nor/core.h | 4 + drivers/mtd/spi-nor/swp.c | 427 +++++++++++++++++++++++++++++++++++ 4 files changed, 435 insertions(+), 404 deletions(-) create mode 100644 drivers/mtd/spi-nor/swp.c
Signature · 1 line
2.25.1
PATCH v3 1/2 mtd: spi-nor: Move Software Write Protection logic out of the core
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.
---
v3:
- Add description at the top of swp.c file:
"SPI NOR Software Write Protection logic."
- Move if (!nor->params->locking_ops) check in spi_nor_register_locking_ops()
v2: new patch
drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 406 +-------------------------------- drivers/mtd/spi-nor/core.h | 4 + drivers/mtd/spi-nor/swp.c | 424 +++++++++++++++++++++++++++++++++++ 4 files changed, 432 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 +3 -403
436 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 +424 -0
424 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v3 1/2] mtd: spi-nor: Move Software Write Protection logic out of the core
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 in
swp.c.Signed-off-by Tudor Ambarus <[email protected]>
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments Inc.
Re: [PATCH v3 1/2] mtd: spi-nor: Move Software Write Protection logic out of the core
In reply to Tudor AmbarusAm 2021-03-22 08:51, schrieb Tudor Ambarus:
Quoted 6 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]>
-michael
PATCH v3 2/2 mtd: spi-nor: swp: Improve code around spi_nor_check_lock_status_sr()
In reply to Tudor Ambarus- bool return value for spi_nor_check_lock_status_sr(), gets rid of the return 1,
- introduce temporary variables for better readability.
---
v3: new patch
drivers/mtd/spi-nor/swp.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
drivers/mtd/spi-nor/swp.c +15 -12
@@ -81,36 +81,39 @@ 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, -uint64_t len,u8 sr,bool locked) +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; +loff_t lock_offs, lock_offs_max, offs_max;uint64_t lock_len;if (!len) -return 1 ; +return true;spi_nor_get_locked_range_sr (nor, sr, &lock_offs, &lock_len); + lock_offs_max = lock_offs + lock_len; + offs_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 (offs_max <= lock_offs_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_offs_max) || (offs_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); }
Signature · 1 line
2.25.1
Re: [PATCH v3 2/2] mtd: spi-nor: swp: Improve code around spi_nor_check_lock_status_sr()
Quoted 6 lines · Tudor Ambarus
- bool return value for
spi_nor_check_lock_status_sr(), gets rid of the return 1,
- introduce temporary variables for better readability.Suggested-by Joe Perches <[email protected]>Signed-off-by Tudor Ambarus <[email protected]>
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments Inc.
Re: [PATCH v3 2/2] mtd: spi-nor: swp: Improve code around spi_nor_check_lock_status_sr()
In reply to Tudor AmbarusAm 2021-03-22 08:51, schrieb Tudor Ambarus:
Quoted 7 lines
- bool return value for
spi_nor_check_lock_status_sr(), gets rid of the return 1,
- introduce temporary variables for better readability.Suggested-by Joe Perches <[email protected]>Signed-off-by Tudor Ambarus <[email protected]>---
-michael
Tudor Ambarus
AppliedQuoted 6 lines · Tudor Ambarus
Various cleanup patches done while reviewing contributions.
Tudor Ambarus (2):
mtd: spi-nor: Move Software Write Protection logic out of the core
mtd: spi-nor: swp: Improve code aroundspi_nor_check_lock_status_sr()
Quoted 6 lines
drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 406 +-------------------------------- drivers/mtd/spi-nor/core.h | 4 + drivers/mtd/spi-nor/swp.c | 427 +++++++++++++++++++++++++++++++++++ 4 files changed, 435 insertions(+), 404 deletions(-) create mode 100644 drivers/mtd/spi-nor/swp.c
Applied to spi-nor/next, thanks!
[1/2] mtd: spi-nor: Move Software Write Protection logic out of the core
https://git.kernel.org/mtd/c/c4c795105f29 [2/2] mtd: spi-nor: swp: Improve code around spi_nor_check_lock_status_sr() https://git.kernel.org/mtd/c/b6cbd9167d44
Best regards,
Signature · 1 line
Tudor Ambarus <[email protected]>