From 41849d49d7d5307d7399314b59fb16d1c39ce0f0 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 21 Nov 2015 12:14:44 +0100 Subject: mtd: nand: r852: Remove unnecessary synchronize_irq() before free_irq() Calling synchronize_irq() right before free_irq() is quite useless. On one hand the IRQ can easily fire again before free_irq() is entered, on the other hand free_irq() itself calls synchronize_irq() internally (in a race condition free way), before any state associated with the IRQ is freed. Patch was generated using the following semantic patch: // @@ expression irq; @@ -synchronize_irq(irq); free_irq(irq, ...); // Signed-off-by: Lars-Peter Clausen Signed-off-by: Brian Norris --- drivers/mtd/nand/r852.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/mtd/nand/r852.c') diff --git a/drivers/mtd/nand/r852.c b/drivers/mtd/nand/r852.c index d8bb2be..be28cdd 100644 --- a/drivers/mtd/nand/r852.c +++ b/drivers/mtd/nand/r852.c @@ -980,7 +980,6 @@ static void r852_remove(struct pci_dev *pci_dev) /* Stop interrupts */ r852_disable_irqs(dev); - synchronize_irq(dev->irq); free_irq(dev->irq, dev); /* Cleanup */ -- cgit v1.1 From 4bd4ebcc540c35d4477b098cf26394f976551464 Mon Sep 17 00:00:00 2001 From: Boris BREZILLON Date: Tue, 1 Dec 2015 12:03:04 +0100 Subject: mtd: nand: make use of mtd_to_nand() in NAND drivers mtd_to_nand() was recently introduced to avoid direct accesses to the mtd->priv field. Update all NAND drivers to use it. Signed-off-by: Boris Brezillon Signed-off-by: Brian Norris --- drivers/mtd/nand/r852.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/mtd/nand/r852.c') diff --git a/drivers/mtd/nand/r852.c b/drivers/mtd/nand/r852.c index be28cdd..ca05b20 100644 --- a/drivers/mtd/nand/r852.c +++ b/drivers/mtd/nand/r852.c @@ -64,7 +64,7 @@ static inline void r852_write_reg_dword(struct r852_device *dev, /* returns pointer to our private structure */ static inline struct r852_device *r852_get_dev(struct mtd_info *mtd) { - struct nand_chip *chip = mtd->priv; + struct nand_chip *chip = mtd_to_nand(mtd); return chip->priv; } -- cgit v1.1 From de9f56f9137b8a6bfaf9b9dcb7d297bf0b61ffbf Mon Sep 17 00:00:00 2001 From: Boris BREZILLON Date: Thu, 10 Dec 2015 09:00:21 +0100 Subject: mtd: nand: r852: use the mtd instance embedded in struct nand_chip struct nand_chip now embeds an mtd device. Make use of this mtd instance. Signed-off-by: Boris Brezillon Signed-off-by: Brian Norris --- drivers/mtd/nand/r852.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'drivers/mtd/nand/r852.c') diff --git a/drivers/mtd/nand/r852.c b/drivers/mtd/nand/r852.c index ca05b20..1ac8ef2 100644 --- a/drivers/mtd/nand/r852.c +++ b/drivers/mtd/nand/r852.c @@ -634,25 +634,22 @@ static void r852_update_media_status(struct r852_device *dev) */ static int r852_register_nand_device(struct r852_device *dev) { - dev->mtd = kzalloc(sizeof(struct mtd_info), GFP_KERNEL); - - if (!dev->mtd) - goto error1; + struct mtd_info *mtd = nand_to_mtd(dev->chip); WARN_ON(dev->card_registred); - dev->mtd->priv = dev->chip; - dev->mtd->dev.parent = &dev->pci_dev->dev; + mtd->priv = dev->chip; + mtd->dev.parent = &dev->pci_dev->dev; if (dev->readonly) dev->chip->options |= NAND_ROM; r852_engine_enable(dev); - if (sm_register_device(dev->mtd, dev->sm)) - goto error2; + if (sm_register_device(mtd, dev->sm)) + goto error1; - if (device_create_file(&dev->mtd->dev, &dev_attr_media_type)) { + if (device_create_file(&mtd->dev, &dev_attr_media_type)) { message("can't create media type sysfs attribute"); goto error3; } @@ -660,9 +657,7 @@ static int r852_register_nand_device(struct r852_device *dev) dev->card_registred = 1; return 0; error3: - nand_release(dev->mtd); -error2: - kfree(dev->mtd); + nand_release(mtd); error1: /* Force card redetect */ dev->card_detected = 0; @@ -675,15 +670,15 @@ error1: static void r852_unregister_nand_device(struct r852_device *dev) { + struct mtd_info *mtd = nand_to_mtd(dev->chip); + if (!dev->card_registred) return; - device_remove_file(&dev->mtd->dev, &dev_attr_media_type); - nand_release(dev->mtd); + device_remove_file(&mtd->dev, &dev_attr_media_type); + nand_release(mtd); r852_engine_disable(dev); dev->card_registred = 0; - kfree(dev->mtd); - dev->mtd = NULL; } /* Card state updater */ @@ -1031,6 +1026,7 @@ static int r852_suspend(struct device *device) static int r852_resume(struct device *device) { struct r852_device *dev = pci_get_drvdata(to_pci_dev(device)); + struct mtd_info *mtd = nand_to_mtd(dev->chip); r852_disable_irqs(dev); r852_card_update_present(dev); @@ -1050,9 +1046,9 @@ static int r852_resume(struct device *device) /* Otherwise, initialize the card */ if (dev->card_registred) { r852_engine_enable(dev); - dev->chip->select_chip(dev->mtd, 0); - dev->chip->cmdfunc(dev->mtd, NAND_CMD_RESET, -1, -1); - dev->chip->select_chip(dev->mtd, -1); + dev->chip->select_chip(mtd, 0); + dev->chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); + dev->chip->select_chip(mtd, -1); } /* Program card detection IRQ */ -- cgit v1.1 From 37f5a54646da0760306ab8570115e20d0ed615f5 Mon Sep 17 00:00:00 2001 From: Boris BREZILLON Date: Thu, 10 Dec 2015 09:00:34 +0100 Subject: mtd: nand: remove useless mtd->priv = chip assignments mtd_to_nand() now uses the container_of() approach to transform an mtd_info pointer into a nand_chip one. Drop useless mtd->priv assignments from NAND controller drivers. Signed-off-by: Boris Brezillon Signed-off-by: Brian Norris --- drivers/mtd/nand/r852.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/mtd/nand/r852.c') diff --git a/drivers/mtd/nand/r852.c b/drivers/mtd/nand/r852.c index 1ac8ef2..cb0bf09 100644 --- a/drivers/mtd/nand/r852.c +++ b/drivers/mtd/nand/r852.c @@ -638,7 +638,6 @@ static int r852_register_nand_device(struct r852_device *dev) WARN_ON(dev->card_registred); - mtd->priv = dev->chip; mtd->dev.parent = &dev->pci_dev->dev; if (dev->readonly) -- cgit v1.1 From 6e9411923b8f4c0e568cbae0f35b7ee4eb989914 Mon Sep 17 00:00:00 2001 From: Boris BREZILLON Date: Wed, 30 Dec 2015 20:32:03 +0100 Subject: mtd: nand: return consistent error codes in ecc.correct() implementations The error code returned by the ecc.correct() are not consistent over the all implementations. Document the expected behavior in include/linux/mtd/nand.h and fix offending implementations. [Brian: this looks like a bugfix for the ECC reporting in the bf5xx_nand driver, but we haven't seen any testing results for it] Signed-off-by: Boris Brezillon Tested-by: Franklin S Cooper Jr. Signed-off-by: Brian Norris --- drivers/mtd/nand/r852.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/mtd/nand/r852.c') diff --git a/drivers/mtd/nand/r852.c b/drivers/mtd/nand/r852.c index cb0bf09..5b15f2f 100644 --- a/drivers/mtd/nand/r852.c +++ b/drivers/mtd/nand/r852.c @@ -477,7 +477,7 @@ static int r852_ecc_correct(struct mtd_info *mtd, uint8_t *dat, if (dev->dma_error) { dev->dma_error = 0; - return -1; + return -EIO; } r852_write_reg(dev, R852_CTL, dev->ctlreg | R852_CTL_ECC_ACCESS); @@ -491,7 +491,7 @@ static int r852_ecc_correct(struct mtd_info *mtd, uint8_t *dat, /* ecc uncorrectable error */ if (ecc_status & R852_ECC_FAIL) { dbg("ecc: unrecoverable error, in half %d", i); - error = -1; + error = -EBADMSG; goto exit; } -- cgit v1.1 From d699ed250c07384840263bbbf69cf7b90b45470c Mon Sep 17 00:00:00 2001 From: Boris BREZILLON Date: Thu, 10 Dec 2015 09:00:41 +0100 Subject: mtd: nand: make use of nand_set/get_controller_data() helpers New helpers have been added to avoid directly accessing chip->field. Use them where appropriate. Signed-off-by: Boris Brezillon [Brian: fixed a few rebase conflicts] Signed-off-by: Brian Norris --- drivers/mtd/nand/r852.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/mtd/nand/r852.c') diff --git a/drivers/mtd/nand/r852.c b/drivers/mtd/nand/r852.c index 5b15f2f..fc9287a 100644 --- a/drivers/mtd/nand/r852.c +++ b/drivers/mtd/nand/r852.c @@ -65,7 +65,7 @@ static inline void r852_write_reg_dword(struct r852_device *dev, static inline struct r852_device *r852_get_dev(struct mtd_info *mtd) { struct nand_chip *chip = mtd_to_nand(mtd); - return chip->priv; + return nand_get_controller_data(chip); } @@ -361,7 +361,7 @@ static void r852_cmdctl(struct mtd_info *mtd, int dat, unsigned int ctrl) */ static int r852_wait(struct mtd_info *mtd, struct nand_chip *chip) { - struct r852_device *dev = chip->priv; + struct r852_device *dev = nand_get_controller_data(chip); unsigned long timeout; int status; @@ -879,7 +879,7 @@ static int r852_probe(struct pci_dev *pci_dev, const struct pci_device_id *id) if (!dev) goto error5; - chip->priv = dev; + nand_set_controller_data(chip, dev); dev->chip = chip; dev->pci_dev = pci_dev; pci_set_drvdata(pci_dev, dev); -- cgit v1.1