Skip to content

Commit 2e3a747

Browse files
mwallePratyush Yadav
authored andcommitted
mtd: spi-nor: Fix spi_nor_try_unlock_all()
Commit ff67592 ("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. Fixes: ff67592 ("mtd: spi-nor: Introduce spi_nor_set_mtd_info()") Cc: [email protected] Reported-by: Jean-Marc Ranger <[email protected]> Closes: https://lore.kernel.org/all/DM6PR06MB561177323DC5207E34AF2A06C547A@DM6PR06MB5611.namprd06.prod.outlook.com/ Tested-by: Jean-Marc Ranger <[email protected]> Signed-off-by: Michael Walle <[email protected]> Reviewed-by: Pratyush Yadav <[email protected]> Signed-off-by: Pratyush Yadav <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 12da2e6 commit 2e3a747

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

drivers/mtd/spi-nor/swp.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ static u64 spi_nor_get_min_prot_length_sr(struct spi_nor *nor)
5656
static void spi_nor_get_locked_range_sr(struct spi_nor *nor, u8 sr, loff_t *ofs,
5757
u64 *len)
5858
{
59-
struct mtd_info *mtd = &nor->mtd;
6059
u64 min_prot_len;
6160
u8 mask = spi_nor_get_sr_bp_mask(nor);
6261
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,
7776
min_prot_len = spi_nor_get_min_prot_length_sr(nor);
7877
*len = min_prot_len << (bp - 1);
7978

80-
if (*len > mtd->size)
81-
*len = mtd->size;
79+
if (*len > nor->params->size)
80+
*len = nor->params->size;
8281

8382
if (nor->flags & SNOR_F_HAS_SR_TB && sr & tb_mask)
8483
*ofs = 0;
8584
else
86-
*ofs = mtd->size - *len;
85+
*ofs = nor->params->size - *len;
8786
}
8887

8988
/*
@@ -158,7 +157,6 @@ static bool spi_nor_is_unlocked_sr(struct spi_nor *nor, loff_t ofs, u64 len,
158157
*/
159158
static int spi_nor_sr_lock(struct spi_nor *nor, loff_t ofs, u64 len)
160159
{
161-
struct mtd_info *mtd = &nor->mtd;
162160
u64 min_prot_len;
163161
int ret, status_old, status_new;
164162
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)
183181
can_be_bottom = false;
184182

185183
/* If anything above us is unlocked, we can't use 'top' protection */
186-
if (!spi_nor_is_locked_sr(nor, ofs + len, mtd->size - (ofs + len),
184+
if (!spi_nor_is_locked_sr(nor, ofs + len, nor->params->size - (ofs + len),
187185
status_old))
188186
can_be_top = false;
189187

@@ -195,11 +193,11 @@ static int spi_nor_sr_lock(struct spi_nor *nor, loff_t ofs, u64 len)
195193

196194
/* lock_len: length of region that should end up locked */
197195
if (use_top)
198-
lock_len = mtd->size - ofs;
196+
lock_len = nor->params->size - ofs;
199197
else
200198
lock_len = ofs + len;
201199

202-
if (lock_len == mtd->size) {
200+
if (lock_len == nor->params->size) {
203201
val = mask;
204202
} else {
205203
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)
248246
*/
249247
static int spi_nor_sr_unlock(struct spi_nor *nor, loff_t ofs, u64 len)
250248
{
251-
struct mtd_info *mtd = &nor->mtd;
252249
u64 min_prot_len;
253250
int ret, status_old, status_new;
254251
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)
273270
can_be_top = false;
274271

275272
/* If anything above us is locked, we can't use 'bottom' protection */
276-
if (!spi_nor_is_unlocked_sr(nor, ofs + len, mtd->size - (ofs + len),
273+
if (!spi_nor_is_unlocked_sr(nor, ofs + len, nor->params->size - (ofs + len),
277274
status_old))
278275
can_be_bottom = false;
279276

@@ -285,7 +282,7 @@ static int spi_nor_sr_unlock(struct spi_nor *nor, loff_t ofs, u64 len)
285282

286283
/* lock_len: length of region that should remain locked */
287284
if (use_top)
288-
lock_len = mtd->size - (ofs + len);
285+
lock_len = nor->params->size - (ofs + len);
289286
else
290287
lock_len = ofs;
291288

0 commit comments

Comments
 (0)