Skip to content

Commit

Permalink
libc/mtdoutstream: Fix the in insufficient erase in byte write case
Browse files Browse the repository at this point in the history
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
  • Loading branch information
xiaoxiang781216 authored and anchao committed Nov 4, 2024
1 parent cccc413 commit 11960fd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions libs/libc/stream/lib_mtdoutstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,12 @@ static int mtdoutstream_puts(FAR struct lib_outstream_s *self,
#ifdef CONFIG_MTD_BYTE_WRITE
if (inode->u.i_mtd->write != NULL)
{
if (self->nput % erasesize == 0)
size_t sblock = (self->nput + erasesize - 1) / erasesize;
size_t eblock = (self->nput + len + erasesize - 1) / erasesize;

if (sblock != eblock)
{
ret = MTD_ERASE(inode->u.i_mtd, self->nput / erasesize, 1);
ret = MTD_ERASE(inode->u.i_mtd, sblock, eblock - sblock);
if (ret < 0)
{
return ret;
Expand Down

0 comments on commit 11960fd

Please sign in to comment.