Linux-mtd Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 1/2] mtd: spi-nor: fix spi_nor_lock_and_prep() usage
@ 2020-01-07 22:23 Michael Walle
  2020-01-07 22:23 ` [PATCH 2/2] mtd: spi-nor: fix locking argument in spi_nor_is_locked() Michael Walle
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Walle @ 2020-01-07 22:23 UTC (permalink / raw)
  To: linux-mtd, linux-kernel
  Cc: Vignesh Raghavendra, Tudor Ambarus, Richard Weinberger,
	Michael Walle, Miquel Raynal, Brian Norris

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}")
Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/mtd/spi-nor/spi-nor.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index b381bc0f825e..5cc4c0b331b3 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -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;
 }
 
-- 
2.20.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] mtd: spi-nor: fix locking argument in spi_nor_is_locked()
  2020-01-07 22:23 [PATCH 1/2] mtd: spi-nor: fix spi_nor_lock_and_prep() usage Michael Walle
@ 2020-01-07 22:23 ` Michael Walle
  2020-01-13 10:10   ` Tudor.Ambarus
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Walle @ 2020-01-07 22:23 UTC (permalink / raw)
  To: linux-mtd, linux-kernel
  Cc: Vignesh Raghavendra, Tudor Ambarus, Richard Weinberger,
	Michael Walle, Miquel Raynal, Brian Norris

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")
Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/mtd/spi-nor/spi-nor.c | 4 ++--
 include/linux/mtd/spi-nor.h   | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 5cc4c0b331b3..d422aead9f36 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -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;
 }
 
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index b661fd948a25..a8fcb1d70510 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -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 {
-- 
2.20.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] mtd: spi-nor: fix locking argument in spi_nor_is_locked()
  2020-01-07 22:23 ` [PATCH 2/2] mtd: spi-nor: fix locking argument in spi_nor_is_locked() Michael Walle
@ 2020-01-13 10:10   ` Tudor.Ambarus
  2020-01-13 10:19     ` Michael Walle
  0 siblings, 1 reply; 5+ messages in thread
From: Tudor.Ambarus @ 2020-01-13 10:10 UTC (permalink / raw)
  To: michael
  Cc: vigneshr, richard, linux-kernel, linux-mtd, miquel.raynal,
	computersforpeace

Hi, Michael,

On Wednesday, January 8, 2020 12:23:17 AM EET Michael Walle wrote:
> diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
> index b661fd948a25..a8fcb1d70510 100644
> --- a/include/linux/mtd/spi-nor.h
> +++ b/include/linux/mtd/spi-nor.h
> @@ -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


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] mtd: spi-nor: fix locking argument in spi_nor_is_locked()
  2020-01-13 10:10   ` Tudor.Ambarus
@ 2020-01-13 10:19     ` Michael Walle
  2020-01-13 11:09       ` Tudor.Ambarus
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Walle @ 2020-01-13 10:19 UTC (permalink / raw)
  To: Tudor.Ambarus
  Cc: vigneshr, richard, linux-kernel, linux-mtd, miquel.raynal,
	computersforpeace

Am 2020-01-13 11:10, schrieb Tudor.Ambarus@microchip.com:
> Hi, Michael,
> 
> On Wednesday, January 8, 2020 12:23:17 AM EET Michael Walle wrote:
>> diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
>> index b661fd948a25..a8fcb1d70510 100644
>> --- a/include/linux/mtd/spi-nor.h
>> +++ b/include/linux/mtd/spi-nor.h
>> @@ -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

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] mtd: spi-nor: fix locking argument in spi_nor_is_locked()
  2020-01-13 10:19     ` Michael Walle
@ 2020-01-13 11:09       ` Tudor.Ambarus
  0 siblings, 0 replies; 5+ messages in thread
From: Tudor.Ambarus @ 2020-01-13 11:09 UTC (permalink / raw)
  To: michael, vigneshr
  Cc: richard, computersforpeace, linux-mtd, linux-kernel, miquel.raynal

On Monday, January 13, 2020 12:19:47 PM EET Michael Walle wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the
> content is safe
> Am 2020-01-13 11:10, schrieb Tudor.Ambarus@microchip.com:
> > Hi, Michael,
> > 
> > On Wednesday, January 8, 2020 12:23:17 AM EET Michael Walle wrote:
> >> diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
> >> index b661fd948a25..a8fcb1d70510 100644
> >> --- a/include/linux/mtd/spi-nor.h
> >> +++ b/include/linux/mtd/spi-nor.h
> >> @@ -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

yes

> 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.
 
> 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



______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-07 22:23 [PATCH 1/2] mtd: spi-nor: fix spi_nor_lock_and_prep() usage Michael Walle
2020-01-07 22:23 ` [PATCH 2/2] mtd: spi-nor: fix locking argument in spi_nor_is_locked() Michael Walle
2020-01-13 10:10   ` Tudor.Ambarus
2020-01-13 10:19     ` Michael Walle
2020-01-13 11:09       ` Tudor.Ambarus

Linux-mtd Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mtd/0 linux-mtd/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mtd linux-mtd/ https://lore.kernel.org/linux-mtd \
		linux-mtd@lists.infradead.org
	public-inbox-index linux-mtd

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-mtd


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git