Skip to content

Commit

Permalink
extmod/vfs_blockdev: Support bool return from Python read/write blocks.
Browse files Browse the repository at this point in the history
Commit f4ab9d9 inadvertently broke some
Python block devices, for example esp32 and stm32 SDCard classes.  Those
classes return a bool from their `readblocks` and `writeblocks` methods
instead of an integer errno code.  With that change, both `False` and
`True` return values are now be interpreted as non-zero and hence the block
device call fails.

The fix in this commit is to allow a bool and explicitly convert `True` to
0 and `False` to `-MP_EIO`.

Signed-off-by: Damien George <[email protected]>
  • Loading branch information
dpgeorge authored and iabdalkader committed Nov 19, 2024
1 parent a971731 commit 5adf65b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions extmod/vfs_blockdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ static int mp_vfs_blockdev_call_rw(mp_obj_t *args, size_t block_num, size_t bloc
if (ret == mp_const_none) {
return 0;
} else {
// Some block devices return a bool indicating success, so
// convert those to an errno integer code.
if (ret == mp_const_true) {
return 0;
} else if (ret == mp_const_false) {
return -MP_EIO;
}
// Block device functions are expected to return 0 on success
// and negative integer on errors. Check for positive integer
// results as some callers (i.e. littlefs) will produce corrupt
Expand Down

0 comments on commit 5adf65b

Please sign in to comment.