From e61d51dab3fce109dc31ac88dbbc3701ea23bd6d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 17 Nov 2015 08:39:06 -0600 Subject: [PATCH] If multiple AT24xx devices are supported and resources are allocated, then it may also be necessary to free those resource --- drivers/mtd/at24xx.c | 19 ++++++++++++++++++- include/nuttx/mtd/mtd.h | 13 +++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/at24xx.c b/drivers/mtd/at24xx.c index f928f27d4a..9ce0ee31c8 100644 --- a/drivers/mtd/at24xx.c +++ b/drivers/mtd/at24xx.c @@ -540,7 +540,7 @@ static int at24c_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) * Name: at24c_initialize * * Description: - * Create an initialize MTD device instance. MTD devices are not registered + * Create an initialized MTD device instance. MTD devices are not registered * in the file system, but are created as instances that can be bound to * other functions (such as a block or character driver front end). * @@ -618,4 +618,21 @@ FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev) return (FAR struct mtd_dev_s *)priv; } +/************************************************************************************ + * Name: at24c_uninitialize + * + * Description: + * Release resources held by an allocated MTD device instance. Resources are only + * allocated for the case where multiple AT24xx devices are support. + * + ************************************************************************************/ + +#ifdef CONFIG_AT24XX_MULTI +void at24c_uninitialize(FAR struct mtd_dev_s *mtd) +{ + FAR struct at24c_dev_s *priv = (FAR struct at24c_dev_s *)mtd; + DEBUGASSERT(priv != NULL); + kmm_free(priv); +} +#endif /* CONFIG_AT24XX_MULTI */ #endif /* CONFIG_MTD_AT24XX */ diff --git a/include/nuttx/mtd/mtd.h b/include/nuttx/mtd/mtd.h index 69866d1752..4bd25a612f 100644 --- a/include/nuttx/mtd/mtd.h +++ b/include/nuttx/mtd/mtd.h @@ -390,6 +390,19 @@ FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev, FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev); #endif +/************************************************************************************ + * Name: at24c_uninitialize + * + * Description: + * Release resources held by an allocated MTD device instance. Resources are only + * allocated for the case where multiple AT24xx devices are support. + * + ************************************************************************************/ + +#ifdef CONFIG_AT24XX_MULTI +void at24c_uninitialize(FAR struct mtd_dev_s *mtd); +#endif + /**************************************************************************** * Name: at25_initialize *