diff --git a/components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c b/components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c index d72b4852fd0..9631bdfa570 100644 --- a/components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c @@ -908,6 +908,9 @@ DRESULT disk_read(BYTE drv, BYTE *buff, DWORD sector, UINT count) rt_size_t result; rt_device_t device = disk[drv]; + if (device == RT_NULL) + return RES_ERROR; + result = rt_device_read(device, sector, buff, count); if (result == count) { @@ -923,6 +926,9 @@ DRESULT disk_write(BYTE drv, const BYTE *buff, DWORD sector, UINT count) rt_size_t result; rt_device_t device = disk[drv]; + if (device == RT_NULL) + return RES_ERROR; + result = rt_device_write(device, sector, buff, count); if (result == count) { diff --git a/components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c b/components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c index 4d4de5e1230..a477851e7e7 100644 --- a/components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c @@ -1146,6 +1146,9 @@ DRESULT disk_read(BYTE drv, BYTE *buff, DWORD sector, UINT count) rt_size_t result; rt_device_t device = disk[drv]; + if (device == RT_NULL) + return RES_ERROR; + result = rt_device_read(device, sector, buff, count); if (result == count) { @@ -1161,6 +1164,9 @@ DRESULT disk_write(BYTE drv, const BYTE *buff, DWORD sector, UINT count) rt_size_t result; rt_device_t device = disk[drv]; + if (device == RT_NULL) + return RES_ERROR; + result = rt_device_write(device, sector, buff, count); if (result == count) {