Skip to contentSkip to conversation

mtd: spi-nor: fix spi_nor_lock_and_prep() usage

PATCH In review Michael Walle 2 participants 5 messages Jan 7, 2020 – Jan 13, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 mtd: spi-nor: fix spi_nor_lock_and_prep() usage

lock_and_prep() and unlock_and_unprep() are asymmetrical. The second argument should be the same and represents the operation. This was correct before commit 8cc7f33aadc8 ("mtd: spi-nor: factor out replace-able flash_{lock,unlock}").

Fixes 8cc7f33aadc8 ("mtd: spi-nor: factor out replace-able flash_{lock,unlock}")
---
 drivers/mtd/spi-nor/spi-nor.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +2 -2
index b381bc0f825e..5cc4c0b331b3 100644
@@ -2047,7 +2047,7 @@ static int spi_nor_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 
 	ret = nor->params.locking_ops->lock(nor, ofs, len);
 
-	spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_UNLOCK);
+	spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_LOCK);
 	return ret;
 }
 
@@ -2062,7 +2062,7 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 
 	ret = nor->params.locking_ops->unlock(nor, ofs, len);
 
-	spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_LOCK);
+	spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_UNLOCK);
 	return ret;
 }
 
Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/2 mtd: spi-nor: fix locking argument in spi_nor_is_locked()

The second argument represents the operation which takes the lock. Add a new SPI_NOR_OPS_IS_LOCKED and use it.

Fixes 5bf0e69b67a5 ("mtd: spi-nor: add mtd_is_locked() support")
---
 drivers/mtd/spi-nor/spi-nor.c | 4 ++--
 include/linux/mtd/spi-nor.h   | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +2 -2
index 5cc4c0b331b3..d422aead9f36 100644
@@ -2071,13 +2071,13 @@ 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, SPI_NOR_OPS_UNLOCK);
+	ret = spi_nor_lock_and_prep(nor, SPI_NOR_OPS_IS_LOCKED);
 	if (ret)
 		return ret;
 
 	ret = nor->params.locking_ops->is_locked(nor, ofs, len);
 
-	spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_LOCK);
+	spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_IS_LOCKED);
 	return ret;
 }
 
include/linux/mtd/spi-nor.h +1 -0
index b661fd948a25..a8fcb1d70510 100644
@@ -235,6 +235,7 @@ enum spi_nor_ops {
 	SPI_NOR_OPS_ERASE,
 	SPI_NOR_OPS_LOCK,
 	SPI_NOR_OPS_UNLOCK,
+	SPI_NOR_OPS_IS_LOCKED,
 };
 
 enum spi_nor_option_flags {
Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH 2/2] mtd: spi-nor: fix locking argument in spi_nor_is_locked()

Hi, Michael,

include/linux/mtd/spi-nor.h enum spi_nor_ops { · line 239

Quoted 10 lines · EET Michael Walle
include/linux/mtd/spi-nor.h +1 -0
index b661fd948a25..a8fcb1d70510 100644
@@ -235,6 +235,7 @@ enum spi_nor_ops {
        SPI_NOR_OPS_ERASE,
        SPI_NOR_OPS_LOCK,
        SPI_NOR_OPS_UNLOCK,
+       SPI_NOR_OPS_IS_LOCKED,
 };

There is no NOR controller that uses this enum, can we get rid of it?

Cheers,
ta

#3 lore raw

Re: [PATCH 2/2] mtd: spi-nor: fix locking argument in spi_nor_is_locked()

Am 2020-01-13 11:10, schrieb [email protected]:

Quoted 15 lines

Hi, Michael,

include/linux/mtd/spi-nor.h enum spi_nor_ops { · line 239

Quoted 10 lines · EET Michael Walle
include/linux/mtd/spi-nor.h +1 -0
index b661fd948a25..a8fcb1d70510 100644
@@ -235,6 +235,7 @@ enum spi_nor_ops {
        SPI_NOR_OPS_ERASE,
        SPI_NOR_OPS_LOCK,
        SPI_NOR_OPS_UNLOCK,
+       SPI_NOR_OPS_IS_LOCKED,
 };

There is no NOR controller that uses this enum, can we get rid of it?

you mean the second argument of the spi_nor_lock_and_prep() and spi_nor_unlock_and_unprep()? sure. But it removes information from the prepare() callback. like in "prepare what?". From what I see its only used for locking. Maybe then rename it to prepare_lock and prepare_unlock.

-michael

#4 lore raw

Re: [PATCH 2/2] mtd: spi-nor: fix locking argument in spi_nor_is_locked()

Quoted 16 lines · EET Michael Walle

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Am 2020-01-13 11:10, schrieb [email protected]:

Quoted 13 lines

Hi, Michael,

Quoted 10 lines · EET Michael Walle
include/linux/mtd/spi-nor.h +0 -0
index b661fd948a25..a8fcb1d70510 100644
@@ -235,6 +235,7 @@ enum spi_nor_ops {
 
        SPI_NOR_OPS_ERASE,
        SPI_NOR_OPS_LOCK,
        SPI_NOR_OPS_UNLOCK,
 
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
include/linux/mtd/spi-nor.h +1 -0
+       SPI_NOR_OPS_IS_LOCKED,
 

};

There is no NOR controller that uses this enum, can we get rid of it?

you mean the second argument of the spi_nor_lock_and_prep() and spi_nor_unlock_and_unprep()? sure. But it removes information from the

yes

Quoted 1 line

prepare() callback. like in "prepare what?". From what I see its only

Prepare the controller for whatever op. As I see, it is used for taking a bus mutex and for enabling some clock.

Quoted 3 lines

used for locking. Maybe then rename it to prepare_lock and prepare_unlock.

I would keep the function name as it is. Maybe Vignesh has some other opinion on this?

Cheers,
ta