Linux-mtd Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2 1/2] mtd: concat: refactor concat_lock/concat_unlock
@ 2019-05-22 23:19 Chris Packham
  2019-05-22 23:19 ` [PATCH v2 2/2] mtd: concat: implement _is_locked mtd operation Chris Packham
  2019-06-14  3:26 ` [PATCH v2 1/2] mtd: concat: refactor concat_lock/concat_unlock Chris Packham
  0 siblings, 2 replies; 6+ messages in thread
From: Chris Packham @ 2019-05-22 23:19 UTC (permalink / raw)
  To: dwmw2, computersforpeace, marek.vasut, miquel.raynal, richard, vigneshr
  Cc: Chris Packham, linux-mtd, linux-kernel

concat_lock() and concat_unlock() only differed in terms of the mtd_xx
operation they called. Refactor them to use a common helper function and
pass a boolean flag to indicate whether lock or unlock is needed.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Changes in v2:
- Use a boolean flag instead of passing a function pointer.

 drivers/mtd/mtdconcat.c | 44 +++++++++++------------------------------
 1 file changed, 12 insertions(+), 32 deletions(-)

diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index cbc5925e6440..6cb60dea509a 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -451,7 +451,8 @@ static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
 	return err;
 }
 
-static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
+static int concat_xxlock(struct mtd_info *mtd, loff_t ofs, uint64_t len,
+			 bool is_lock)
 {
 	struct mtd_concat *concat = CONCAT(mtd);
 	int i, err = -EINVAL;
@@ -470,7 +471,10 @@ static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 		else
 			size = len;
 
-		err = mtd_lock(subdev, ofs, size);
+		if (is_lock)
+			err = mtd_lock(subdev, ofs, size);
+		else
+			err = mtd_unlock(subdev, ofs, size);
 		if (err)
 			break;
 
@@ -485,38 +489,14 @@ static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 	return err;
 }
 
-static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
+static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 {
-	struct mtd_concat *concat = CONCAT(mtd);
-	int i, err = 0;
-
-	for (i = 0; i < concat->num_subdev; i++) {
-		struct mtd_info *subdev = concat->subdev[i];
-		uint64_t size;
-
-		if (ofs >= subdev->size) {
-			size = 0;
-			ofs -= subdev->size;
-			continue;
-		}
-		if (ofs + len > subdev->size)
-			size = subdev->size - ofs;
-		else
-			size = len;
-
-		err = mtd_unlock(subdev, ofs, size);
-		if (err)
-			break;
-
-		len -= size;
-		if (len == 0)
-			break;
-
-		err = -EINVAL;
-		ofs = 0;
-	}
+	return concat_xxlock(mtd, ofs, len, true);
+}
 
-	return err;
+static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
+{
+	return concat_xxlock(mtd, ofs, len, false);
 }
 
 static void concat_sync(struct mtd_info *mtd)
-- 
2.21.0


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

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

* [PATCH v2 2/2] mtd: concat: implement _is_locked mtd operation
  2019-05-22 23:19 [PATCH v2 1/2] mtd: concat: refactor concat_lock/concat_unlock Chris Packham
@ 2019-05-22 23:19 ` Chris Packham
  2019-06-14  3:26 ` [PATCH v2 1/2] mtd: concat: refactor concat_lock/concat_unlock Chris Packham
  1 sibling, 0 replies; 6+ messages in thread
From: Chris Packham @ 2019-05-22 23:19 UTC (permalink / raw)
  To: dwmw2, computersforpeace, marek.vasut, miquel.raynal, richard, vigneshr
  Cc: Chris Packham, linux-mtd, linux-kernel

Add an implementation of the _is_locked operation for concatenated mtd
devices. This doesn't handle getting the lock status of a range that
spans chips, which is consistent with cfi_ppb_is_locked and
cfi_intelext_is_locked which only look at the first block in the range.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Changes in v2:
- Don't re-use the xxlock helper.
- Explicitly disallow ranges that span chips.

 drivers/mtd/mtdconcat.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index 6cb60dea509a..eef0612c2e94 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -499,6 +499,28 @@ static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 	return concat_xxlock(mtd, ofs, len, false);
 }
 
+static int concat_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
+{
+	struct mtd_concat *concat = CONCAT(mtd);
+	int i, err = -EINVAL;
+
+	for (i = 0; i < concat->num_subdev; i++) {
+		struct mtd_info *subdev = concat->subdev[i];
+
+		if (ofs >= subdev->size) {
+			ofs -= subdev->size;
+			continue;
+		}
+
+		if (ofs + len > subdev->size)
+			break;
+
+		return mtd_is_locked(subdev, ofs, len);
+	}
+
+	return err;
+}
+
 static void concat_sync(struct mtd_info *mtd)
 {
 	struct mtd_concat *concat = CONCAT(mtd);
@@ -698,6 +720,7 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[],	/* subdevices to c
 	concat->mtd._sync = concat_sync;
 	concat->mtd._lock = concat_lock;
 	concat->mtd._unlock = concat_unlock;
+	concat->mtd._is_locked = concat_is_locked;
 	concat->mtd._suspend = concat_suspend;
 	concat->mtd._resume = concat_resume;
 
-- 
2.21.0


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

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

* Re: [PATCH v2 1/2] mtd: concat: refactor concat_lock/concat_unlock
  2019-05-22 23:19 [PATCH v2 1/2] mtd: concat: refactor concat_lock/concat_unlock Chris Packham
  2019-05-22 23:19 ` [PATCH v2 2/2] mtd: concat: implement _is_locked mtd operation Chris Packham
@ 2019-06-14  3:26 ` Chris Packham
  2019-06-17 22:07   ` Richard Weinberger
  1 sibling, 1 reply; 6+ messages in thread
From: Chris Packham @ 2019-06-14  3:26 UTC (permalink / raw)
  To: dwmw2, computersforpeace, marek.vasut, miquel.raynal, richard, vigneshr
  Cc: linux-mtd, linux-kernel

Hi All,

Ping?

On 23/05/19 11:19 AM, Chris Packham wrote:
> concat_lock() and concat_unlock() only differed in terms of the mtd_xx
> operation they called. Refactor them to use a common helper function and
> pass a boolean flag to indicate whether lock or unlock is needed.
> 
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> ---
> Changes in v2:
> - Use a boolean flag instead of passing a function pointer.
> 
>   drivers/mtd/mtdconcat.c | 44 +++++++++++------------------------------
>   1 file changed, 12 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
> index cbc5925e6440..6cb60dea509a 100644
> --- a/drivers/mtd/mtdconcat.c
> +++ b/drivers/mtd/mtdconcat.c
> @@ -451,7 +451,8 @@ static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
>   	return err;
>   }
>   
> -static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
> +static int concat_xxlock(struct mtd_info *mtd, loff_t ofs, uint64_t len,
> +			 bool is_lock)
>   {
>   	struct mtd_concat *concat = CONCAT(mtd);
>   	int i, err = -EINVAL;
> @@ -470,7 +471,10 @@ static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
>   		else
>   			size = len;
>   
> -		err = mtd_lock(subdev, ofs, size);
> +		if (is_lock)
> +			err = mtd_lock(subdev, ofs, size);
> +		else
> +			err = mtd_unlock(subdev, ofs, size);
>   		if (err)
>   			break;
>   
> @@ -485,38 +489,14 @@ static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
>   	return err;
>   }
>   
> -static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
> +static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
>   {
> -	struct mtd_concat *concat = CONCAT(mtd);
> -	int i, err = 0;
> -
> -	for (i = 0; i < concat->num_subdev; i++) {
> -		struct mtd_info *subdev = concat->subdev[i];
> -		uint64_t size;
> -
> -		if (ofs >= subdev->size) {
> -			size = 0;
> -			ofs -= subdev->size;
> -			continue;
> -		}
> -		if (ofs + len > subdev->size)
> -			size = subdev->size - ofs;
> -		else
> -			size = len;
> -
> -		err = mtd_unlock(subdev, ofs, size);
> -		if (err)
> -			break;
> -
> -		len -= size;
> -		if (len == 0)
> -			break;
> -
> -		err = -EINVAL;
> -		ofs = 0;
> -	}
> +	return concat_xxlock(mtd, ofs, len, true);
> +}
>   
> -	return err;
> +static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
> +{
> +	return concat_xxlock(mtd, ofs, len, false);
>   }
>   
>   static void concat_sync(struct mtd_info *mtd)
> 


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

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

* Re: [PATCH v2 1/2] mtd: concat: refactor concat_lock/concat_unlock
  2019-06-14  3:26 ` [PATCH v2 1/2] mtd: concat: refactor concat_lock/concat_unlock Chris Packham
@ 2019-06-17 22:07   ` Richard Weinberger
  2019-06-17 22:11     ` Chris Packham
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Weinberger @ 2019-06-17 22:07 UTC (permalink / raw)
  To: Chris Packham
  Cc: vigneshr, richard, linux-kernel, marek.vasut, linux-mtd,
	miquel.raynal, computersforpeace, dwmw2

On Fri, Jun 14, 2019 at 5:26 AM Chris Packham
<Chris.Packham@alliedtelesis.co.nz> wrote:
>
> Hi All,
>
> Ping?

Your patch is not lost. We start soon with collecting all material for
the merge window. :-)

-- 
Thanks,
//richard

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

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

* Re: [PATCH v2 1/2] mtd: concat: refactor concat_lock/concat_unlock
  2019-06-17 22:07   ` Richard Weinberger
@ 2019-06-17 22:11     ` Chris Packham
  2019-07-07 18:45       ` Richard Weinberger
  0 siblings, 1 reply; 6+ messages in thread
From: Chris Packham @ 2019-06-17 22:11 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: vigneshr, richard, linux-kernel, marek.vasut, linux-mtd,
	miquel.raynal, computersforpeace, dwmw2

On 18/06/19 10:08 AM, Richard Weinberger wrote:
> On Fri, Jun 14, 2019 at 5:26 AM Chris Packham
> <Chris.Packham@alliedtelesis.co.nz> wrote:
>>
>> Hi All,
>>
>> Ping?
> 
> Your patch is not lost. We start soon with collecting all material for
> the merge window. :-)
> 

OK thanks for the confirmation and sorry for the noise.

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

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

* Re: [PATCH v2 1/2] mtd: concat: refactor concat_lock/concat_unlock
  2019-06-17 22:11     ` Chris Packham
@ 2019-07-07 18:45       ` Richard Weinberger
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Weinberger @ 2019-07-07 18:45 UTC (permalink / raw)
  To: Chris Packham
  Cc: vigneshr, richard, linux-kernel, marek.vasut, linux-mtd,
	miquel.raynal, computersforpeace, dwmw2

On Tue, Jun 18, 2019 at 12:11 AM Chris Packham
<Chris.Packham@alliedtelesis.co.nz> wrote:
>
> On 18/06/19 10:08 AM, Richard Weinberger wrote:
> > On Fri, Jun 14, 2019 at 5:26 AM Chris Packham
> > <Chris.Packham@alliedtelesis.co.nz> wrote:
> >>
> >> Hi All,
> >>
> >> Ping?
> >
> > Your patch is not lost. We start soon with collecting all material for
> > the merge window. :-)
> >
>
> OK thanks for the confirmation and sorry for the noise.

Applied. :-)

-- 
Thanks,
//richard

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

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

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-22 23:19 [PATCH v2 1/2] mtd: concat: refactor concat_lock/concat_unlock Chris Packham
2019-05-22 23:19 ` [PATCH v2 2/2] mtd: concat: implement _is_locked mtd operation Chris Packham
2019-06-14  3:26 ` [PATCH v2 1/2] mtd: concat: refactor concat_lock/concat_unlock Chris Packham
2019-06-17 22:07   ` Richard Weinberger
2019-06-17 22:11     ` Chris Packham
2019-07-07 18:45       ` Richard Weinberger

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 linux-mtd@archiver.kernel.org
	public-inbox-index linux-mtd


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