Skip to content

Commit 7ca36d4

Browse files
committed
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.
1 parent a4b84cf commit 7ca36d4

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

shared-module/usb_midi/__init__.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ supervisor_allocation* usb_midi_allocation;
4040

4141
void usb_midi_init(void) {
4242
// TODO(tannewt): Make this dynamic.
43-
uint16_t tuple_size = align32_size(sizeof(mp_obj_tuple_t) + sizeof(mp_obj_t*) * 2);
44-
uint16_t portin_size = align32_size(sizeof(usb_midi_portin_obj_t));
45-
uint16_t portout_size = align32_size(sizeof(usb_midi_portout_obj_t));
43+
size_t tuple_size = align32_size(sizeof(mp_obj_tuple_t) + sizeof(mp_obj_t*) * 2);
44+
size_t portin_size = align32_size(sizeof(usb_midi_portin_obj_t));
45+
size_t portout_size = align32_size(sizeof(usb_midi_portout_obj_t));
4646

4747
// For each embedded MIDI Jack in the descriptor we create a Port
4848
usb_midi_allocation = allocate_memory(tuple_size + portin_size + portout_size, false, false);

supervisor/memory.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,8 @@ supervisor_allocation* allocate_remaining_memory(void);
6464
// supervisor_move_memory().
6565
supervisor_allocation* allocate_memory(uint32_t length, bool high_address, bool movable);
6666

67-
static inline uint16_t align32_size(uint16_t size) {
68-
if (size % 4 != 0) {
69-
return (size & 0xfffc) + 0x4;
70-
}
71-
return size;
67+
static inline size_t align32_size(size_t size) {
68+
return (size + 3) & ~3;
7269
}
7370

7471
size_t get_allocation_length(supervisor_allocation* allocation);

0 commit comments

Comments
 (0)