]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
mtd: Remove mtd_erase_callback() entirely
authorMarek Behún <marek.behun@nic.cz>
Tue, 5 Oct 2021 13:56:06 +0000 (15:56 +0200)
committerJagan Teki <jagan@amarulasolutions.com>
Sat, 23 Oct 2021 10:17:33 +0000 (15:47 +0530)
The original purpose of mtd_erase_callback() in Linux at the time it was
imported to U-Boot, was to inform the caller that erasing is done (since
it was an asynchronous operation).

All supplied callback methods in U-Boot do nothing, but the
mtd_erase_callback() function was (until previous patch) grossly abused
in U-Boot's mtdpart implementation for completely different purpose.

Since we got rid of the abusement, remove the mtd_erase_callback()
function and the .callback member from struct erase_info entirely, in
order to avoid such problems in the future.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
15 files changed:
cmd/onenand.c
drivers/mtd/altera_qspi.c
drivers/mtd/cfi_mtd.c
drivers/mtd/mtdconcat.c
drivers/mtd/mtdcore.c
drivers/mtd/mtdpart.c
drivers/mtd/nand/raw/nand_base.c
drivers/mtd/onenand/onenand_base.c
drivers/mtd/spi/sf_mtd.c
drivers/mtd/spi/spi-nor-core.c
drivers/mtd/ubi/io.c
env/onenand.c
fs/yaffs2/yaffs_mtdif.c
include/linux/mtd/mtd.h
include/nand.h

index 852ed5c7b21ced632c0a62850556ff6d75f1147f..592985a7ee36704b16e350902927d792f64fa0f7 100644 (file)
@@ -186,9 +186,7 @@ next:
 static int onenand_block_erase(u32 start, u32 size, int force)
 {
        struct onenand_chip *this = mtd->priv;
-       struct erase_info instr = {
-               .callback       = NULL,
-       };
+       struct erase_info instr = {};
        loff_t ofs;
        int ret;
        int blocksize = 1 << this->erase_shift;
@@ -219,10 +217,7 @@ static int onenand_block_erase(u32 start, u32 size, int force)
 static int onenand_block_test(u32 start, u32 size)
 {
        struct onenand_chip *this = mtd->priv;
-       struct erase_info instr = {
-               .callback       = NULL,
-               .priv           = 0,
-       };
+       struct erase_info instr = {};
 
        int blocks;
        loff_t ofs;
index 7bac599a54a106880da851d9df6d604679ca9bbd..d31391f36a47161e848c0215c2e96407669903c8 100644 (file)
@@ -153,7 +153,6 @@ static int altera_qspi_erase(struct mtd_info *mtd, struct erase_info *instr)
                                putc('\n');
                        instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN;
                        instr->state = MTD_ERASE_FAILED;
-                       mtd_erase_callback(instr);
                        return -EIO;
                }
                flash = pdata->base + addr;
@@ -177,7 +176,6 @@ static int altera_qspi_erase(struct mtd_info *mtd, struct erase_info *instr)
                                writel(stat, &regs->isr); /* clear isr */
                                instr->fail_addr = addr;
                                instr->state = MTD_ERASE_FAILED;
-                               mtd_erase_callback(instr);
                                return -EIO;
                        }
                        if (flash_verbose)
@@ -189,7 +187,6 @@ static int altera_qspi_erase(struct mtd_info *mtd, struct erase_info *instr)
                addr += mtd->erasesize;
        }
        instr->state = MTD_ERASE_DONE;
-       mtd_erase_callback(instr);
 
        return 0;
 }
index 78293caa2f7ba972d570729182dcfd7929e30727..2295bb7220b433f33e1a82cc99bc7662e3d196d8 100644 (file)
@@ -58,7 +58,6 @@ static int cfi_mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
                }
 
                instr->state = MTD_ERASE_DONE;
-               mtd_erase_callback(instr);
                return 0;
        }
 
index 684bc949985b0f7916eb201333697a9860e23800..af3c4765c4dfb9ab486855db09bcf6e26a25efac 100644 (file)
@@ -338,14 +338,6 @@ concat_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops)
        return -EINVAL;
 }
 
-static void concat_erase_callback(struct erase_info *instr)
-{
-       /* Nothing to do here in U-Boot */
-#ifndef __UBOOT__
-       wake_up((wait_queue_head_t *) instr->priv);
-#endif
-}
-
 static int concat_dev_erase(struct mtd_info *mtd, struct erase_info *erase)
 {
        int err;
@@ -358,7 +350,6 @@ static int concat_dev_erase(struct mtd_info *mtd, struct erase_info *erase)
        init_waitqueue_head(&waitq);
 
        erase->mtd = mtd;
-       erase->callback = concat_erase_callback;
        erase->priv = (unsigned long) &waitq;
 
        /*
@@ -498,8 +489,6 @@ static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
        if (err)
                return err;
 
-       if (instr->callback)
-               instr->callback(instr);
        return 0;
 }
 
index 9496903e861908b9aa437458640008835276e9f2..1d45fb55c7214db5b2c17f73a649fb25f1cb5e38 100644 (file)
@@ -906,13 +906,6 @@ void __put_mtd_device(struct mtd_info *mtd)
 }
 EXPORT_SYMBOL_GPL(__put_mtd_device);
 
-/*
- * Erase is an asynchronous operation.  Device drivers are supposed
- * to call instr->callback() whenever the operation completes, even
- * if it completes with a failure.
- * Callers are supposed to pass a callback function and wait for it
- * to be called before writing to the block.
- */
 int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
 {
        if (instr->addr > mtd->size || instr->len > mtd->size - instr->addr)
@@ -922,7 +915,6 @@ int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
        instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN;
        if (!instr->len) {
                instr->state = MTD_ERASE_DONE;
-               mtd_erase_callback(instr);
                return 0;
        }
        return mtd->_erase(mtd, instr);
index 6ab481a7b1c01a3be2616e7730bb8dc96432753c..a435ce6d079b51bd2d778338eb12da72309e20a7 100644 (file)
@@ -456,27 +456,6 @@ static int part_erase(struct mtd_info *mtd, struct erase_info *instr)
        return ret;
 }
 
-void mtd_erase_callback(struct erase_info *instr)
-{
-       if (!instr->callback)
-               return;
-
-       if (instr->mtd->_erase == part_erase && instr->len) {
-               if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
-                       instr->fail_addr -= instr->mtd->offset;
-               instr->addr -= instr->mtd->offset;
-       }
-
-       instr->callback(instr);
-
-       if (instr->mtd->_erase == part_erase && instr->len) {
-               if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
-                       instr->fail_addr += instr->mtd->offset;
-               instr->addr += instr->mtd->offset;
-       }
-}
-EXPORT_SYMBOL_GPL(mtd_erase_callback);
-
 static int part_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 {
        return mtd->parent->_lock(mtd->parent, ofs + mtd->offset, len);
index b533683dfe6562c69fc6784ade5740060b482b7c..f7616985d95e44e33acc6e6f6b8e744e28b02ee2 100644 (file)
@@ -3602,10 +3602,6 @@ erase_exit:
        chip->select_chip(mtd, -1);
        nand_release_device(mtd);
 
-       /* Do call back function */
-       if (!ret)
-               mtd_erase_callback(instr);
-
        /* Return more or less happy */
        return ret;
 }
index 46aeef258d9877f5bb9d048eb3972c87d2c9b75c..56e1858de45131bfed2f75df41156020f6ca7f4e 100644 (file)
@@ -1836,9 +1836,6 @@ int onenand_erase(struct mtd_info *mtd, struct erase_info *instr)
 erase_exit:
 
        ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO;
-       /* Do call back function */
-       if (!ret)
-               mtd_erase_callback(instr);
 
        /* Deselect and wake up anyone waiting on the device */
        onenand_release_device(mtd);
index 04de8680809c055206b14bb34c736ec5cfde20a0..0aed28a52b78acff7ad31f430285759fd0305bb3 100644 (file)
@@ -46,7 +46,6 @@ static int spi_flash_mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
        }
 
        instr->state = MTD_ERASE_DONE;
-       mtd_erase_callback(instr);
 
        return 0;
 }
index a85759967b00abf59151c6dfc6dd1299085b2cde..4388a08a90de5459cb9e71cc9c08e45583b72453 100644 (file)
@@ -918,7 +918,7 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
        div_u64_rem(instr->len, mtd->erasesize, &rem);
        if (rem) {
                ret = -EINVAL;
-               goto erase_err_callback;
+               goto err;
        }
 
        addr = instr->addr;
@@ -966,14 +966,13 @@ erase_err:
        if (!ret)
                ret = err;
 
-erase_err_callback:
+err:
        if (ret) {
                instr->fail_addr = addr_known ? addr : MTD_FAIL_ADDR_UNKNOWN;
                instr->state = MTD_ERASE_FAILED;
        } else {
                instr->state = MTD_ERASE_DONE;
        }
-       mtd_erase_callback(instr);
 
        return ret;
 }
index b8b878b9182d852cf54f504bb7ad1824d5fbdd8d..14be95b74bc4b1c72d71a702ac43938d6a94e080 100644 (file)
@@ -304,18 +304,6 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
        return err;
 }
 
-/**
- * erase_callback - MTD erasure call-back.
- * @ei: MTD erase information object.
- *
- * Note, even though MTD erase interface is asynchronous, all the current
- * implementations are synchronous anyway.
- */
-static void erase_callback(struct erase_info *ei)
-{
-       wake_up_interruptible((wait_queue_head_t *)ei->priv);
-}
-
 /**
  * do_sync_erase - synchronously erase a physical eraseblock.
  * @ubi: UBI device description object
@@ -346,7 +334,6 @@ retry:
        ei.mtd      = ubi->mtd;
        ei.addr     = (loff_t)pnum * ubi->peb_size;
        ei.len      = ubi->peb_size;
-       ei.callback = erase_callback;
        ei.priv     = (unsigned long)&wq;
 
        err = mtd_erase(ubi->mtd, &ei);
index c8da3ff8114b7cee3261646afc608e3dfdde06b1..1faa2cb62a34ac99d2dd4ca048e5e2083b879d20 100644 (file)
@@ -73,9 +73,7 @@ static int env_onenand_save(void)
 #endif
        loff_t  env_addr = CONFIG_ENV_ADDR;
        size_t  retlen;
-       struct erase_info instr = {
-               .callback       = NULL,
-       };
+       struct erase_info instr = {};
 
        ret = env_export(&env_new);
        if (ret)
index d338f9aa918f30b77c390bd763fc13cec1fe51a9..50fed2d4b150f0db6ab65bc788d3d50782b27e60 100644 (file)
@@ -145,7 +145,6 @@ int nandmtd_EraseBlockInNAND(struct yaffs_dev *dev, int blockNumber)
        ei.len = dev->data_bytes_per_chunk * dev->param.chunks_per_block;
        ei.time = 1000;
        ei.retries = 2;
-       ei.callback = NULL;
        ei.priv = (u_long) dev;
 
        /* Todo finish off the ei if required */
index 3b302fb8c31e202cc8317967edcbac5a61b4e6a2..7455400981503b3d616d0b9f6d83b958f1278403 100644 (file)
@@ -51,7 +51,6 @@ struct erase_info {
        u_long retries;
        unsigned dev;
        unsigned cell;
-       void (*callback) (struct erase_info *self);
        u_long priv;
        u_char state;
        struct erase_info *next;
@@ -535,16 +534,6 @@ extern int unregister_mtd_user (struct mtd_notifier *old);
 #endif
 void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size);
 
-#ifdef CONFIG_MTD_PARTITIONS
-void mtd_erase_callback(struct erase_info *instr);
-#else
-static inline void mtd_erase_callback(struct erase_info *instr)
-{
-       if (instr->callback)
-               instr->callback(instr);
-}
-#endif
-
 static inline int mtd_is_bitflip(int err) {
        return err == -EUCLEAN;
 }
index 75c605193ab140d8943e69a11eef0d9607d23f1a..09dbda4e81b22cf7071dc003cdf3e2e805329443 100644 (file)
@@ -69,7 +69,6 @@ static inline int nand_erase(struct mtd_info *info, loff_t off, size_t size)
        instr.mtd = info;
        instr.addr = off;
        instr.len = size;
-       instr.callback = 0;
 
        return mtd_erase(info, &instr);
 }