bch:alloc bch->buffer when offset not aligned
Signed-off-by: guohao15 <guohao15@xiaomi.com>
This commit is contained in:
parent
458bab9ae7
commit
7f16770b91
2 changed files with 16 additions and 16 deletions
|
@ -23,6 +23,7 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
#include <nuttx/kmalloc.h>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
@ -112,7 +113,7 @@ int bchlib_flushsector(FAR struct bchlib_s *bch, bool discard)
|
||||||
* media.
|
* media.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (bch->dirty)
|
if (bch->dirty && bch->buffer != NULL)
|
||||||
{
|
{
|
||||||
inode = bch->inode;
|
inode = bch->inode;
|
||||||
|
|
||||||
|
@ -168,6 +169,20 @@ int bchlib_readsector(FAR struct bchlib_s *bch, size_t sector)
|
||||||
FAR struct inode *inode;
|
FAR struct inode *inode;
|
||||||
ssize_t ret = OK;
|
ssize_t ret = OK;
|
||||||
|
|
||||||
|
if (bch->buffer == NULL)
|
||||||
|
{
|
||||||
|
#if CONFIG_BCH_BUFFER_ALIGNMENT != 0
|
||||||
|
bch->buffer = kmm_memalign(CONFIG_BCH_BUFFER_ALIGNMENT, bch->sectsize);
|
||||||
|
#else
|
||||||
|
bch->buffer = kmm_malloc(bch->sectsize);
|
||||||
|
#endif
|
||||||
|
if (bch->buffer == NULL)
|
||||||
|
{
|
||||||
|
ferr("Failed to allocate sector buffer\n");
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (bch->sector != sector)
|
if (bch->sector != sector)
|
||||||
{
|
{
|
||||||
inode = bch->inode;
|
inode = bch->inode;
|
||||||
|
|
|
@ -110,21 +110,6 @@ int bchlib_setup(const char *blkdev, bool readonly, FAR void **handle)
|
||||||
bch->sectsize = geo.geo_sectorsize;
|
bch->sectsize = geo.geo_sectorsize;
|
||||||
bch->sector = (size_t)-1;
|
bch->sector = (size_t)-1;
|
||||||
bch->readonly = readonly;
|
bch->readonly = readonly;
|
||||||
|
|
||||||
/* Allocate the sector I/O buffer */
|
|
||||||
|
|
||||||
#if CONFIG_BCH_BUFFER_ALIGNMENT != 0
|
|
||||||
bch->buffer = kmm_memalign(CONFIG_BCH_BUFFER_ALIGNMENT, bch->sectsize);
|
|
||||||
#else
|
|
||||||
bch->buffer = kmm_malloc(bch->sectsize);
|
|
||||||
#endif
|
|
||||||
if (!bch->buffer)
|
|
||||||
{
|
|
||||||
ferr("ERROR: Failed to allocate sector buffer\n");
|
|
||||||
ret = -ENOMEM;
|
|
||||||
goto errout_with_bch;
|
|
||||||
}
|
|
||||||
|
|
||||||
*handle = bch;
|
*handle = bch;
|
||||||
return OK;
|
return OK;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue