aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/ubi')
-rw-r--r--drivers/mtd/ubi/gluebi.c29
1 files changed, 5 insertions, 24 deletions
diff --git a/drivers/mtd/ubi/gluebi.c b/drivers/mtd/ubi/gluebi.c
index 941bc3c05d6e..90b98822d9a4 100644
--- a/drivers/mtd/ubi/gluebi.c
+++ b/drivers/mtd/ubi/gluebi.c
@@ -174,11 +174,7 @@ static int gluebi_read(struct mtd_info *mtd, loff_t from, size_t len,
174 int err = 0, lnum, offs, total_read; 174 int err = 0, lnum, offs, total_read;
175 struct gluebi_device *gluebi; 175 struct gluebi_device *gluebi;
176 176
177 if (len < 0 || from < 0 || from + len > mtd->size)
178 return -EINVAL;
179
180 gluebi = container_of(mtd, struct gluebi_device, mtd); 177 gluebi = container_of(mtd, struct gluebi_device, mtd);
181
182 lnum = div_u64_rem(from, mtd->erasesize, &offs); 178 lnum = div_u64_rem(from, mtd->erasesize, &offs);
183 total_read = len; 179 total_read = len;
184 while (total_read) { 180 while (total_read) {
@@ -218,14 +214,7 @@ static int gluebi_write(struct mtd_info *mtd, loff_t to, size_t len,
218 int err = 0, lnum, offs, total_written; 214 int err = 0, lnum, offs, total_written;
219 struct gluebi_device *gluebi; 215 struct gluebi_device *gluebi;
220 216
221 if (len < 0 || to < 0 || len + to > mtd->size)
222 return -EINVAL;
223
224 gluebi = container_of(mtd, struct gluebi_device, mtd); 217 gluebi = container_of(mtd, struct gluebi_device, mtd);
225
226 if (!(mtd->flags & MTD_WRITEABLE))
227 return -EROFS;
228
229 lnum = div_u64_rem(to, mtd->erasesize, &offs); 218 lnum = div_u64_rem(to, mtd->erasesize, &offs);
230 219
231 if (len % mtd->writesize || offs % mtd->writesize) 220 if (len % mtd->writesize || offs % mtd->writesize)
@@ -265,21 +254,13 @@ static int gluebi_erase(struct mtd_info *mtd, struct erase_info *instr)
265 int err, i, lnum, count; 254 int err, i, lnum, count;
266 struct gluebi_device *gluebi; 255 struct gluebi_device *gluebi;
267 256
268 if (instr->addr < 0 || instr->addr > mtd->size - mtd->erasesize)
269 return -EINVAL;
270 if (instr->len < 0 || instr->addr + instr->len > mtd->size)
271 return -EINVAL;
272 if (mtd_mod_by_ws(instr->addr, mtd) || mtd_mod_by_ws(instr->len, mtd)) 257 if (mtd_mod_by_ws(instr->addr, mtd) || mtd_mod_by_ws(instr->len, mtd))
273 return -EINVAL; 258 return -EINVAL;
274 259
275 lnum = mtd_div_by_eb(instr->addr, mtd); 260 lnum = mtd_div_by_eb(instr->addr, mtd);
276 count = mtd_div_by_eb(instr->len, mtd); 261 count = mtd_div_by_eb(instr->len, mtd);
277
278 gluebi = container_of(mtd, struct gluebi_device, mtd); 262 gluebi = container_of(mtd, struct gluebi_device, mtd);
279 263
280 if (!(mtd->flags & MTD_WRITEABLE))
281 return -EROFS;
282
283 for (i = 0; i < count - 1; i++) { 264 for (i = 0; i < count - 1; i++) {
284 err = ubi_leb_unmap(gluebi->desc, lnum + i); 265 err = ubi_leb_unmap(gluebi->desc, lnum + i);
285 if (err) 266 if (err)
@@ -340,11 +321,11 @@ static int gluebi_create(struct ubi_device_info *di,
340 mtd->owner = THIS_MODULE; 321 mtd->owner = THIS_MODULE;
341 mtd->writesize = di->min_io_size; 322 mtd->writesize = di->min_io_size;
342 mtd->erasesize = vi->usable_leb_size; 323 mtd->erasesize = vi->usable_leb_size;
343 mtd->read = gluebi_read; 324 mtd->_read = gluebi_read;
344 mtd->write = gluebi_write; 325 mtd->_write = gluebi_write;
345 mtd->erase = gluebi_erase; 326 mtd->_erase = gluebi_erase;
346 mtd->get_device = gluebi_get_device; 327 mtd->_get_device = gluebi_get_device;
347 mtd->put_device = gluebi_put_device; 328 mtd->_put_device = gluebi_put_device;
348 329
349 /* 330 /*
350 * In case of dynamic a volume, MTD device size is just volume size. In 331 * In case of dynamic a volume, MTD device size is just volume size. In