mirror of
https://github.com/torvalds/linux.git
synced 2024-11-10 14:11:52 +00:00
mtd: spi-nor: Reorder the preparation vs. locking steps
The ->prepare()/->unprepare() hooks are now legacy, we no longer accept new drivers supporting them. The only remaining controllers using them acquires a per-chip mutex, which should not interfere with the rest of the operation done in the core. As a result, we should be safe to reorganize these helpers to first perform the preparation, before acquiring the core locks. This is necessary in order to be able to improve the locking mechanism in the core (coming next). No side effects are expected. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/r/20230328154105.448540-4-miquel.raynal@bootlin.com Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
This commit is contained in:
parent
ccff2cfa1a
commit
3204634772
@ -1070,27 +1070,24 @@ static void spi_nor_set_4byte_opcodes(struct spi_nor *nor)
|
||||
}
|
||||
}
|
||||
|
||||
int spi_nor_lock_and_prep(struct spi_nor *nor)
|
||||
int spi_nor_prep_and_lock(struct spi_nor *nor)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (nor->controller_ops && nor->controller_ops->prepare)
|
||||
ret = nor->controller_ops->prepare(nor);
|
||||
|
||||
mutex_lock(&nor->lock);
|
||||
|
||||
if (nor->controller_ops && nor->controller_ops->prepare) {
|
||||
ret = nor->controller_ops->prepare(nor);
|
||||
if (ret) {
|
||||
mutex_unlock(&nor->lock);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void spi_nor_unlock_and_unprep(struct spi_nor *nor)
|
||||
{
|
||||
mutex_unlock(&nor->lock);
|
||||
|
||||
if (nor->controller_ops && nor->controller_ops->unprepare)
|
||||
nor->controller_ops->unprepare(nor);
|
||||
mutex_unlock(&nor->lock);
|
||||
}
|
||||
|
||||
static u32 spi_nor_convert_addr(struct spi_nor *nor, loff_t addr)
|
||||
@ -1446,7 +1443,7 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
|
||||
addr = instr->addr;
|
||||
len = instr->len;
|
||||
|
||||
ret = spi_nor_lock_and_prep(nor);
|
||||
ret = spi_nor_prep_and_lock(nor);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
@ -1706,7 +1703,7 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
|
||||
|
||||
dev_dbg(nor->dev, "from 0x%08x, len %zd\n", (u32)from, len);
|
||||
|
||||
ret = spi_nor_lock_and_prep(nor);
|
||||
ret = spi_nor_prep_and_lock(nor);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
@ -1752,7 +1749,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
|
||||
|
||||
dev_dbg(nor->dev, "to 0x%08x, len %zd\n", (u32)to, len);
|
||||
|
||||
ret = spi_nor_lock_and_prep(nor);
|
||||
ret = spi_nor_prep_and_lock(nor);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
@ -647,7 +647,7 @@ int spi_nor_write_disable(struct spi_nor *nor);
|
||||
int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable);
|
||||
int spi_nor_wait_till_ready(struct spi_nor *nor);
|
||||
int spi_nor_global_block_unlock(struct spi_nor *nor);
|
||||
int spi_nor_lock_and_prep(struct spi_nor *nor);
|
||||
int spi_nor_prep_and_lock(struct spi_nor *nor);
|
||||
void spi_nor_unlock_and_unprep(struct spi_nor *nor);
|
||||
int spi_nor_sr1_bit6_quad_enable(struct spi_nor *nor);
|
||||
int spi_nor_sr2_bit1_quad_enable(struct spi_nor *nor);
|
||||
|
@ -255,7 +255,7 @@ static int spi_nor_mtd_otp_info(struct mtd_info *mtd, size_t len,
|
||||
if (len < n_regions * sizeof(*buf))
|
||||
return -ENOSPC;
|
||||
|
||||
ret = spi_nor_lock_and_prep(nor);
|
||||
ret = spi_nor_prep_and_lock(nor);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
@ -325,7 +325,7 @@ static int spi_nor_mtd_otp_read_write(struct mtd_info *mtd, loff_t ofs,
|
||||
if (!total_len)
|
||||
return 0;
|
||||
|
||||
ret = spi_nor_lock_and_prep(nor);
|
||||
ret = spi_nor_prep_and_lock(nor);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
@ -415,7 +415,7 @@ static int spi_nor_mtd_otp_erase(struct mtd_info *mtd, loff_t from, size_t len)
|
||||
if (!IS_ALIGNED(len, rlen) || !IS_ALIGNED(from, rlen))
|
||||
return -EINVAL;
|
||||
|
||||
ret = spi_nor_lock_and_prep(nor);
|
||||
ret = spi_nor_prep_and_lock(nor);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
@ -460,7 +460,7 @@ static int spi_nor_mtd_otp_lock(struct mtd_info *mtd, loff_t from, size_t len)
|
||||
if (!IS_ALIGNED(len, rlen) || !IS_ALIGNED(from, rlen))
|
||||
return -EINVAL;
|
||||
|
||||
ret = spi_nor_lock_and_prep(nor);
|
||||
ret = spi_nor_prep_and_lock(nor);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
@ -126,7 +126,7 @@ static int sst_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
|
||||
|
||||
dev_dbg(nor->dev, "to 0x%08x, len %zd\n", (u32)to, len);
|
||||
|
||||
ret = spi_nor_lock_and_prep(nor);
|
||||
ret = spi_nor_prep_and_lock(nor);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
@ -348,7 +348,7 @@ static int spi_nor_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
|
||||
struct spi_nor *nor = mtd_to_spi_nor(mtd);
|
||||
int ret;
|
||||
|
||||
ret = spi_nor_lock_and_prep(nor);
|
||||
ret = spi_nor_prep_and_lock(nor);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
@ -363,7 +363,7 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
|
||||
struct spi_nor *nor = mtd_to_spi_nor(mtd);
|
||||
int ret;
|
||||
|
||||
ret = spi_nor_lock_and_prep(nor);
|
||||
ret = spi_nor_prep_and_lock(nor);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
@ -378,7 +378,7 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
|
||||
struct spi_nor *nor = mtd_to_spi_nor(mtd);
|
||||
int ret;
|
||||
|
||||
ret = spi_nor_lock_and_prep(nor);
|
||||
ret = spi_nor_prep_and_lock(nor);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user