Skip to content

Commit 884cfd9

Browse files
author
Boris Brezillon
committed
mtd: Stop assuming mtd_erase() is asynchronous
None of the mtd->_erase() implementations work in an asynchronous manner, so let's simplify MTD users that call mtd_erase(). All they need to do is check the value returned by mtd_erase() and assume that != 0 means failure. Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com> Reviewed-by: Richard Weinberger <richard@nod.at>
1 parent dcba51b commit 884cfd9

19 files changed

Lines changed: 52 additions & 370 deletions

File tree

‎drivers/mtd/devices/bcm47xxsflash.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ static int bcm47xxsflash_erase(struct mtd_info *mtd, struct erase_info *erase)
9595
else
9696
erase->state = MTD_ERASE_DONE;
9797

98-
if (erase->callback)
99-
erase->callback(erase);
100-
10198
return err;
10299
}
103100

‎drivers/mtd/ftl.c‎

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,6 @@ typedef struct partition_t {
140140
#define XFER_PREPARED 0x03
141141
#define XFER_FAILED 0x04
142142

143-
/*====================================================================*/
144-
145-
146-
static void ftl_erase_callback(struct erase_info *done);
147-
148-
149143
/*======================================================================
150144
151145
Scan_header() checks to see if a memory region contains an FTL
@@ -349,17 +343,19 @@ static int erase_xfer(partition_t *part,
349343
return -ENOMEM;
350344

351345
erase->mtd = part->mbd.mtd;
352-
erase->callback = ftl_erase_callback;
353346
erase->addr = xfer->Offset;
354347
erase->len = 1 << part->header.EraseUnitSize;
355-
erase->priv = (u_long)part;
356348

357349
ret = mtd_erase(part->mbd.mtd, erase);
350+
if (!ret) {
351+
xfer->state = XFER_ERASED;
352+
xfer->EraseCount++;
353+
} else {
354+
xfer->state = XFER_FAILED;
355+
pr_notice("ftl_cs: erase failed: err = %d\n", ret);
356+
}
358357

359-
if (!ret)
360-
xfer->EraseCount++;
361-
else
362-
kfree(erase);
358+
kfree(erase);
363359

364360
return ret;
365361
} /* erase_xfer */
@@ -371,37 +367,6 @@ static int erase_xfer(partition_t *part,
371367
372368
======================================================================*/
373369

374-
static void ftl_erase_callback(struct erase_info *erase)
375-
{
376-
partition_t *part;
377-
struct xfer_info_t *xfer;
378-
int i;
379-
380-
/* Look up the transfer unit */
381-
part = (partition_t *)(erase->priv);
382-
383-
for (i = 0; i < part->header.NumTransferUnits; i++)
384-
if (part->XferInfo[i].Offset == erase->addr) break;
385-
386-
if (i == part->header.NumTransferUnits) {
387-
printk(KERN_NOTICE "ftl_cs: internal error: "
388-
"erase lookup failed!\n");
389-
return;
390-
}
391-
392-
xfer = &part->XferInfo[i];
393-
if (erase->state == MTD_ERASE_DONE)
394-
xfer->state = XFER_ERASED;
395-
else {
396-
xfer->state = XFER_FAILED;
397-
printk(KERN_NOTICE "ftl_cs: erase failed: state = %d\n",
398-
erase->state);
399-
}
400-
401-
kfree(erase);
402-
403-
} /* ftl_erase_callback */
404-
405370
static int prepare_xfer(partition_t *part, int i)
406371
{
407372
erase_unit_header_t header;

‎drivers/mtd/inftlmount.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,10 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block)
393393
mark only the failed block in the bbt. */
394394
for (physblock = 0; physblock < inftl->EraseSize;
395395
physblock += instr->len, instr->addr += instr->len) {
396-
mtd_erase(inftl->mbd.mtd, instr);
396+
int ret;
397397

398-
if (instr->state == MTD_ERASE_FAILED) {
398+
ret = mtd_erase(inftl->mbd.mtd, instr);
399+
if (ret) {
399400
printk(KERN_WARNING "INFTL: error while formatting block %d\n",
400401
block);
401402
goto fail;

‎drivers/mtd/mtdblock.c‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,48 +55,28 @@ struct mtdblk_dev {
5555
* being written to until a different sector is required.
5656
*/
5757

58-
static void erase_callback(struct erase_info *done)
59-
{
60-
wait_queue_head_t *wait_q = (wait_queue_head_t *)done->priv;
61-
wake_up(wait_q);
62-
}
63-
6458
static int erase_write (struct mtd_info *mtd, unsigned long pos,
6559
int len, const char *buf)
6660
{
6761
struct erase_info erase;
68-
DECLARE_WAITQUEUE(wait, current);
69-
wait_queue_head_t wait_q;
7062
size_t retlen;
7163
int ret;
7264

7365
/*
7466
* First, let's erase the flash block.
7567
*/
76-
77-
init_waitqueue_head(&wait_q);
7868
erase.mtd = mtd;
79-
erase.callback = erase_callback;
8069
erase.addr = pos;
8170
erase.len = len;
82-
erase.priv = (u_long)&wait_q;
83-
84-
set_current_state(TASK_INTERRUPTIBLE);
85-
add_wait_queue(&wait_q, &wait);
8671

8772
ret = mtd_erase(mtd, &erase);
8873
if (ret) {
89-
set_current_state(TASK_RUNNING);
90-
remove_wait_queue(&wait_q, &wait);
9174
printk (KERN_WARNING "mtdblock: erase of region [0x%lx, 0x%x] "
9275
"on \"%s\" failed\n",
9376
pos, len, mtd->name);
9477
return ret;
9578
}
9679

97-
schedule(); /* Wait for erase to finish. */
98-
remove_wait_queue(&wait_q, &wait);
99-
10080
/*
10181
* Next, write the data to flash.
10282
*/

‎drivers/mtd/mtdchar.c‎

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,6 @@ static ssize_t mtdchar_write(struct file *file, const char __user *buf, size_t c
324324
IOCTL calls for getting device parameters.
325325
326326
======================================================================*/
327-
static void mtdchar_erase_callback (struct erase_info *instr)
328-
{
329-
wake_up((wait_queue_head_t *)instr->priv);
330-
}
331327

332328
static int otp_select_filemode(struct mtd_file_info *mfi, int mode)
333329
{
@@ -709,11 +705,6 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
709705
if (!erase)
710706
ret = -ENOMEM;
711707
else {
712-
wait_queue_head_t waitq;
713-
DECLARE_WAITQUEUE(wait, current);
714-
715-
init_waitqueue_head(&waitq);
716-
717708
if (cmd == MEMERASE64) {
718709
struct erase_info_user64 einfo64;
719710

@@ -736,30 +727,8 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
736727
erase->len = einfo32.length;
737728
}
738729
erase->mtd = mtd;
739-
erase->callback = mtdchar_erase_callback;
740-
erase->priv = (unsigned long)&waitq;
741-
742-
/*
743-
FIXME: Allow INTERRUPTIBLE. Which means
744-
not having the wait_queue head on the stack.
745-
746-
If the wq_head is on the stack, and we
747-
leave because we got interrupted, then the
748-
wq_head is no longer there when the
749-
callback routine tries to wake us up.
750-
*/
730+
751731
ret = mtd_erase(mtd, erase);
752-
if (!ret) {
753-
set_current_state(TASK_UNINTERRUPTIBLE);
754-
add_wait_queue(&waitq, &wait);
755-
if (erase->state != MTD_ERASE_DONE &&
756-
erase->state != MTD_ERASE_FAILED)
757-
schedule();
758-
remove_wait_queue(&waitq, &wait);
759-
set_current_state(TASK_RUNNING);
760-
761-
ret = (erase->state == MTD_ERASE_FAILED)?-EIO:0;
762-
}
763732
kfree(erase);
764733
}
765734
break;

‎drivers/mtd/mtdconcat.c‎

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -333,45 +333,6 @@ concat_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops)
333333
return -EINVAL;
334334
}
335335

336-
static void concat_erase_callback(struct erase_info *instr)
337-
{
338-
wake_up((wait_queue_head_t *) instr->priv);
339-
}
340-
341-
static int concat_dev_erase(struct mtd_info *mtd, struct erase_info *erase)
342-
{
343-
int err;
344-
wait_queue_head_t waitq;
345-
DECLARE_WAITQUEUE(wait, current);
346-
347-
/*
348-
* This code was stol^H^H^H^Hinspired by mtdchar.c
349-
*/
350-
init_waitqueue_head(&waitq);
351-
352-
erase->mtd = mtd;
353-
erase->callback = concat_erase_callback;
354-
erase->priv = (unsigned long) &waitq;
355-
356-
/*
357-
* FIXME: Allow INTERRUPTIBLE. Which means
358-
* not having the wait_queue head on the stack.
359-
*/
360-
err = mtd_erase(mtd, erase);
361-
if (!err) {
362-
set_current_state(TASK_UNINTERRUPTIBLE);
363-
add_wait_queue(&waitq, &wait);
364-
if (erase->state != MTD_ERASE_DONE
365-
&& erase->state != MTD_ERASE_FAILED)
366-
schedule();
367-
remove_wait_queue(&waitq, &wait);
368-
set_current_state(TASK_RUNNING);
369-
370-
err = (erase->state == MTD_ERASE_FAILED) ? -EIO : 0;
371-
}
372-
return err;
373-
}
374-
375336
static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
376337
{
377338
struct mtd_concat *concat = CONCAT(mtd);
@@ -466,7 +427,8 @@ static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
466427
erase->len = length;
467428

468429
length -= erase->len;
469-
if ((err = concat_dev_erase(subdev, erase))) {
430+
erase->mtd = subdev;
431+
if ((err = mtd_erase(subdev, erase))) {
470432
/* sanity check: should never happen since
471433
* block alignment has been checked above */
472434
BUG_ON(err == -EINVAL);
@@ -487,12 +449,8 @@ static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
487449
}
488450
instr->state = erase->state;
489451
kfree(erase);
490-
if (err)
491-
return err;
492452

493-
if (instr->callback)
494-
instr->callback(instr);
495-
return 0;
453+
return err;
496454
}
497455

498456
static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)

‎drivers/mtd/mtdcore.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -945,11 +945,9 @@ void __put_mtd_device(struct mtd_info *mtd)
945945
EXPORT_SYMBOL_GPL(__put_mtd_device);
946946

947947
/*
948-
* Erase is an asynchronous operation. Device drivers are supposed
949-
* to call instr->callback() whenever the operation completes, even
950-
* if it completes with a failure.
951-
* Callers are supposed to pass a callback function and wait for it
952-
* to be called before writing to the block.
948+
* Erase is an synchronous operation. Device drivers are epected to return a
949+
* negative error code if the operation failed and update instr->fail_addr
950+
* to point the portion that was not properly erased.
953951
*/
954952
int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
955953
{

‎drivers/mtd/mtdoops.c‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,47 +84,28 @@ static int page_is_used(struct mtdoops_context *cxt, int page)
8484
return test_bit(page, cxt->oops_page_used);
8585
}
8686

87-
static void mtdoops_erase_callback(struct erase_info *done)
88-
{
89-
wait_queue_head_t *wait_q = (wait_queue_head_t *)done->priv;
90-
wake_up(wait_q);
91-
}
92-
9387
static int mtdoops_erase_block(struct mtdoops_context *cxt, int offset)
9488
{
9589
struct mtd_info *mtd = cxt->mtd;
9690
u32 start_page_offset = mtd_div_by_eb(offset, mtd) * mtd->erasesize;
9791
u32 start_page = start_page_offset / record_size;
9892
u32 erase_pages = mtd->erasesize / record_size;
9993
struct erase_info erase;
100-
DECLARE_WAITQUEUE(wait, current);
101-
wait_queue_head_t wait_q;
10294
int ret;
10395
int page;
10496

105-
init_waitqueue_head(&wait_q);
10697
erase.mtd = mtd;
107-
erase.callback = mtdoops_erase_callback;
10898
erase.addr = offset;
10999
erase.len = mtd->erasesize;
110-
erase.priv = (u_long)&wait_q;
111-
112-
set_current_state(TASK_INTERRUPTIBLE);
113-
add_wait_queue(&wait_q, &wait);
114100

115101
ret = mtd_erase(mtd, &erase);
116102
if (ret) {
117-
set_current_state(TASK_RUNNING);
118-
remove_wait_queue(&wait_q, &wait);
119103
printk(KERN_WARNING "mtdoops: erase of region [0x%llx, 0x%llx] on \"%s\" failed\n",
120104
(unsigned long long)erase.addr,
121105
(unsigned long long)erase.len, mtddev);
122106
return ret;
123107
}
124108

125-
schedule(); /* Wait for erase to finish. */
126-
remove_wait_queue(&wait_q, &wait);
127-
128109
/* Mark pages as unused */
129110
for (page = start_page; page < start_page + erase_pages; page++)
130111
mark_page_unused(cxt, page);

‎drivers/mtd/mtdpart.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,6 @@ void mtd_erase_callback(struct erase_info *instr)
222222
instr->fail_addr -= part->offset;
223223
instr->addr -= part->offset;
224224
}
225-
if (instr->callback)
226-
instr->callback(instr);
227225
}
228226
EXPORT_SYMBOL_GPL(mtd_erase_callback);
229227

0 commit comments

Comments
 (0)