From 968763aa1d4ee5ed597d6f32b19fef6cbbed5c5c Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 27 Mar 2018 21:28:18 -0500 Subject: [PATCH] factor out storage_object_from_path --- shared-module/storage/__init__.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index 97a049bac6..3e7b90384a 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -109,19 +109,15 @@ void common_hal_storage_umount_object(mp_obj_t vfs_obj) { mp_vfs_proxy_call(vfs, MP_QSTR_umount, 0, NULL); } -void common_hal_storage_umount_path(const char* mount_path) { - // remove vfs from the mount table - mp_obj_t *vfs_obj = NULL; +STATIC mp_obj_t storage_object_from_path(const char* mount_path) { for (mp_vfs_mount_t **vfsp = &MP_STATE_VM(vfs_mount_table); *vfsp != NULL; vfsp = &(*vfsp)->next) { if (strcmp(mount_path, (*vfsp)->str) == 0) { - vfs_obj = (*vfsp)->obj; - break; + return (*vfsp)->obj; } } - - if (vfs_obj == NULL) { - mp_raise_OSError(MP_EINVAL); - } - - common_hal_storage_umount_object(vfs_obj); + mp_raise_OSError(MP_EINVAL); +} + +void common_hal_storage_umount_path(const char* mount_path) { + common_hal_storage_umount_object(storage_object_from_path(mount_path)); }