diff options
Diffstat (limited to 'firmware/usbstack/usb_storage.c')
-rw-r--r-- | firmware/usbstack/usb_storage.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/firmware/usbstack/usb_storage.c b/firmware/usbstack/usb_storage.c index a439ad4bf0..59ada3bdd8 100644 --- a/firmware/usbstack/usb_storage.c +++ b/firmware/usbstack/usb_storage.c | |||
@@ -74,7 +74,8 @@ | |||
74 | #endif /* CONFIG_CPU == AS3525 */ | 74 | #endif /* CONFIG_CPU == AS3525 */ |
75 | #endif /* USB_READ_BUFFER_SIZE */ | 75 | #endif /* USB_READ_BUFFER_SIZE */ |
76 | 76 | ||
77 | #define MAX_CBW_SIZE 1024 | 77 | /* We don't use sizeof() here, because we *need* a multiple of 32 */ |
78 | #define MAX_CBW_SIZE 32 | ||
78 | 79 | ||
79 | #ifdef USB_WRITE_BUFFER_SIZE | 80 | #ifdef USB_WRITE_BUFFER_SIZE |
80 | #define WRITE_BUFFER_SIZE USB_WRITE_BUFFER_SIZE | 81 | #define WRITE_BUFFER_SIZE USB_WRITE_BUFFER_SIZE |
@@ -453,18 +454,16 @@ void usb_storage_init_connection(void) | |||
453 | ramdisk_buffer = _ramdisk_buffer; | 454 | ramdisk_buffer = _ramdisk_buffer; |
454 | #endif | 455 | #endif |
455 | #else | 456 | #else |
456 | /* TODO : check if bufsize is at least 32K ? */ | ||
457 | size_t bufsize; | ||
458 | unsigned char * buffer; | 457 | unsigned char * buffer; |
459 | /* dummy ops with no callbacks, needed because by | 458 | /* dummy ops with no callbacks, needed because by |
460 | * default buflib buffers can be moved around which must be avoided */ | 459 | * default buflib buffers can be moved around which must be avoided */ |
461 | static struct buflib_callbacks dummy_ops; | 460 | static struct buflib_callbacks dummy_ops; |
462 | 461 | ||
463 | usb_handle = core_alloc_maximum("usb storage", &bufsize, &dummy_ops); | 462 | // Add 31 to handle worst-case misalignment |
463 | usb_handle = core_alloc_ex("usb storage", ALLOCATE_BUFFER_SIZE + MAX_CBW_SIZE + 31, &dummy_ops); | ||
464 | if (usb_handle < 0) | 464 | if (usb_handle < 0) |
465 | panicf("%s(): OOM", __func__); | 465 | panicf("%s(): OOM", __func__); |
466 | if (bufsize < ALLOCATE_BUFFER_SIZE + MAX_CBW_SIZE + 31) | 466 | |
467 | panicf("%s(): got only %d, not enough", __func__, bufsize); | ||
468 | buffer = core_get_data(usb_handle); | 467 | buffer = core_get_data(usb_handle); |
469 | #if defined(UNCACHED_ADDR) && CONFIG_CPU != AS3525 | 468 | #if defined(UNCACHED_ADDR) && CONFIG_CPU != AS3525 |
470 | cbw_buffer = (void *)UNCACHED_ADDR((unsigned int)(buffer+31) & 0xffffffe0); | 469 | cbw_buffer = (void *)UNCACHED_ADDR((unsigned int)(buffer+31) & 0xffffffe0); |