aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-02-03 11:13:23 -0500
committerDavid Woodhouse <David.Woodhouse@intel.com>2012-03-26 19:29:11 -0400
commit664addc248d2fed68d013d26ff2fc796d7134259 (patch)
tree197681f173c14068a8d634c9ab1c889fd02316cf
parent5def48982b778aaebe201f85af7170b7d0a6619f (diff)
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>
-rw-r--r--drivers/mtd/chips/map_ram.c4
-rw-r--r--drivers/mtd/chips/map_rom.c3
-rw-r--r--drivers/mtd/devices/phram.c1
-rw-r--r--drivers/mtd/mtdconcat.c27
-rw-r--r--drivers/mtd/mtdcore.c12
-rw-r--r--drivers/mtd/mtdpart.c14
-rw-r--r--drivers/mtd/ubi/gluebi.c8
-rw-r--r--include/linux/mtd/mtd.h2
8 files changed, 17 insertions, 54 deletions
diff --git a/drivers/mtd/chips/map_ram.c b/drivers/mtd/chips/map_ram.c
index 225307088dc0..991c2a1c05d3 100644
--- a/drivers/mtd/chips/map_ram.c
+++ b/drivers/mtd/chips/map_ram.c
@@ -122,14 +122,10 @@ static int mapram_erase (struct mtd_info *mtd, struct erase_info *instr)
122 unsigned long i; 122 unsigned long i;
123 123
124 allff = map_word_ff(map); 124 allff = map_word_ff(map);
125
126 for (i=0; i<instr->len; i += map_bankwidth(map)) 125 for (i=0; i<instr->len; i += map_bankwidth(map))
127 map_write(map, allff, instr->addr + i); 126 map_write(map, allff, instr->addr + i);
128
129 instr->state = MTD_ERASE_DONE; 127 instr->state = MTD_ERASE_DONE;
130
131 mtd_erase_callback(instr); 128 mtd_erase_callback(instr);
132
133 return 0; 129 return 0;
134} 130}
135 131
diff --git a/drivers/mtd/chips/map_rom.c b/drivers/mtd/chips/map_rom.c
index facb56092d39..47a43cf7e5c6 100644
--- a/drivers/mtd/chips/map_rom.c
+++ b/drivers/mtd/chips/map_rom.c
@@ -85,8 +85,7 @@ static void maprom_nop(struct mtd_info *mtd)
85 85
86static int maprom_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf) 86static int maprom_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
87{ 87{
88 printk(KERN_NOTICE "maprom_write called\n"); 88 return -EROFS;
89 return -EIO;
90} 89}
91 90
92static int maprom_erase (struct mtd_info *mtd, struct erase_info *info) 91static int maprom_erase (struct mtd_info *mtd, struct erase_info *info)
diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
index 36add7ce4632..d0e8dc69fe1c 100644
--- a/drivers/mtd/devices/phram.c
+++ b/drivers/mtd/devices/phram.c
@@ -33,7 +33,6 @@ struct phram_mtd_list {
33 33
34static LIST_HEAD(phram_list); 34static LIST_HEAD(phram_list);
35 35
36
37static int phram_erase(struct mtd_info *mtd, struct erase_info *instr) 36static int phram_erase(struct mtd_info *mtd, struct erase_info *instr)
38{ 37{
39 u_char *start = mtd->priv; 38 u_char *start = mtd->priv;
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index 1f2071803931..dd24232265e6 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -126,9 +126,6 @@ concat_write(struct mtd_info *mtd, loff_t to, size_t len,
126 int err = -EINVAL; 126 int err = -EINVAL;
127 int i; 127 int i;
128 128
129 if (!(mtd->flags & MTD_WRITEABLE))
130 return -EROFS;
131
132 *retlen = 0; 129 *retlen = 0;
133 130
134 for (i = 0; i < concat->num_subdev; i++) { 131 for (i = 0; i < concat->num_subdev; i++) {
@@ -145,11 +142,7 @@ concat_write(struct mtd_info *mtd, loff_t to, size_t len,
145 else 142 else
146 size = len; 143 size = len;
147 144
148 if (!(subdev->flags & MTD_WRITEABLE)) 145 err = mtd_write(subdev, to, size, &retsize, buf);
149 err = -EROFS;
150 else
151 err = mtd_write(subdev, to, size, &retsize, buf);
152
153 if (err) 146 if (err)
154 break; 147 break;
155 148
@@ -176,9 +169,6 @@ concat_writev(struct mtd_info *mtd, const struct kvec *vecs,
176 int i; 169 int i;
177 int err = -EINVAL; 170 int err = -EINVAL;
178 171
179 if (!(mtd->flags & MTD_WRITEABLE))
180 return -EROFS;
181
182 *retlen = 0; 172 *retlen = 0;
183 173
184 /* Calculate total length of data */ 174 /* Calculate total length of data */
@@ -220,12 +210,8 @@ concat_writev(struct mtd_info *mtd, const struct kvec *vecs,
220 old_iov_len = vecs_copy[entry_high].iov_len; 210 old_iov_len = vecs_copy[entry_high].iov_len;
221 vecs_copy[entry_high].iov_len = size; 211 vecs_copy[entry_high].iov_len = size;
222 212
223 if (!(subdev->flags & MTD_WRITEABLE)) 213 err = mtd_writev(subdev, &vecs_copy[entry_low],
224 err = -EROFS; 214 entry_high - entry_low + 1, to, &retsize);
225 else
226 err = mtd_writev(subdev, &vecs_copy[entry_low],
227 entry_high - entry_low + 1, to,
228 &retsize);
229 215
230 vecs_copy[entry_high].iov_len = old_iov_len - size; 216 vecs_copy[entry_high].iov_len = old_iov_len - size;
231 vecs_copy[entry_high].iov_base += size; 217 vecs_copy[entry_high].iov_base += size;
@@ -399,9 +385,6 @@ static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
399 uint64_t length, offset = 0; 385 uint64_t length, offset = 0;
400 struct erase_info *erase; 386 struct erase_info *erase;
401 387
402 if (!(mtd->flags & MTD_WRITEABLE))
403 return -EROFS;
404
405 /* 388 /*
406 * Check for proper erase block alignment of the to-be-erased area. 389 * Check for proper erase block alignment of the to-be-erased area.
407 * It is easier to do this based on the super device's erase 390 * 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)
489 else 472 else
490 erase->len = length; 473 erase->len = length;
491 474
492 if (!(subdev->flags & MTD_WRITEABLE)) {
493 err = -EROFS;
494 break;
495 }
496 length -= erase->len; 475 length -= erase->len;
497 if ((err = concat_dev_erase(subdev, erase))) { 476 if ((err = concat_dev_erase(subdev, erase))) {
498 /* sanity check: should never happen since 477 /* sanity check: should never happen since
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 8d5e103695f9..b9b28647adef 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -693,6 +693,8 @@ int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
693{ 693{
694 if (instr->addr > mtd->size || instr->len > mtd->size - instr->addr) 694 if (instr->addr > mtd->size || instr->len > mtd->size - instr->addr)
695 return -EINVAL; 695 return -EINVAL;
696 if (!(mtd->flags & MTD_WRITEABLE))
697 return -EROFS;
696 return mtd->_erase(mtd, instr); 698 return mtd->_erase(mtd, instr);
697} 699}
698EXPORT_SYMBOL_GPL(mtd_erase); 700EXPORT_SYMBOL_GPL(mtd_erase);
@@ -752,10 +754,10 @@ int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
752 const u_char *buf) 754 const u_char *buf)
753{ 755{
754 *retlen = 0; 756 *retlen = 0;
755 if (!mtd->_write)
756 return -EROFS;
757 if (to < 0 || to > mtd->size || len > mtd->size - to) 757 if (to < 0 || to > mtd->size || len > mtd->size - to)
758 return -EINVAL; 758 return -EINVAL;
759 if (!mtd->_write || !(mtd->flags & MTD_WRITEABLE))
760 return -EROFS;
759 return mtd->_write(mtd, to, len, retlen, buf); 761 return mtd->_write(mtd, to, len, retlen, buf);
760} 762}
761EXPORT_SYMBOL_GPL(mtd_write); 763EXPORT_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,
775 return -EOPNOTSUPP; 777 return -EOPNOTSUPP;
776 if (to < 0 || to > mtd->size || len > mtd->size - to) 778 if (to < 0 || to > mtd->size || len > mtd->size - to)
777 return -EINVAL; 779 return -EINVAL;
780 if (!(mtd->flags & MTD_WRITEABLE))
781 return -EROFS;
778 return mtd->_panic_write(mtd, to, len, retlen, buf); 782 return mtd->_panic_write(mtd, to, len, retlen, buf);
779} 783}
780EXPORT_SYMBOL_GPL(mtd_panic_write); 784EXPORT_SYMBOL_GPL(mtd_panic_write);
@@ -826,6 +830,8 @@ int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs)
826 return -EOPNOTSUPP; 830 return -EOPNOTSUPP;
827 if (ofs < 0 || ofs > mtd->size) 831 if (ofs < 0 || ofs > mtd->size)
828 return -EINVAL; 832 return -EINVAL;
833 if (!(mtd->flags & MTD_WRITEABLE))
834 return -EROFS;
829 return mtd->_block_markbad(mtd, ofs); 835 return mtd->_block_markbad(mtd, ofs);
830} 836}
831EXPORT_SYMBOL_GPL(mtd_block_markbad); 837EXPORT_SYMBOL_GPL(mtd_block_markbad);
@@ -877,6 +883,8 @@ int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
877 unsigned long count, loff_t to, size_t *retlen) 883 unsigned long count, loff_t to, size_t *retlen)
878{ 884{
879 *retlen = 0; 885 *retlen = 0;
886 if (!(mtd->flags & MTD_WRITEABLE))
887 return -EROFS;
880 if (!mtd->_writev) 888 if (!mtd->_writev)
881 return default_mtd_writev(mtd, vecs, count, to, retlen); 889 return default_mtd_writev(mtd, vecs, count, to, retlen);
882 return mtd->_writev(mtd, vecs, count, to, retlen); 890 return mtd->_writev(mtd, vecs, count, to, retlen);
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index fbe2c8a22e1c..33d32c6f4f58 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -172,8 +172,6 @@ static int part_write(struct mtd_info *mtd, loff_t to, size_t len,
172 size_t *retlen, const u_char *buf) 172 size_t *retlen, const u_char *buf)
173{ 173{
174 struct mtd_part *part = PART(mtd); 174 struct mtd_part *part = PART(mtd);
175 if (!(mtd->flags & MTD_WRITEABLE))
176 return -EROFS;
177 return mtd_write(part->master, to + part->offset, len, retlen, buf); 175 return mtd_write(part->master, to + part->offset, len, retlen, buf);
178} 176}
179 177
@@ -181,8 +179,6 @@ static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
181 size_t *retlen, const u_char *buf) 179 size_t *retlen, const u_char *buf)
182{ 180{
183 struct mtd_part *part = PART(mtd); 181 struct mtd_part *part = PART(mtd);
184 if (!(mtd->flags & MTD_WRITEABLE))
185 return -EROFS;
186 return mtd_panic_write(part->master, to + part->offset, len, retlen, 182 return mtd_panic_write(part->master, to + part->offset, len, retlen,
187 buf); 183 buf);
188} 184}
@@ -192,9 +188,6 @@ static int part_write_oob(struct mtd_info *mtd, loff_t to,
192{ 188{
193 struct mtd_part *part = PART(mtd); 189 struct mtd_part *part = PART(mtd);
194 190
195 if (!(mtd->flags & MTD_WRITEABLE))
196 return -EROFS;
197
198 if (to >= mtd->size) 191 if (to >= mtd->size)
199 return -EINVAL; 192 return -EINVAL;
200 if (ops->datbuf && to + ops->len > mtd->size) 193 if (ops->datbuf && to + ops->len > mtd->size)
@@ -220,8 +213,6 @@ static int part_writev(struct mtd_info *mtd, const struct kvec *vecs,
220 unsigned long count, loff_t to, size_t *retlen) 213 unsigned long count, loff_t to, size_t *retlen)
221{ 214{
222 struct mtd_part *part = PART(mtd); 215 struct mtd_part *part = PART(mtd);
223 if (!(mtd->flags & MTD_WRITEABLE))
224 return -EROFS;
225 return mtd_writev(part->master, vecs, count, to + part->offset, 216 return mtd_writev(part->master, vecs, count, to + part->offset,
226 retlen); 217 retlen);
227} 218}
@@ -230,8 +221,7 @@ static int part_erase(struct mtd_info *mtd, struct erase_info *instr)
230{ 221{
231 struct mtd_part *part = PART(mtd); 222 struct mtd_part *part = PART(mtd);
232 int ret; 223 int ret;
233 if (!(mtd->flags & MTD_WRITEABLE)) 224
234 return -EROFS;
235 instr->addr += part->offset; 225 instr->addr += part->offset;
236 ret = mtd_erase(part->master, instr); 226 ret = mtd_erase(part->master, instr);
237 if (ret) { 227 if (ret) {
@@ -304,8 +294,6 @@ static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)
304 struct mtd_part *part = PART(mtd); 294 struct mtd_part *part = PART(mtd);
305 int res; 295 int res;
306 296
307 if (!(mtd->flags & MTD_WRITEABLE))
308 return -EROFS;
309 ofs += part->offset; 297 ofs += part->offset;
310 res = mtd_block_markbad(part->master, ofs); 298 res = mtd_block_markbad(part->master, ofs);
311 if (!res) 299 if (!res)
diff --git a/drivers/mtd/ubi/gluebi.c b/drivers/mtd/ubi/gluebi.c
index b875c2c50d82..90b98822d9a4 100644
--- a/drivers/mtd/ubi/gluebi.c
+++ b/drivers/mtd/ubi/gluebi.c
@@ -215,10 +215,6 @@ static int gluebi_write(struct mtd_info *mtd, loff_t to, size_t len,
215 struct gluebi_device *gluebi; 215 struct gluebi_device *gluebi;
216 216
217 gluebi = container_of(mtd, struct gluebi_device, mtd); 217 gluebi = container_of(mtd, struct gluebi_device, mtd);
218
219 if (!(mtd->flags & MTD_WRITEABLE))
220 return -EROFS;
221
222 lnum = div_u64_rem(to, mtd->erasesize, &offs); 218 lnum = div_u64_rem(to, mtd->erasesize, &offs);
223 219
224 if (len % mtd->writesize || offs % mtd->writesize) 220 if (len % mtd->writesize || offs % mtd->writesize)
@@ -263,12 +259,8 @@ static int gluebi_erase(struct mtd_info *mtd, struct erase_info *instr)
263 259
264 lnum = mtd_div_by_eb(instr->addr, mtd); 260 lnum = mtd_div_by_eb(instr->addr, mtd);
265 count = mtd_div_by_eb(instr->len, mtd); 261 count = mtd_div_by_eb(instr->len, mtd);
266
267 gluebi = container_of(mtd, struct gluebi_device, mtd); 262 gluebi = container_of(mtd, struct gluebi_device, mtd);
268 263
269 if (!(mtd->flags & MTD_WRITEABLE))
270 return -EROFS;
271
272 for (i = 0; i < count - 1; i++) { 264 for (i = 0; i < count - 1; i++) {
273 err = ubi_leb_unmap(gluebi->desc, lnum + i); 265 err = ubi_leb_unmap(gluebi->desc, lnum + i);
274 if (err) 266 if (err)
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 317a80c4d54c..fa20a8f0463a 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -268,6 +268,8 @@ static inline int mtd_write_oob(struct mtd_info *mtd, loff_t to,
268 ops->retlen = ops->oobretlen = 0; 268 ops->retlen = ops->oobretlen = 0;
269 if (!mtd->_write_oob) 269 if (!mtd->_write_oob)
270 return -EOPNOTSUPP; 270 return -EOPNOTSUPP;
271 if (!(mtd->flags & MTD_WRITEABLE))
272 return -EROFS;
271 return mtd->_write_oob(mtd, to, ops); 273 return mtd->_write_oob(mtd, to, ops);
272} 274}
273 275