mtd: spi-nor: Fix spi_nor_try_unlock_all()
Subsystems (3)
Michael Walle
maintainerPATCH 1/1 mtd: spi-nor: Fix spi_nor_try_unlock_all()
Commit ff67592cbdfc ("mtd: spi-nor: Introduce spi_nor_set_mtd_info()") moved all initialization of the mtd fields at the end of spi_nor_scan(). Normally, the mtd info is only needed for the mtd ops on the device, with one exception: spi_nor_try_unlock_all(), which will also make use of the mtd->size parameter. With that commit, the size will always be zero because it is not initialized. Fix that by not using the size of the mtd_info struct, but use the size from struct spi_nor_flash_parameter.
--- drivers/mtd/spi-nor/swp.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/mtd/spi-nor/swp.c +8 -11
@@ -56,7 +56,6 @@ static u64 spi_nor_get_min_prot_length_sr(struct spi_nor *nor)static void spi_nor_get_locked_range_sr (struct spi_nor *nor,u8 sr,loff_t *ofs,u64 *len) { -struct mtd_info *mtd = &nor->mtd;u64 min_prot_len;u8 mask =spi_nor_get_sr_bp_mask (nor);u8 tb_mask =spi_nor_get_sr_tb_mask (nor);
@@ -77,13 +76,13 @@ static void spi_nor_get_locked_range_sr(struct spi_nor *nor, u8 sr, loff_t *ofs, min_prot_len =spi_nor_get_min_prot_length_sr (nor); *len = min_prot_len << (bp -1 ); -if (*len > mtd->size) - *len = mtd->size; +if (*len > nor->params->size) + *len = nor->params->size;if (nor->flags &SNOR_F_HAS_SR_TB && sr & tb_mask) *ofs =0 ;else - *ofs = mtd->size - *len; + *ofs = nor->params->size - *len; }/*
@@ -158,7 +157,6 @@ static bool spi_nor_is_unlocked_sr(struct spi_nor *nor, loff_t ofs, u64 len,*/ static int spi_nor_sr_lock (struct spi_nor *nor,loff_t ofs,u64 len) { -struct mtd_info *mtd = &nor->mtd;u64 min_prot_len;int ret, status_old, status_new;u8 mask =spi_nor_get_sr_bp_mask (nor);
@@ -183,7 +181,7 @@ static int spi_nor_sr_lock(struct spi_nor *nor, loff_t ofs, u64 len) can_be_bottom = false;/* If anything above us is unlocked, we can't use 'top' protection */ -if (!spi_nor_is_locked_sr (nor, ofs + len, mtd->size - (ofs + len), +if (!spi_nor_is_locked_sr (nor, ofs + len, nor->params->size - (ofs + len), status_old)) can_be_top = false;
@@ -195,11 +193,11 @@ static int spi_nor_sr_lock(struct spi_nor *nor, loff_t ofs, u64 len)/* lock_len: length of region that should end up locked */ if (use_top) - lock_len = mtd->size - ofs; + lock_len = nor->params->size - ofs;else lock_len = ofs + len; -if (lock_len == mtd->size) { +if (lock_len == nor->params->size) { val = mask; }else { min_prot_len =spi_nor_get_min_prot_length_sr (nor);
@@ -248,7 +246,6 @@ static int spi_nor_sr_lock(struct spi_nor *nor, loff_t ofs, u64 len)*/ static int spi_nor_sr_unlock (struct spi_nor *nor,loff_t ofs,u64 len) { -struct mtd_info *mtd = &nor->mtd;u64 min_prot_len;int ret, status_old, status_new;u8 mask =spi_nor_get_sr_bp_mask (nor);
@@ -273,7 +270,7 @@ static int spi_nor_sr_unlock(struct spi_nor *nor, loff_t ofs, u64 len) can_be_top = false;/* If anything above us is locked, we can't use 'bottom' protection */ -if (!spi_nor_is_unlocked_sr (nor, ofs + len, mtd->size - (ofs + len), +if (!spi_nor_is_unlocked_sr (nor, ofs + len, nor->params->size - (ofs + len), status_old)) can_be_bottom = false;
@@ -285,7 +282,7 @@ static int spi_nor_sr_unlock(struct spi_nor *nor, loff_t ofs, u64 len)/* lock_len: length of region that should remain locked */ if (use_top) - lock_len = mtd->size - (ofs + len); + lock_len = nor->params->size - (ofs + len);else lock_len = ofs;
Signature · 1 line
2.39.5
Quoted 7 lines · Michael Walle
Commit
ff67592cbdfc("mtd: spi-nor: Introducespi_nor_set_mtd_info()") moved all initialization of the mtd fields at the end ofspi_nor_scan(). Normally, the mtd info is only needed for the mtd ops on the device, with one exception:spi_nor_try_unlock_all(), which will also make use of themtd->sizeparameter. With that commit, the size will always be zero because it is not initialized. Fix that by not using the size of themtd_infostruct, but use the size from structspi_nor_flash_parameter.
I suppose some of this code would be cleaner if we declared a size variable instead of typing out nor->params->size every time, but I don't think it matters too much so this patch is fine too. Thanks for fixing this!
[...]
Signature · 2 lines
Regards, Pratyush Yadav
Pratyush Yadav
maintainerQuoted 8 lines · Michael Walle
Commit
ff67592cbdfc("mtd: spi-nor: Introducespi_nor_set_mtd_info()") moved all initialization of the mtd fields at the end ofspi_nor_scan(). Normally, the mtd info is only needed for the mtd ops on the device, with one exception:spi_nor_try_unlock_all(), which will also make use of themtd->sizeparameter. With that commit, the size will always be zero because it is not initialized. Fix that by not using the size of themtd_infostruct, but use the size from structspi_nor_flash_parameter.
Quoted 6 lines
Fixes ff67592cbdfc ("mtd: spi-nor: Introduce spi_nor_set_mtd_info()")Reported-by Jean-Marc Ranger <[email protected]>Closes https://lore.kernel.org/all/DM6PR06MB561177323DC5207E34AF2A06C547A@DM6PR06MB5611.namprd06.prod.outlook.com/ open hereTested-by Jean-Marc Ranger <[email protected]>Signed-off-by Michael Walle <[email protected]>
This patch hasn't had much time on the list but we are already at -rc4 and I want it to get some time in linux-next. If later reviews come in and changes are needed, I can drop it and apply the new version. So applied to spi-nor/next. Thanks!
[...]
Signature · 2 lines
Regards, Pratyush Yadav