summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrank Gevaerts <frank@gevaerts.be>2014-01-04 23:35:00 +0100
committerFrank Gevaerts <frank@gevaerts.be>2014-01-11 19:22:49 +0100
commit656261bde1122612d1bf8ffc3c992c75a7fbc52e (patch)
tree1e7ec70918e6768ab9b05d30d130fe8a2ba4d15d
parent26b317e094a37c43d23e661cf99fe858c159f1b2 (diff)
downloadrockbox-656261b.tar.gz
rockbox-656261b.tar.bz2
rockbox-656261b.zip
Don't use core_alloc_maximum() in usb_storage.
usb_storage needs a fairly reasonable amount of memory. Allocating what we need and no more allows other (future) USB drivers to get something too, and is much cleaner in general. Change-Id: Iec9573c0f251f02400f92d92727cbf2969785de0
-rw-r--r--firmware/usbstack/usb_storage.c11
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 @@
#endif /* CONFIG_CPU == AS3525 */
#endif /* USB_READ_BUFFER_SIZE */
-#define MAX_CBW_SIZE 1024
+/* We don't use sizeof() here, because we *need* a multiple of 32 */
+#define MAX_CBW_SIZE 32
#ifdef USB_WRITE_BUFFER_SIZE
#define WRITE_BUFFER_SIZE USB_WRITE_BUFFER_SIZE
@@ -453,18 +454,16 @@ void usb_storage_init_connection(void)
ramdisk_buffer = _ramdisk_buffer;
#endif
#else
- /* TODO : check if bufsize is at least 32K ? */
- size_t bufsize;
unsigned char * buffer;
/* dummy ops with no callbacks, needed because by
* default buflib buffers can be moved around which must be avoided */
static struct buflib_callbacks dummy_ops;
- usb_handle = core_alloc_maximum("usb storage", &bufsize, &dummy_ops);
+ // Add 31 to handle worst-case misalignment
+ usb_handle = core_alloc_ex("usb storage", ALLOCATE_BUFFER_SIZE + MAX_CBW_SIZE + 31, &dummy_ops);
if (usb_handle < 0)
panicf("%s(): OOM", __func__);
- if (bufsize < ALLOCATE_BUFFER_SIZE + MAX_CBW_SIZE + 31)
- panicf("%s(): got only %d, not enough", __func__, bufsize);
+
buffer = core_get_data(usb_handle);
#if defined(UNCACHED_ADDR) && CONFIG_CPU != AS3525
cbw_buffer = (void *)UNCACHED_ADDR((unsigned int)(buffer+31) & 0xffffffe0);