Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HID: nintendo: check analog user calibration for plausibility
Arne Wendt writes: Cheap clone controllers may (falsely) report as having a user calibration for the analog sticks in place, but return wrong/impossible values for the actual calibration data. In the present case at mine, the controller reports having a user calibration in place and successfully executes the read commands. The reported user calibration however is min = center = max = 0. This pull request addresses problems of this kind by checking the provided user calibration-data for plausibility (min < center < max) and falling back to the default values if implausible. I'll note that I was experiencing a crash because of this bug when using the GuliKit KingKong 2 controller. The crash manifests as a divide by zero error in the kernel logs: kernel: divide error: 0000 [#1] PREEMPT SMP NOPTI Changes in v2: - Move the plausibility check to joycon_read_stick_calibration() and have that function return -EINVAL if the check fails. - In the plausibility check, change >= to ==. hid_field_extract() never returns a negative value, so a scenario involving min > center or center > max is impossible. - To reduce code duplication, move the code for setting default calibration values into a single function called joycon_use_default_calibration(). Link: nicman23/dkms-hid-nintendo#25 Link: DanielOgorchock/linux#36 Co-authored-by: Arne Wendt <[email protected]> Signed-off-by: Johnothan King <[email protected]>
- Loading branch information