extmod/vfs: Skip littlefs detection if mp_vfs_blockdev_read_ext() fails.#19306
extmod/vfs: Skip littlefs detection if mp_vfs_blockdev_read_ext() fails.#19306projectgus wants to merge 1 commit into
Conversation
|
Code size report: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #19306 +/- ##
=======================================
Coverage 98.47% 98.48%
=======================================
Files 176 176
Lines 22845 22846 +1
=======================================
+ Hits 22497 22499 +2
+ Misses 348 347 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
This looks very reasonable to me, to check the return value (regardless of anything else, that seems like the right thing to do).
I very much doubt there's such a driver that this change would break. So I think it's OK. But I do see that code coverage is failing. Is there a way to test this change? Maybe try to auto-mount a block device that fails on all reads? |
a9d7a75 to
4caffe3
Compare
Otherwise 'buf' is read uninitialised. Extends vfs_blockdev_invalid test to include the mount auto-detection path. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
4caffe3 to
86f68f5
Compare
|
Updated an existing vfs invalid block device to also cover mount failures, looks like this code path is now covered. |
| return MP_OBJ_TYPE_GET_SLOT(&mp_fat_vfs_type, make_new)(&mp_fat_vfs_type, 1, 0, &bdev_obj); | ||
| #endif | ||
|
|
||
| // no filesystem found | ||
| mp_raise_OSError(MP_ENODEV); |
There was a problem hiding this comment.
Something unexpected I noticed is that if FAT support is enabled, this code path will return EIO. If FAT support is not enabled, it will return ENODEV from a few lines down (and the new test would fail).
It's not a particularly big inconsistency so probably we can ignore it, but mentioning as it'd also be easy to change this function so it returns ENODEV for both filesystems or so it records the block read error code and returns that in the LFS2 case as well.
Summary
I noticed in passing that
bufcan be read uninitialised while checking for littlefs, ifmp_vfs_blockdev_read_extfails.Rather than initialise
buf(expensive), have opted to check the return value of the read function.This work was funded through GitHub Sponsors.
Testing
Trade-offs and Alternatives
littlefs2ending up on the stack independently of the internal flash is additionally low (and the first match will return, so a stale copy should never end up being checked on the second iteration.)buf, but as mentioned above, this is more expensive than checking the return value.mp_vfs_blockdev_read_extand returns the result to littlefs2 it seems like such a port block driver would already not work with littlefs.Generative AI
I did not use generative AI tools when creating this PR.