Skip to content

Commit 782e25c

Browse files
committed
shared/supervisor/usb_msc_flash.c: check for valid vfs from get_vfs()
1 parent e3c5548 commit 782e25c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

supervisor/shared/usb/usb_msc_flash.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
196196
int32_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

228229
void 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

234237
bool 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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy