Skip to content

Commit 5dc9eda

Browse files
committed
extmod/vfs_blockdev: Support bool return from Python read/write blocks.
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]>
1 parent 611d8f9 commit 5dc9eda

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

extmod/vfs_blockdev.c

+7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ static int mp_vfs_blockdev_call_rw(mp_obj_t *args, size_t block_num, size_t bloc
5858
if (ret == mp_const_none) {
5959
return 0;
6060
} else {
61+
// Some block devices return a bool indicating success, so
62+
// convert those to an errno integer code.
63+
if (ret == mp_const_true) {
64+
return 0;
65+
} else if (ret == mp_const_false) {
66+
return -MP_EIO;
67+
}
6168
// Block device functions are expected to return 0 on success
6269
// and negative integer on errors. Check for positive integer
6370
// results as some callers (i.e. littlefs) will produce corrupt

0 commit comments

Comments
 (0)