Skip to content

Commit

Permalink
mtd: nand: Provide nand_cleanup() function to free NAND related resou…
Browse files Browse the repository at this point in the history
…rces

Provide a nand_cleanup() function to free all nand related resources
without unregistering the mtd device.
This should allow drivers to call mtd_device_unregister() and handle
its return value and still being able to cleanup all nand related
resources.

Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Daniel Walter <dwalter@sigma-star.at>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
  • Loading branch information
Richard Weinberger authored and Boris Brezillon committed Sep 23, 2016
1 parent a984319 commit d44154f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
22 changes: 15 additions & 7 deletions drivers/mtd/nand/nand_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -4799,19 +4799,15 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
EXPORT_SYMBOL(nand_scan);

/**
* nand_release - [NAND Interface] Free resources held by the NAND device
* @mtd: MTD device structure
* nand_cleanup - [NAND Interface] Free resources held by the NAND device
* @chip: NAND chip object
*/
void nand_release(struct mtd_info *mtd)
void nand_cleanup(struct nand_chip *chip)
{
struct nand_chip *chip = mtd_to_nand(mtd);

if (chip->ecc.mode == NAND_ECC_SOFT &&
chip->ecc.algo == NAND_ECC_BCH)
nand_bch_free((struct nand_bch_control *)chip->ecc.priv);

mtd_device_unregister(mtd);

nand_release_data_interface(chip);

/* Free bad block table memory */
Expand All @@ -4824,6 +4820,18 @@ void nand_release(struct mtd_info *mtd)
& NAND_BBT_DYNAMICSTRUCT)
kfree(chip->badblock_pattern);
}
EXPORT_SYMBOL_GPL(nand_cleanup);

/**
* nand_release - [NAND Interface] Unregister the MTD device and free resources
* held by the NAND device
* @mtd: MTD device structure
*/
void nand_release(struct mtd_info *mtd)
{
mtd_device_unregister(mtd);
nand_cleanup(mtd_to_nand(mtd));
}
EXPORT_SYMBOL_GPL(nand_release);

MODULE_LICENSE("GPL");
Expand Down
5 changes: 4 additions & 1 deletion include/linux/mtd/nand.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int nand_scan_ident(struct mtd_info *mtd, int max_chips,
struct nand_flash_dev *table);
int nand_scan_tail(struct mtd_info *mtd);

/* Free resources held by the NAND device */
/* Unregister the MTD device and free resources held by the NAND device */
void nand_release(struct mtd_info *mtd);

/* Internal helper for board drivers which need to override command function */
Expand Down Expand Up @@ -1186,4 +1186,7 @@ int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
/* Reset and initialize a NAND device */
int nand_reset(struct nand_chip *chip);

/* Free resources held by the NAND device */
void nand_cleanup(struct nand_chip *chip);

#endif /* __LINUX_MTD_NAND_H */

0 comments on commit d44154f

Please sign in to comment.