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>
This commit is contained in:
committed by
Richard Weinberger
parent
df616d7a44
commit
6a08a2f127
@@ -437,7 +437,8 @@ static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
|
|||||||
return err;
|
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);
|
struct mtd_concat *concat = CONCAT(mtd);
|
||||||
int i, err = -EINVAL;
|
int i, err = -EINVAL;
|
||||||
@@ -456,7 +457,10 @@ static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
|
|||||||
else
|
else
|
||||||
size = len;
|
size = len;
|
||||||
|
|
||||||
|
if (is_lock)
|
||||||
err = mtd_lock(subdev, ofs, size);
|
err = mtd_lock(subdev, ofs, size);
|
||||||
|
else
|
||||||
|
err = mtd_unlock(subdev, ofs, size);
|
||||||
if (err)
|
if (err)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -471,38 +475,14 @@ static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
|
||||||
|
{
|
||||||
|
return concat_xxlock(mtd, ofs, len, true);
|
||||||
|
}
|
||||||
|
|
||||||
static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
|
static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
|
||||||
{
|
{
|
||||||
struct mtd_concat *concat = CONCAT(mtd);
|
return concat_xxlock(mtd, ofs, len, false);
|
||||||
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 err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void concat_sync(struct mtd_info *mtd)
|
static void concat_sync(struct mtd_info *mtd)
|
||||||
|
|||||||
Reference in New Issue
Block a user