diff mbox series

[v2,1/2] mtd: concat: refactor concat_lock/concat_unlock

Message ID 20190522231948.17559-1-chris.packham@alliedtelesis.co.nz
State Accepted
Delegated to: Richard Weinberger
Headers show
Series [v2,1/2] mtd: concat: refactor concat_lock/concat_unlock | expand

Commit Message

Chris Packham May 22, 2019, 11:19 p.m. UTC
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(-)

Comments

Chris Packham June 14, 2019, 3:26 a.m. UTC | #1
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)
>
Richard Weinberger June 17, 2019, 10:07 p.m. UTC | #2
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. :-)
Chris Packham June 17, 2019, 10:11 p.m. UTC | #3
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.
Richard Weinberger July 7, 2019, 6:45 p.m. UTC | #4
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. :-)
diff mbox series

Patch

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)