Commit 7e1f0dc0551b99acb5e8fa161a7ac401994d57d8
Committed by
David Woodhouse
1 parent
969e57adc2
Exists in
master
and in
6 other branches
mtd: introduce mtd_erase interface
This patch is part of a patch-set which changes the MTD interface from 'mtd->func()' form to 'mtd_func()' form. We need this because we want to add common code to to all drivers in the mtd core level, which is impossible with the current interface when MTD clients call driver functions like 'read()' or 'write()' directly. At this point we just introduce a new inline wrapper function, but later some of them are expected to gain more code. E.g., the input parameters check should be moved to the wrappers rather than be duplicated at many drivers. This particular patch introduced the 'mtd_erase()' interface. The following patches add all the other interfaces one by one. Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Showing 22 changed files with 37 additions and 28 deletions Side-by-side Diff
- drivers/mtd/ftl.c
- drivers/mtd/inftlmount.c
- drivers/mtd/mtdblock.c
- drivers/mtd/mtdchar.c
- drivers/mtd/mtdconcat.c
- drivers/mtd/mtdoops.c
- drivers/mtd/mtdpart.c
- drivers/mtd/mtdswap.c
- drivers/mtd/nftlmount.c
- drivers/mtd/rfd_ftl.c
- drivers/mtd/sm_ftl.c
- drivers/mtd/tests/mtd_oobtest.c
- drivers/mtd/tests/mtd_pagetest.c
- drivers/mtd/tests/mtd_speedtest.c
- drivers/mtd/tests/mtd_stresstest.c
- drivers/mtd/tests/mtd_subpagetest.c
- drivers/mtd/tests/mtd_torturetest.c
- drivers/mtd/ubi/io.c
- drivers/staging/spectra/lld_mtd.c
- fs/jffs2/erase.c
- fs/logfs/dev_mtd.c
- include/linux/mtd/mtd.h
drivers/mtd/ftl.c
drivers/mtd/inftlmount.c
... | ... | @@ -220,7 +220,7 @@ |
220 | 220 | */ |
221 | 221 | instr->addr = ip->Reserved0 * inftl->EraseSize; |
222 | 222 | instr->len = inftl->EraseSize; |
223 | - mtd->erase(mtd, instr); | |
223 | + mtd_erase(mtd, instr); | |
224 | 224 | } |
225 | 225 | if ((ip->lastUnit - ip->firstUnit + 1) < ip->virtualUnits) { |
226 | 226 | printk(KERN_WARNING "INFTL: Media Header " |
... | ... | @@ -393,7 +393,7 @@ |
393 | 393 | mark only the failed block in the bbt. */ |
394 | 394 | for (physblock = 0; physblock < inftl->EraseSize; |
395 | 395 | physblock += instr->len, instr->addr += instr->len) { |
396 | - mtd->erase(inftl->mbd.mtd, instr); | |
396 | + mtd_erase(inftl->mbd.mtd, instr); | |
397 | 397 | |
398 | 398 | if (instr->state == MTD_ERASE_FAILED) { |
399 | 399 | printk(KERN_WARNING "INFTL: error while formatting block %d\n", |
drivers/mtd/mtdblock.c
drivers/mtd/mtdchar.c
... | ... | @@ -731,7 +731,7 @@ |
731 | 731 | wq_head is no longer there when the |
732 | 732 | callback routine tries to wake us up. |
733 | 733 | */ |
734 | - ret = mtd->erase(mtd, erase); | |
734 | + ret = mtd_erase(mtd, erase); | |
735 | 735 | if (!ret) { |
736 | 736 | set_current_state(TASK_UNINTERRUPTIBLE); |
737 | 737 | add_wait_queue(&waitq, &wait); |
drivers/mtd/mtdconcat.c
... | ... | @@ -379,7 +379,7 @@ |
379 | 379 | * FIXME: Allow INTERRUPTIBLE. Which means |
380 | 380 | * not having the wait_queue head on the stack. |
381 | 381 | */ |
382 | - err = mtd->erase(mtd, erase); | |
382 | + err = mtd_erase(mtd, erase); | |
383 | 383 | if (!err) { |
384 | 384 | set_current_state(TASK_UNINTERRUPTIBLE); |
385 | 385 | add_wait_queue(&waitq, &wait); |
drivers/mtd/mtdoops.c
drivers/mtd/mtdpart.c
... | ... | @@ -257,7 +257,7 @@ |
257 | 257 | if (instr->addr >= mtd->size) |
258 | 258 | return -EINVAL; |
259 | 259 | instr->addr += part->offset; |
260 | - ret = part->master->erase(part->master, instr); | |
260 | + ret = mtd_erase(part->master, instr); | |
261 | 261 | if (ret) { |
262 | 262 | if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN) |
263 | 263 | instr->fail_addr -= part->offset; |
drivers/mtd/mtdswap.c
drivers/mtd/nftlmount.c
... | ... | @@ -326,7 +326,7 @@ |
326 | 326 | instr->mtd = nftl->mbd.mtd; |
327 | 327 | instr->addr = block * nftl->EraseSize; |
328 | 328 | instr->len = nftl->EraseSize; |
329 | - mtd->erase(mtd, instr); | |
329 | + mtd_erase(mtd, instr); | |
330 | 330 | |
331 | 331 | if (instr->state == MTD_ERASE_FAILED) { |
332 | 332 | printk("Error while formatting block %d\n", block); |
drivers/mtd/rfd_ftl.c
... | ... | @@ -342,7 +342,7 @@ |
342 | 342 | part->blocks[block].state = BLOCK_ERASING; |
343 | 343 | part->blocks[block].free_sectors = 0; |
344 | 344 | |
345 | - rc = part->mbd.mtd->erase(part->mbd.mtd, erase); | |
345 | + rc = mtd_erase(part->mbd.mtd, erase); | |
346 | 346 | |
347 | 347 | if (rc) { |
348 | 348 | printk(KERN_ERR PREFIX "erase of region %llx,%llx on '%s' " |
drivers/mtd/sm_ftl.c
drivers/mtd/tests/mtd_oobtest.c
drivers/mtd/tests/mtd_pagetest.c
drivers/mtd/tests/mtd_speedtest.c
... | ... | @@ -79,7 +79,7 @@ |
79 | 79 | ei.addr = addr; |
80 | 80 | ei.len = mtd->erasesize; |
81 | 81 | |
82 | - err = mtd->erase(mtd, &ei); | |
82 | + err = mtd_erase(mtd, &ei); | |
83 | 83 | if (err) { |
84 | 84 | printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum); |
85 | 85 | return err; |
... | ... | @@ -105,7 +105,7 @@ |
105 | 105 | ei.addr = addr; |
106 | 106 | ei.len = mtd->erasesize * blocks; |
107 | 107 | |
108 | - err = mtd->erase(mtd, &ei); | |
108 | + err = mtd_erase(mtd, &ei); | |
109 | 109 | if (err) { |
110 | 110 | printk(PRINT_PREF "error %d while erasing EB %d, blocks %d\n", |
111 | 111 | err, ebnum, blocks); |
drivers/mtd/tests/mtd_stresstest.c
drivers/mtd/tests/mtd_subpagetest.c
drivers/mtd/tests/mtd_torturetest.c
drivers/mtd/ubi/io.c
... | ... | @@ -361,7 +361,7 @@ |
361 | 361 | ei.callback = erase_callback; |
362 | 362 | ei.priv = (unsigned long)&wq; |
363 | 363 | |
364 | - err = ubi->mtd->erase(ubi->mtd, &ei); | |
364 | + err = mtd_erase(ubi->mtd, &ei); | |
365 | 365 | if (err) { |
366 | 366 | if (retries++ < UBI_IO_RETRIES) { |
367 | 367 | dbg_io("error %d while erasing PEB %d, retry", |
drivers/staging/spectra/lld_mtd.c
... | ... | @@ -188,7 +188,7 @@ |
188 | 188 | erase.len = spectra_mtd->erasesize; |
189 | 189 | erase.priv = (unsigned long)∁ |
190 | 190 | |
191 | - ret = spectra_mtd->erase(spectra_mtd, &erase); | |
191 | + ret = mtd_erase(spectra_mtd, &erase); | |
192 | 192 | if (!ret) { |
193 | 193 | wait_for_completion(&comp); |
194 | 194 | if (erase.state != MTD_ERASE_DONE) |
fs/jffs2/erase.c
fs/logfs/dev_mtd.c
include/linux/mtd/mtd.h
... | ... | @@ -171,11 +171,8 @@ |
171 | 171 | struct mtd_erase_region_info *eraseregions; |
172 | 172 | |
173 | 173 | /* |
174 | - * Erase is an asynchronous operation. Device drivers are supposed | |
175 | - * to call instr->callback() whenever the operation completes, even | |
176 | - * if it completes with a failure. | |
177 | - * Callers are supposed to pass a callback function and wait for it | |
178 | - * to be called before writing to the block. | |
174 | + * Do not call via these pointers, use corresponding mtd_*() | |
175 | + * wrappers instead. | |
179 | 176 | */ |
180 | 177 | int (*erase) (struct mtd_info *mtd, struct erase_info *instr); |
181 | 178 | |
... | ... | @@ -273,6 +270,18 @@ |
273 | 270 | int (*get_device) (struct mtd_info *mtd); |
274 | 271 | void (*put_device) (struct mtd_info *mtd); |
275 | 272 | }; |
273 | + | |
274 | +/* | |
275 | + * Erase is an asynchronous operation. Device drivers are supposed | |
276 | + * to call instr->callback() whenever the operation completes, even | |
277 | + * if it completes with a failure. | |
278 | + * Callers are supposed to pass a callback function and wait for it | |
279 | + * to be called before writing to the block. | |
280 | + */ | |
281 | +static inline int mtd_erase(struct mtd_info *mtd, struct erase_info *instr) | |
282 | +{ | |
283 | + return mtd->erase(mtd, instr); | |
284 | +} | |
276 | 285 | |
277 | 286 | static inline struct mtd_info *dev_to_mtd(struct device *dev) |
278 | 287 | { |