From a4957be25b7ed668181ef755ef8d38bcc6b77fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20=C3=98ye=20Amundsen?= Date: Thu, 28 May 2020 09:23:51 +0200 Subject: [PATCH] storage/stream: allow NULL data pointer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is done to support the idiomatic way of performing flush operations, where the caller might not have access to the proper data pointer. Also, there is no reason why reading from address 0 should not be allowed. Signed-off-by: Håkon Øye Amundsen --- subsys/storage/stream/stream_flash.c | 2 +- tests/subsys/storage/stream/stream_flash/src/main.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/subsys/storage/stream/stream_flash.c b/subsys/storage/stream/stream_flash.c index 0e7bd2ea776..49f99391229 100644 --- a/subsys/storage/stream/stream_flash.c +++ b/subsys/storage/stream/stream_flash.c @@ -115,7 +115,7 @@ int stream_flash_buffered_write(struct stream_flash_ctx *ctx, const uint8_t *dat size_t fill_length; uint8_t filler; - if (!ctx || !data) { + if (!ctx) { return -EFAULT; } diff --git a/tests/subsys/storage/stream/stream_flash/src/main.c b/tests/subsys/storage/stream/stream_flash/src/main.c index b0cb842fffd..043affef1ee 100644 --- a/tests/subsys/storage/stream/stream_flash/src/main.c +++ b/tests/subsys/storage/stream/stream_flash/src/main.c @@ -306,6 +306,17 @@ static void test_stream_flash_buffered_write_callback(void) zassert_equal(rc, -EFAULT, "expected failure from callback"); } +static void test_stream_flash_flush(void) +{ + int rc; + + init_target(); + + /* Perform flush with NULL data pointer and 0 lentgth */ + rc = stream_flash_buffered_write(&ctx, NULL, 0, true); + zassert_equal(rc, 0, "expected success"); +} + #ifdef CONFIG_STREAM_FLASH_ERASE static void test_stream_flash_buffered_write_whole_page(void) { @@ -381,6 +392,7 @@ void test_main(void) ztest_unit_test(test_stream_flash_buffered_write_multi_page), ztest_unit_test(test_stream_flash_buf_size_greater_than_page_size), ztest_unit_test(test_stream_flash_buffered_write_callback), + ztest_unit_test(test_stream_flash_flush), ztest_unit_test(test_stream_flash_buffered_write_whole_page), ztest_unit_test(test_stream_flash_erase_page), ztest_unit_test(test_stream_flash_bytes_written)