You've already forked linux-apfs
mirror of
https://github.com/linux-apfs/linux-apfs.git
synced 2026-05-01 15:00:59 -07:00
mtd: remove R/O checking duplication
Many drivers check whether the partition is R/O and return -EROFS if yes. Let's stop having duplicated checks and move them to the API functions instead. And again a bit of noise - deleted few too sparse newlines, sorry. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
This commit is contained in:
committed by
David Woodhouse
parent
5def48982b
commit
664addc248
@@ -122,14 +122,10 @@ static int mapram_erase (struct mtd_info *mtd, struct erase_info *instr)
|
|||||||
unsigned long i;
|
unsigned long i;
|
||||||
|
|
||||||
allff = map_word_ff(map);
|
allff = map_word_ff(map);
|
||||||
|
|
||||||
for (i=0; i<instr->len; i += map_bankwidth(map))
|
for (i=0; i<instr->len; i += map_bankwidth(map))
|
||||||
map_write(map, allff, instr->addr + i);
|
map_write(map, allff, instr->addr + i);
|
||||||
|
|
||||||
instr->state = MTD_ERASE_DONE;
|
instr->state = MTD_ERASE_DONE;
|
||||||
|
|
||||||
mtd_erase_callback(instr);
|
mtd_erase_callback(instr);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,8 +85,7 @@ static void maprom_nop(struct mtd_info *mtd)
|
|||||||
|
|
||||||
static int maprom_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
|
static int maprom_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
|
||||||
{
|
{
|
||||||
printk(KERN_NOTICE "maprom_write called\n");
|
return -EROFS;
|
||||||
return -EIO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int maprom_erase (struct mtd_info *mtd, struct erase_info *info)
|
static int maprom_erase (struct mtd_info *mtd, struct erase_info *info)
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ struct phram_mtd_list {
|
|||||||
|
|
||||||
static LIST_HEAD(phram_list);
|
static LIST_HEAD(phram_list);
|
||||||
|
|
||||||
|
|
||||||
static int phram_erase(struct mtd_info *mtd, struct erase_info *instr)
|
static int phram_erase(struct mtd_info *mtd, struct erase_info *instr)
|
||||||
{
|
{
|
||||||
u_char *start = mtd->priv;
|
u_char *start = mtd->priv;
|
||||||
|
|||||||
+3
-24
@@ -126,9 +126,6 @@ concat_write(struct mtd_info *mtd, loff_t to, size_t len,
|
|||||||
int err = -EINVAL;
|
int err = -EINVAL;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!(mtd->flags & MTD_WRITEABLE))
|
|
||||||
return -EROFS;
|
|
||||||
|
|
||||||
*retlen = 0;
|
*retlen = 0;
|
||||||
|
|
||||||
for (i = 0; i < concat->num_subdev; i++) {
|
for (i = 0; i < concat->num_subdev; i++) {
|
||||||
@@ -145,11 +142,7 @@ concat_write(struct mtd_info *mtd, loff_t to, size_t len,
|
|||||||
else
|
else
|
||||||
size = len;
|
size = len;
|
||||||
|
|
||||||
if (!(subdev->flags & MTD_WRITEABLE))
|
err = mtd_write(subdev, to, size, &retsize, buf);
|
||||||
err = -EROFS;
|
|
||||||
else
|
|
||||||
err = mtd_write(subdev, to, size, &retsize, buf);
|
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -176,9 +169,6 @@ concat_writev(struct mtd_info *mtd, const struct kvec *vecs,
|
|||||||
int i;
|
int i;
|
||||||
int err = -EINVAL;
|
int err = -EINVAL;
|
||||||
|
|
||||||
if (!(mtd->flags & MTD_WRITEABLE))
|
|
||||||
return -EROFS;
|
|
||||||
|
|
||||||
*retlen = 0;
|
*retlen = 0;
|
||||||
|
|
||||||
/* Calculate total length of data */
|
/* Calculate total length of data */
|
||||||
@@ -220,12 +210,8 @@ concat_writev(struct mtd_info *mtd, const struct kvec *vecs,
|
|||||||
old_iov_len = vecs_copy[entry_high].iov_len;
|
old_iov_len = vecs_copy[entry_high].iov_len;
|
||||||
vecs_copy[entry_high].iov_len = size;
|
vecs_copy[entry_high].iov_len = size;
|
||||||
|
|
||||||
if (!(subdev->flags & MTD_WRITEABLE))
|
err = mtd_writev(subdev, &vecs_copy[entry_low],
|
||||||
err = -EROFS;
|
entry_high - entry_low + 1, to, &retsize);
|
||||||
else
|
|
||||||
err = mtd_writev(subdev, &vecs_copy[entry_low],
|
|
||||||
entry_high - entry_low + 1, to,
|
|
||||||
&retsize);
|
|
||||||
|
|
||||||
vecs_copy[entry_high].iov_len = old_iov_len - size;
|
vecs_copy[entry_high].iov_len = old_iov_len - size;
|
||||||
vecs_copy[entry_high].iov_base += size;
|
vecs_copy[entry_high].iov_base += size;
|
||||||
@@ -399,9 +385,6 @@ static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
|
|||||||
uint64_t length, offset = 0;
|
uint64_t length, offset = 0;
|
||||||
struct erase_info *erase;
|
struct erase_info *erase;
|
||||||
|
|
||||||
if (!(mtd->flags & MTD_WRITEABLE))
|
|
||||||
return -EROFS;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for proper erase block alignment of the to-be-erased area.
|
* Check for proper erase block alignment of the to-be-erased area.
|
||||||
* It is easier to do this based on the super device's erase
|
* It is easier to do this based on the super device's erase
|
||||||
@@ -489,10 +472,6 @@ static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
|
|||||||
else
|
else
|
||||||
erase->len = length;
|
erase->len = length;
|
||||||
|
|
||||||
if (!(subdev->flags & MTD_WRITEABLE)) {
|
|
||||||
err = -EROFS;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
length -= erase->len;
|
length -= erase->len;
|
||||||
if ((err = concat_dev_erase(subdev, erase))) {
|
if ((err = concat_dev_erase(subdev, erase))) {
|
||||||
/* sanity check: should never happen since
|
/* sanity check: should never happen since
|
||||||
|
|||||||
+10
-2
@@ -693,6 +693,8 @@ int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
|
|||||||
{
|
{
|
||||||
if (instr->addr > mtd->size || instr->len > mtd->size - instr->addr)
|
if (instr->addr > mtd->size || instr->len > mtd->size - instr->addr)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
if (!(mtd->flags & MTD_WRITEABLE))
|
||||||
|
return -EROFS;
|
||||||
return mtd->_erase(mtd, instr);
|
return mtd->_erase(mtd, instr);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(mtd_erase);
|
EXPORT_SYMBOL_GPL(mtd_erase);
|
||||||
@@ -752,10 +754,10 @@ int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
|
|||||||
const u_char *buf)
|
const u_char *buf)
|
||||||
{
|
{
|
||||||
*retlen = 0;
|
*retlen = 0;
|
||||||
if (!mtd->_write)
|
|
||||||
return -EROFS;
|
|
||||||
if (to < 0 || to > mtd->size || len > mtd->size - to)
|
if (to < 0 || to > mtd->size || len > mtd->size - to)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
if (!mtd->_write || !(mtd->flags & MTD_WRITEABLE))
|
||||||
|
return -EROFS;
|
||||||
return mtd->_write(mtd, to, len, retlen, buf);
|
return mtd->_write(mtd, to, len, retlen, buf);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(mtd_write);
|
EXPORT_SYMBOL_GPL(mtd_write);
|
||||||
@@ -775,6 +777,8 @@ int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
|
|||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
if (to < 0 || to > mtd->size || len > mtd->size - to)
|
if (to < 0 || to > mtd->size || len > mtd->size - to)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
if (!(mtd->flags & MTD_WRITEABLE))
|
||||||
|
return -EROFS;
|
||||||
return mtd->_panic_write(mtd, to, len, retlen, buf);
|
return mtd->_panic_write(mtd, to, len, retlen, buf);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(mtd_panic_write);
|
EXPORT_SYMBOL_GPL(mtd_panic_write);
|
||||||
@@ -826,6 +830,8 @@ int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs)
|
|||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
if (ofs < 0 || ofs > mtd->size)
|
if (ofs < 0 || ofs > mtd->size)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
if (!(mtd->flags & MTD_WRITEABLE))
|
||||||
|
return -EROFS;
|
||||||
return mtd->_block_markbad(mtd, ofs);
|
return mtd->_block_markbad(mtd, ofs);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(mtd_block_markbad);
|
EXPORT_SYMBOL_GPL(mtd_block_markbad);
|
||||||
@@ -877,6 +883,8 @@ int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
|
|||||||
unsigned long count, loff_t to, size_t *retlen)
|
unsigned long count, loff_t to, size_t *retlen)
|
||||||
{
|
{
|
||||||
*retlen = 0;
|
*retlen = 0;
|
||||||
|
if (!(mtd->flags & MTD_WRITEABLE))
|
||||||
|
return -EROFS;
|
||||||
if (!mtd->_writev)
|
if (!mtd->_writev)
|
||||||
return default_mtd_writev(mtd, vecs, count, to, retlen);
|
return default_mtd_writev(mtd, vecs, count, to, retlen);
|
||||||
return mtd->_writev(mtd, vecs, count, to, retlen);
|
return mtd->_writev(mtd, vecs, count, to, retlen);
|
||||||
|
|||||||
+1
-13
@@ -172,8 +172,6 @@ static int part_write(struct mtd_info *mtd, loff_t to, size_t len,
|
|||||||
size_t *retlen, const u_char *buf)
|
size_t *retlen, const u_char *buf)
|
||||||
{
|
{
|
||||||
struct mtd_part *part = PART(mtd);
|
struct mtd_part *part = PART(mtd);
|
||||||
if (!(mtd->flags & MTD_WRITEABLE))
|
|
||||||
return -EROFS;
|
|
||||||
return mtd_write(part->master, to + part->offset, len, retlen, buf);
|
return mtd_write(part->master, to + part->offset, len, retlen, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,8 +179,6 @@ static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
|
|||||||
size_t *retlen, const u_char *buf)
|
size_t *retlen, const u_char *buf)
|
||||||
{
|
{
|
||||||
struct mtd_part *part = PART(mtd);
|
struct mtd_part *part = PART(mtd);
|
||||||
if (!(mtd->flags & MTD_WRITEABLE))
|
|
||||||
return -EROFS;
|
|
||||||
return mtd_panic_write(part->master, to + part->offset, len, retlen,
|
return mtd_panic_write(part->master, to + part->offset, len, retlen,
|
||||||
buf);
|
buf);
|
||||||
}
|
}
|
||||||
@@ -192,9 +188,6 @@ static int part_write_oob(struct mtd_info *mtd, loff_t to,
|
|||||||
{
|
{
|
||||||
struct mtd_part *part = PART(mtd);
|
struct mtd_part *part = PART(mtd);
|
||||||
|
|
||||||
if (!(mtd->flags & MTD_WRITEABLE))
|
|
||||||
return -EROFS;
|
|
||||||
|
|
||||||
if (to >= mtd->size)
|
if (to >= mtd->size)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (ops->datbuf && to + ops->len > mtd->size)
|
if (ops->datbuf && to + ops->len > mtd->size)
|
||||||
@@ -220,8 +213,6 @@ static int part_writev(struct mtd_info *mtd, const struct kvec *vecs,
|
|||||||
unsigned long count, loff_t to, size_t *retlen)
|
unsigned long count, loff_t to, size_t *retlen)
|
||||||
{
|
{
|
||||||
struct mtd_part *part = PART(mtd);
|
struct mtd_part *part = PART(mtd);
|
||||||
if (!(mtd->flags & MTD_WRITEABLE))
|
|
||||||
return -EROFS;
|
|
||||||
return mtd_writev(part->master, vecs, count, to + part->offset,
|
return mtd_writev(part->master, vecs, count, to + part->offset,
|
||||||
retlen);
|
retlen);
|
||||||
}
|
}
|
||||||
@@ -230,8 +221,7 @@ static int part_erase(struct mtd_info *mtd, struct erase_info *instr)
|
|||||||
{
|
{
|
||||||
struct mtd_part *part = PART(mtd);
|
struct mtd_part *part = PART(mtd);
|
||||||
int ret;
|
int ret;
|
||||||
if (!(mtd->flags & MTD_WRITEABLE))
|
|
||||||
return -EROFS;
|
|
||||||
instr->addr += part->offset;
|
instr->addr += part->offset;
|
||||||
ret = mtd_erase(part->master, instr);
|
ret = mtd_erase(part->master, instr);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
@@ -304,8 +294,6 @@ static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)
|
|||||||
struct mtd_part *part = PART(mtd);
|
struct mtd_part *part = PART(mtd);
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
if (!(mtd->flags & MTD_WRITEABLE))
|
|
||||||
return -EROFS;
|
|
||||||
ofs += part->offset;
|
ofs += part->offset;
|
||||||
res = mtd_block_markbad(part->master, ofs);
|
res = mtd_block_markbad(part->master, ofs);
|
||||||
if (!res)
|
if (!res)
|
||||||
|
|||||||
@@ -215,10 +215,6 @@ static int gluebi_write(struct mtd_info *mtd, loff_t to, size_t len,
|
|||||||
struct gluebi_device *gluebi;
|
struct gluebi_device *gluebi;
|
||||||
|
|
||||||
gluebi = container_of(mtd, struct gluebi_device, mtd);
|
gluebi = container_of(mtd, struct gluebi_device, mtd);
|
||||||
|
|
||||||
if (!(mtd->flags & MTD_WRITEABLE))
|
|
||||||
return -EROFS;
|
|
||||||
|
|
||||||
lnum = div_u64_rem(to, mtd->erasesize, &offs);
|
lnum = div_u64_rem(to, mtd->erasesize, &offs);
|
||||||
|
|
||||||
if (len % mtd->writesize || offs % mtd->writesize)
|
if (len % mtd->writesize || offs % mtd->writesize)
|
||||||
@@ -263,12 +259,8 @@ static int gluebi_erase(struct mtd_info *mtd, struct erase_info *instr)
|
|||||||
|
|
||||||
lnum = mtd_div_by_eb(instr->addr, mtd);
|
lnum = mtd_div_by_eb(instr->addr, mtd);
|
||||||
count = mtd_div_by_eb(instr->len, mtd);
|
count = mtd_div_by_eb(instr->len, mtd);
|
||||||
|
|
||||||
gluebi = container_of(mtd, struct gluebi_device, mtd);
|
gluebi = container_of(mtd, struct gluebi_device, mtd);
|
||||||
|
|
||||||
if (!(mtd->flags & MTD_WRITEABLE))
|
|
||||||
return -EROFS;
|
|
||||||
|
|
||||||
for (i = 0; i < count - 1; i++) {
|
for (i = 0; i < count - 1; i++) {
|
||||||
err = ubi_leb_unmap(gluebi->desc, lnum + i);
|
err = ubi_leb_unmap(gluebi->desc, lnum + i);
|
||||||
if (err)
|
if (err)
|
||||||
|
|||||||
@@ -268,6 +268,8 @@ static inline int mtd_write_oob(struct mtd_info *mtd, loff_t to,
|
|||||||
ops->retlen = ops->oobretlen = 0;
|
ops->retlen = ops->oobretlen = 0;
|
||||||
if (!mtd->_write_oob)
|
if (!mtd->_write_oob)
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
if (!(mtd->flags & MTD_WRITEABLE))
|
||||||
|
return -EROFS;
|
||||||
return mtd->_write_oob(mtd, to, ops);
|
return mtd->_write_oob(mtd, to, ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user