Skip to content

Commit 7190b3e

Browse files
authored
Merge pull request #4798 from dhalbert/hid_devices-gc
gc all pointers in hid_devices properly
2 parents d79d687 + 0f66832 commit 7190b3e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

shared-module/usb_hid/__init__.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,14 @@ void usb_hid_save_report_descriptor(uint8_t *report_descriptor_space, size_t rep
259259
void usb_hid_gc_collect(void) {
260260
gc_collect_ptr(hid_devices_tuple);
261261

262-
// Mark any heap pointers in the static device list as in use.
262+
// Mark possible heap pointers in the static device list as in use.
263263
for (mp_int_t i = 0; i < num_hid_devices; i++) {
264-
gc_collect_ptr(&hid_devices[i]);
264+
// Cast away the const for .report_descriptor. It could be in flash or on the heap.
265+
// Constant report descriptors must be const so that they are used directly from flash
266+
// and not copied into RAM.
267+
gc_collect_ptr((void *)hid_devices[i].report_descriptor);
268+
gc_collect_ptr(hid_devices[i].in_report_buffer);
269+
gc_collect_ptr(hid_devices[i].out_report_buffer);
265270
}
266271
}
267272

0 commit comments

Comments
 (0)