From 5a1750b05358705f215e975ae3b5327e68709072 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Fri, 19 Feb 2021 12:45:21 +0000 Subject: [PATCH] storage/stream/flash: flash_sync: Check if there is anything to write The commit moves block that checks if flash_stream_ctx.buf_bytes is non-zero out of CONFIG_STREAM_FLASH_ERASE specific code, as that is universal check and is valid also for not CONFIG_STREAM_FLASH_ERASE code. Signed-off-by: Dominik Ermel --- subsys/storage/stream/stream_flash.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/subsys/storage/stream/stream_flash.c b/subsys/storage/stream/stream_flash.c index 0662b59df61..1e38315fa69 100644 --- a/subsys/storage/stream/stream_flash.c +++ b/subsys/storage/stream/stream_flash.c @@ -56,10 +56,11 @@ static int flash_sync(struct stream_flash_ctx *ctx) size_t write_addr = ctx->offset + ctx->bytes_written; + if (ctx->buf_bytes == 0) { + return 0; + } + if (IS_ENABLED(CONFIG_STREAM_FLASH_ERASE)) { - if (ctx->buf_bytes == 0) { - return 0; - } rc = stream_flash_erase_page(ctx, write_addr + ctx->buf_bytes - 1);