mtd: fix some unallocated and NULL pointer issues. rwb->wrflush and rwb->wrmaxblocks in rwbuffer could get unallocated values from ftl_initialize() in some configurations. Also fixes related assert:
up_assert: Assertion failed at file:rwbuffer.c line: 643 that can happen with the following configuration: CONFIG_FTL_WRITEBUFFER=y CONFIG_DRVR_WRITEBUFFER=y # CONFIG_FS_WRITABLE is not set These problems are caused by CONFIG variable differences between the buffer layers. TODO: This is not a perfect solution. readahead support has similar issues.
This commit is contained in:
parent
58a0b09b82
commit
0f7210b0ae
@ -29,7 +29,7 @@ config MTD_PARTITION
|
||||
config FTL_WRITEBUFFER
|
||||
bool "Enable write buffering in the FTL layer"
|
||||
default n
|
||||
depends on DRVR_WRITEBUFFER
|
||||
depends on DRVR_WRITEBUFFER && FS_WRITABLE
|
||||
|
||||
config FTL_READAHEAD
|
||||
bool "Enable read-ahead buffering in the FTL layer"
|
||||
|
@ -528,7 +528,7 @@ int ftl_initialize(int minor, FAR struct mtd_dev_s *mtd)
|
||||
|
||||
/* Allocate a FTL device structure */
|
||||
|
||||
dev = (struct ftl_struct_s *)kmm_malloc(sizeof(struct ftl_struct_s));
|
||||
dev = (struct ftl_struct_s *)kmm_zalloc(sizeof(struct ftl_struct_s));
|
||||
if (dev)
|
||||
{
|
||||
/* Initialize the FTL device structure */
|
||||
@ -586,6 +586,9 @@ int ftl_initialize(int minor, FAR struct mtd_dev_s *mtd)
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: rwb_initialize failed: %d\n", ret);
|
||||
#ifdef CONFIG_FS_WRITABLE
|
||||
kmm_free(dev->eblock);
|
||||
#endif
|
||||
kmm_free(dev);
|
||||
return ret;
|
||||
}
|
||||
@ -601,6 +604,9 @@ int ftl_initialize(int minor, FAR struct mtd_dev_s *mtd)
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: register_blockdriver failed: %d\n", -ret);
|
||||
#ifdef CONFIG_FS_WRITABLE
|
||||
kmm_free(dev->eblock);
|
||||
#endif
|
||||
kmm_free(dev);
|
||||
}
|
||||
}
|
||||
|
@ -357,8 +357,12 @@ FAR struct mtd_dev_s *mtd_rwb_initialize(FAR struct mtd_dev_s *mtd)
|
||||
*/
|
||||
|
||||
priv = (FAR struct mtd_rwbuffer_s *)kmm_zalloc(sizeof(struct mtd_rwbuffer_s));
|
||||
if (priv)
|
||||
if (!priv)
|
||||
{
|
||||
ferr("ERROR: Failed to allocate mtd_rwbuffer\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Initialize the allocated structure. (unsupported methods/fields
|
||||
* were already nullified by kmm_zalloc).
|
||||
*/
|
||||
@ -408,7 +412,6 @@ FAR struct mtd_dev_s *mtd_rwb_initialize(FAR struct mtd_dev_s *mtd)
|
||||
kmm_free(priv);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Register the MTD with the procfs system if enabled */
|
||||
|
||||
@ -418,7 +421,6 @@ FAR struct mtd_dev_s *mtd_rwb_initialize(FAR struct mtd_dev_s *mtd)
|
||||
|
||||
/* Return the implementation-specific state structure as the MTD device */
|
||||
|
||||
finfo("Return %p\n", priv);
|
||||
return &priv->mtd;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user