From 85a7254326c57d36ad27bf4f60dcde9ea026942f Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Sat, 2 May 2020 22:06:38 +0200 Subject: [PATCH] pkg/littlefs: init MTD device before accessing it's parameters The parameters of the MTD device (`sector_count`, `page_size`) are only known after the device has been initialized. Init the device before using it to avoid reading all 0 on e.g. SD cards. --- pkg/littlefs/fs/littlefs_fs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/littlefs/fs/littlefs_fs.c b/pkg/littlefs/fs/littlefs_fs.c index 0d7d61294f..8738aa57ea 100644 --- a/pkg/littlefs/fs/littlefs_fs.c +++ b/pkg/littlefs/fs/littlefs_fs.c @@ -132,6 +132,12 @@ static int prepare(littlefs_desc_t *fs) mutex_init(&fs->lock); mutex_lock(&fs->lock); + int ret = mtd_init(fs->dev); + + if (ret) { + return ret; + } + memset(&fs->fs, 0, sizeof(fs->fs)); if (!fs->config.block_count) { @@ -163,7 +169,7 @@ static int prepare(littlefs_desc_t *fs) fs->config.prog_buffer = fs->prog_buf; #endif - return mtd_init(fs->dev); + return 0; } static int _format(vfs_mount_t *mountp)