diff options
author | Chris Packham <chris.packham@alliedtelesis.co.nz> | 2019-05-22 19:19:47 -0400 |
---|---|---|
committer | Richard Weinberger <richard@nod.at> | 2019-07-07 14:39:16 -0400 |
commit | 6a08a2f12781ca788759ff73acf1f36f6ae3f9b7 (patch) | |
tree | 7fb10893ff8afab15e9bfd7200c9ed58a15a71a6 /drivers/mtd/mtdconcat.c | |
parent | df616d7a442b90798d63fbf4447154bbbb9040b1 (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.c | 44 |
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) | |||
437 | return err; | 437 | return err; |
438 | } | 438 | } |
439 | 439 | ||
440 | static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) | 440 | static int concat_xxlock(struct mtd_info *mtd, loff_t ofs, uint64_t len, |
441 | bool is_lock) | ||
441 | { | 442 | { |
442 | struct mtd_concat *concat = CONCAT(mtd); | 443 | struct mtd_concat *concat = CONCAT(mtd); |
443 | int i, err = -EINVAL; | 444 | int i, err = -EINVAL; |
@@ -456,7 +457,10 @@ static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) | |||
456 | else | 457 | else |
457 | size = len; | 458 | size = len; |
458 | 459 | ||
459 | err = mtd_lock(subdev, ofs, size); | 460 | if (is_lock) |
461 | err = mtd_lock(subdev, ofs, size); | ||
462 | else | ||
463 | err = mtd_unlock(subdev, ofs, size); | ||
460 | if (err) | 464 | if (err) |
461 | break; | 465 | break; |
462 | 466 | ||
@@ -471,38 +475,14 @@ static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) | |||
471 | return err; | 475 | return err; |
472 | } | 476 | } |
473 | 477 | ||
474 | static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) | 478 | static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) |
475 | { | 479 | { |
476 | struct mtd_concat *concat = CONCAT(mtd); | 480 | return concat_xxlock(mtd, ofs, len, true); |
477 | int i, err = 0; | 481 | } |
478 | |||
479 | for (i = 0; i < concat->num_subdev; i++) { | ||
480 | struct mtd_info *subdev = concat->subdev[i]; | ||
481 | uint64_t size; | ||
482 | |||
483 | if (ofs >= subdev->size) { | ||
484 | size = 0; | ||
485 | ofs -= subdev->size; | ||
486 | continue; | ||
487 | } | ||
488 | if (ofs + len > subdev->size) | ||
489 | size = subdev->size - ofs; | ||
490 | else | ||
491 | size = len; | ||
492 | |||
493 | err = mtd_unlock(subdev, ofs, size); | ||
494 | if (err) | ||
495 | break; | ||
496 | |||
497 | len -= size; | ||
498 | if (len == 0) | ||
499 | break; | ||
500 | |||
501 | err = -EINVAL; | ||
502 | ofs = 0; | ||
503 | } | ||
504 | 482 | ||
505 | return err; | 483 | static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) |
484 | { | ||
485 | return concat_xxlock(mtd, ofs, len, false); | ||
506 | } | 486 | } |
507 | 487 | ||
508 | static void concat_sync(struct mtd_info *mtd) | 488 | static void concat_sync(struct mtd_info *mtd) |