[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEVj2tn8byGn2RHmvYc77rv2BZkApW3yQ5qSDDzNGxhbygO2Ag@mail.gmail.com>
Date: Tue, 20 Sep 2022 18:02:33 -0400
From: Daniel Ogorchock <djogorchock@...il.com>
To: Johnothan King <johnothanking@...tonmail.com>
Cc: "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-input@...r.kernel.org" <linux-input@...r.kernel.org>,
Benjamin Tissoires <benjamin.tissoires@...hat.com>,
Jiri Kosina <jikos@...nel.org>
Subject: Re: [PATCH v2] HID: nintendo: check analog user calibration for plausibility
On Tue, Sep 20, 2022 at 12:54 PM Johnothan King
<johnothanking@...tonmail.com> wrote:
>
> 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: https://github.com/nicman23/dkms-hid-nintendo/pull/25
> Link: https://github.com/DanielOgorchock/linux/issues/36
> Co-authored-by: Arne Wendt <arne.wendt@...h.de>
> Signed-off-by: Johnothan King <johnothanking@...tonmail.com>
> ---
> drivers/hid/hid-nintendo.c | 58 ++++++++++++++++++++++----------------
> 1 file changed, 33 insertions(+), 25 deletions(-)
>
Reviewed-by: Daniel J. Ogorchock <djogorchock@...il.com>
Thanks for the fix. This seems like a good way around invalid calibration data.
-Daniel
Powered by blists - more mailing lists