[RFC PATCH 4/8] mtd: spi-nor: Reorder the preparation vs locking steps
Miquel Raynal
miquel.raynal at bootlin.com
Wed May 25 09:31:04 PDT 2022
The ->prepare()/->unprepare() hooks are now legacy, and there are only
two controllers left supporting them. In both cases, the implementation
acquires a mutex, which is somehow redundant with the spi-nor main lock
that we acquire as well in the spi_nor_[un]lock_and_[un]prep() helpers.
While the mutex taken in the core is necessary, the helper can be
reorganized to first do the preparation, then acquire the core
lock. This is necessary in order to be able to improve the locking
mechanism in the core and should have no side effect.
Signed-off-by: Miquel Raynal <miquel.raynal at bootlin.com>
---
drivers/mtd/spi-nor/core.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index a9698d6b9813..cea023f2d169 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -1069,23 +1069,20 @@ int spi_nor_lock_and_prep(struct spi_nor *nor)
{
int ret = 0;
- mutex_lock(&nor->lock);
-
- if (nor->controller_ops && nor->controller_ops->prepare) {
+ if (nor->controller_ops && nor->controller_ops->prepare)
ret = nor->controller_ops->prepare(nor);
- if (ret) {
- mutex_unlock(&nor->lock);
- return ret;
- }
- }
+
+ mutex_lock(&nor->lock);
+
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)
--
2.34.1
More information about the linux-mtd
mailing list