@@ -194,6 +194,7 @@ uint8_t tud_msc_get_maxlun_cb(void) {
194194// - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, TEST_UNIT_READY, START_STOP_UNIT, MODE_SENSE6, REQUEST_SENSE
195195// - READ10 and WRITE10 have their own callbacks
196196int32_t tud_msc_scsi_cb (uint8_t lun , const uint8_t scsi_cmd [16 ], void * buffer , uint16_t bufsize ) {
197+ // Note that no command uses a response right now.
197198 const void * response = NULL ;
198199 int32_t resplen = 0 ;
199200
@@ -227,8 +228,10 @@ int32_t tud_msc_scsi_cb(uint8_t lun, const uint8_t scsi_cmd[16], void *buffer, u
227228
228229void tud_msc_capacity_cb (uint8_t lun , uint32_t * block_count , uint16_t * block_size ) {
229230 fs_user_mount_t * vfs = get_vfs (lun );
230- disk_ioctl (vfs , GET_SECTOR_COUNT , block_count );
231- disk_ioctl (vfs , GET_SECTOR_SIZE , block_size );
231+ if (vfs != NULL ) {
232+ disk_ioctl (vfs , GET_SECTOR_COUNT , block_count );
233+ disk_ioctl (vfs , GET_SECTOR_SIZE , block_size );
234+ }
232235}
233236
234237bool tud_msc_is_writable_cb (uint8_t lun ) {
@@ -259,6 +262,9 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void *buff
259262 const uint32_t block_count = bufsize / MSC_FLASH_BLOCK_SIZE ;
260263
261264 fs_user_mount_t * vfs = get_vfs (lun );
265+ if (vfs == NULL ) {
266+ return -1 ;
267+ }
262268 uint32_t disk_block_count ;
263269 disk_ioctl (vfs , GET_SECTOR_COUNT , & disk_block_count );
264270
@@ -281,6 +287,9 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t *
281287 const uint32_t block_count = bufsize / MSC_FLASH_BLOCK_SIZE ;
282288
283289 fs_user_mount_t * vfs = get_vfs (lun );
290+ if (vfs == NULL ) {
291+ return -1 ;
292+ }
284293 disk_write (vfs , buffer , lba , block_count );
285294 // Since by getting here we assume the mount is read-only to
286295 // MicroPython let's update the cached FatFs sector if it's the one
0 commit comments