Skip to content

Commit 5a81f27

Browse files
committed
Don't change number of HID devices until it's vetted
1 parent 20946d9 commit 5a81f27

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

shared-module/usb_hid/__init__.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,13 @@ bool common_hal_usb_hid_enable(const mp_obj_t devices) {
160160
return false;
161161
}
162162

163-
hid_devices_num = MP_OBJ_SMALL_INT_VALUE(mp_obj_len(devices));
164-
if (hid_devices_num > MAX_HID_DEVICES) {
163+
const mp_int_t num_devices = MP_OBJ_SMALL_INT_VALUE(mp_obj_len(devices));
164+
if (num_devices > MAX_HID_DEVICES) {
165165
mp_raise_ValueError_varg(translate("No more than %d HID devices allowed"), MAX_HID_DEVICES);
166166
}
167167

168+
hid_devices_num = num_devices;
169+
168170
// Remember the devices in static storage so they live across VMs.
169171
for (mp_int_t i = 0; i < hid_devices_num; i++) {
170172
// devices has already been validated to contain only usb_hid_device_obj_t objects.

0 commit comments

Comments
 (0)