Commit 664addc248d2fed68d013d26ff2fc796d7134259

Authored by Artem Bityutskiy
Committed by David Woodhouse
1 parent 5def48982b

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>

Showing 8 changed files with 17 additions and 54 deletions Side-by-side Diff

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