summaryrefslogtreecommitdiff
path: root/drivers/mtd/mtdconcat.c
diff options
context:
space:
mode:
authorChris Packham <chris.packham@alliedtelesis.co.nz>2019-05-23 11:19:47 +1200
committerRichard Weinberger <richard@nod.at>2019-07-07 20:39:16 +0200
commit6a08a2f12781ca788759ff73acf1f36f6ae3f9b7 (patch)
tree7fb10893ff8afab15e9bfd7200c9ed58a15a71a6 /drivers/mtd/mtdconcat.c
parentdf616d7a442b90798d63fbf4447154bbbb9040b1 (diff)
mtd: concat: refactor concat_lock/concat_unlock
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> Signed-off-by: Richard Weinberger <richard@nod.at>
Diffstat (limited to 'drivers/mtd/mtdconcat.c')
-rw-r--r--drivers/mtd/mtdconcat.c44
1 files changed, 12 insertions, 32 deletions
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index 7324ff832b41..c9785f96070e 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -437,7 +437,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;
@@ -456,7 +457,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;
@@ -471,38 +475,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)