diff options
| author | Christian Walther <cwalther@gmx.ch> | 2020-10-23 22:35:56 +0200 |
|---|---|---|
| committer | Christian Walther <cwalther@gmx.ch> | 2020-11-28 17:54:34 +0100 |
| commit | 7ca36d45a4ffe40c70814d62cb970007b7f40fee (patch) | |
| tree | 3ea89092ebe5a022670e4b53adfaf514d04155c6 | |
| parent | a4b84cf0e118f06cc3b563866d5c594b94b9b3fb (diff) | |
Fix align32_size().
It not only caused crashes with requests larger than 64K (can happen with RGBMatrix), but also generated a lot longer code than necessary.
| -rw-r--r-- | shared-module/usb_midi/__init__.c | 6 | ||||
| -rwxr-xr-x | supervisor/memory.h | 7 |
2 files changed, 5 insertions, 8 deletions
diff --git a/shared-module/usb_midi/__init__.c b/shared-module/usb_midi/__init__.c index 5afdd1821..3fb3f836c 100644 --- a/shared-module/usb_midi/__init__.c +++ b/shared-module/usb_midi/__init__.c @@ -40,9 +40,9 @@ supervisor_allocation* usb_midi_allocation; void usb_midi_init(void) { // TODO(tannewt): Make this dynamic. - uint16_t tuple_size = align32_size(sizeof(mp_obj_tuple_t) + sizeof(mp_obj_t*) * 2); - uint16_t portin_size = align32_size(sizeof(usb_midi_portin_obj_t)); - uint16_t portout_size = align32_size(sizeof(usb_midi_portout_obj_t)); + size_t tuple_size = align32_size(sizeof(mp_obj_tuple_t) + sizeof(mp_obj_t*) * 2); + size_t portin_size = align32_size(sizeof(usb_midi_portin_obj_t)); + size_t portout_size = align32_size(sizeof(usb_midi_portout_obj_t)); // For each embedded MIDI Jack in the descriptor we create a Port usb_midi_allocation = allocate_memory(tuple_size + portin_size + portout_size, false, false); diff --git a/supervisor/memory.h b/supervisor/memory.h index 4307e3f21..0f820eac1 100755 --- a/supervisor/memory.h +++ b/supervisor/memory.h @@ -64,11 +64,8 @@ supervisor_allocation* allocate_remaining_memory(void); // supervisor_move_memory(). supervisor_allocation* allocate_memory(uint32_t length, bool high_address, bool movable); -static inline uint16_t align32_size(uint16_t size) { - if (size % 4 != 0) { - return (size & 0xfffc) + 0x4; - } - return size; +static inline size_t align32_size(size_t size) { + return (size + 3) & ~3; } size_t get_allocation_length(supervisor_allocation* allocation); |
