Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp8396385rwn; Wed, 14 Sep 2022 13:50:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR4DPAT5eauJ1O5h20LoVZ/ywXw39d5UJ91aCku7RyZFK7RH666ITy2n2xVObGORnZ9fynCI X-Received: by 2002:a17:906:8a58:b0:770:7b53:f78 with SMTP id gx24-20020a1709068a5800b007707b530f78mr27758718ejc.673.1663188648266; Wed, 14 Sep 2022 13:50:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663188648; cv=none; d=google.com; s=arc-20160816; b=SJp94K/TDzjg420Xc6YtH0ORHTpo+dGTYVaiEe8oWrOmo1q/rWWKApNw2OhjJLMJNX lSSK6pJJqGjxaJ8MFeq3CyfTrujzN+4MEk/GpvFc78/vBjxsJ02Rh5bOdBv5bGhwbCuR z+VVp7dy5y3Gfa4QYO70niz+4ywv1qNaiJcvw5xNYxZslaefQt4OaoFrTS+ukCK0/kiL +/wky6bIYmfnuLAid1dikF3SpFVZBQcbNAJXxb+l5oX7Lmmh97TsYa6wRzNyUiPQ9tTw U80YFH+AeAdJ2zmsj+R+hl97dzY3IkE/dyQw798ifOL8MCH/RtGscYKgOtX4V2snnKer I87Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:in-reply-to:references:from:subject:cc:to:date :dkim-signature; bh=QEPTuJ0CDzklXbRh4DD4or5E2pmxX6owZcybaaXghQU=; b=QSlLiTR29E8POU1N67m5TLa/1IRe6U5E62X5puq3xWxmXQv5H5Nz6V6G+6iuurX66b jBjGSbm2hJQ5B8SfUfLb5n85pf04Pem4OY7XqeSEWi7BT+SroswcX4Ozh5zc6P/KFaPQ KXNvENLz5EH7JeJqjwLH8nuQiWGc9HA9gtGqktRQgd9UI6ZdXPtFeISL/iDAP3+KIE16 nzYgvTzxnmTCtcjpQte6F3g+Lp935HTQfuJHS9nBMEZ+hvDS4accdvDP3xTClXOiGkaJ BKByALZ1RRXl6o/OCyIKhqhMWB2YkIFmIQ0Vc1PYPTctFWwLpoMp64oH1x3IfiaePK2J pqSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kolabnow.com header.s=dkim20160331 header.b="b+JaWMp/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qk43-20020a1709077fab00b0078043d1ea03si1043041ejc.351.2022.09.14.13.50.22; Wed, 14 Sep 2022 13:50:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kolabnow.com header.s=dkim20160331 header.b="b+JaWMp/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229667AbiINTkq (ORCPT + 99 others); Wed, 14 Sep 2022 15:40:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229513AbiINTkn (ORCPT ); Wed, 14 Sep 2022 15:40:43 -0400 X-Greylist: delayed 398 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 14 Sep 2022 12:40:40 PDT Received: from mx.kolabnow.com (mx.kolabnow.com [212.103.80.153]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6B13422CC; Wed, 14 Sep 2022 12:40:40 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mx.kolabnow.com (Postfix) with ESMTP id 53970157E; Wed, 14 Sep 2022 21:34:00 +0200 (CEST) Authentication-Results: ext-mx-out001.mykolab.com (amavisd-new); dkim=pass (4096-bit key) reason="pass (just generated, assumed good)" header.d=kolabnow.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kolabnow.com; h= content-transfer-encoding:content-type:content-type:mime-version :message-id:in-reply-to:references:from:from:subject:subject :date:date:received:received:received; s=dkim20160331; t= 1663184039; x=1664998440; bh=QEPTuJ0CDzklXbRh4DD4or5E2pmxX6owZcy baaXghQU=; b=b+JaWMp/YUOwZehRVD9vbdqwn3/GHYsaY6zjt02zcqQSOM0UfaL vqXDh0WB5VitAV9QqtZRGvmi7ZehdrdgRKG3MoMKEZrw+k+TlgbAJYu8HAeAqbA9 eNLqTtYTbnD3xM8krhbqHImkshL9l2quFuueMMNXkjFHbFTbDUbu3U8kythMmsqG hk78+iGetGDR8WT6vjWv5iqCLwLBFDpGFcnTGH3pnzH3OMbKdGtzRGd3ILZoj/FG ++pxXxaa2kZX6Ofg3UD8IYuTtcZVPA65oZ6wOz5XtFLKDvQQ0QBp4HEWAHmmHGE+ KvEwVtGnLaBCBxMvJ9mCjF4RtwE7IQB2t2ZaR+XKmcTKl9WY2q19vwDzv+Vs2C7n i1W4i+EzI7EUIUHQoTjnaKY2Ag2egSb2EeJVTArBr/byHfNeBCkq6gQ2ZuYQrjwh KF/HL2N6TbEy43Az7OdN1jDO53KanSBEui9NRNgJZ7SGXTbABik7arbC5QBANSSg GZE5uBXO6RPesI62/07LXvIyC4jidwkAxNTNFUUoH204RPJMDdJYZRDv9YLHYTcN yg5UiQrzcNecR/oKYAnNIu4ULkEYObYbQcyR2siLbcs2UP/cMZRYZwXlch8ZMVPG rLHcXpPFKImgRO13FYb9FJaxnue2Gaw79O6DqJJi+ChuKA4w4pMC9To8= X-Virus-Scanned: amavisd-new at mykolab.com X-Spam-Score: -1.899 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Received: from mx.kolabnow.com ([127.0.0.1]) by localhost (ext-mx-out001.mykolab.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kZJsm5l6656i; Wed, 14 Sep 2022 21:33:59 +0200 (CEST) Received: from int-mx003.mykolab.com (unknown [10.9.13.3]) by mx.kolabnow.com (Postfix) with ESMTPS id F3091147B; Wed, 14 Sep 2022 21:33:58 +0200 (CEST) Received: from ext-subm001.mykolab.com (unknown [10.9.6.1]) by int-mx003.mykolab.com (Postfix) with ESMTPS id 8992D2E98; Wed, 14 Sep 2022 21:33:58 +0200 (CEST) Date: Wed, 14 Sep 2022 21:33:56 +0200 To: Johnothan King Cc: "Daniel J. Ogorchock" , Jiri Kosina , Benjamin Tissoires , "linux-input@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] HID: nintendo: check analog user calibration for plausibility From: "Silvan Jegen" References: In-Reply-To: Message-Id: <3DQ9AO4TGVHWM.3BGLGQY972JSD@homearch.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Johnothan King 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 =3D center =3D max =3D 0. >=20 > 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. >=20 > 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 >=20 > Link: https://github.com/nicman23/dkms-hid-nintendo/pull/25 > Link: https://github.com/DanielOgorchock/linux/issues/36 > Co-authored-by: Arne Wendt > Signed-off-by: Johnothan King > --- > drivers/hid/hid-nintendo.c | 24 ++++++++++++++++++++++-- > 1 file changed, 22 insertions(+), 2 deletions(-) Reviewed-by: Silvan Jegen I have actually hit this issue as well ... Cheers, Silvan >=20 > diff --git a/drivers/hid/hid-nintendo.c b/drivers/hid/hid-nintendo.c > index 6028af3c3aae..7f287f6a75f5 100644 > --- a/drivers/hid/hid-nintendo.c > +++ b/drivers/hid/hid-nintendo.c > @@ -793,7 +793,17 @@ static int joycon_request_calibration(struct joycon_= ctlr *ctlr) > &ctlr->left_stick_cal_x, > &ctlr->left_stick_cal_y, > true); > - if (ret) { > + > + /* > + * Check whether read succeeded and perform plausibility check > + * for retrieved values. > + */ > + if (ret || > + ctlr->left_stick_cal_x.min >=3D ctlr->left_stick_cal_x.center || > + ctlr->left_stick_cal_x.center >=3D ctlr->left_stick_cal_x.max || > + ctlr->left_stick_cal_y.min >=3D ctlr->left_stick_cal_y.center || > + ctlr->left_stick_cal_y.center >=3D ctlr->left_stick_cal_y.max > + ) { > hid_warn(ctlr->hdev, > "Failed to read left stick cal, using dflts; e=3D%d\n", > ret); > @@ -812,7 +822,17 @@ static int joycon_request_calibration(struct joycon_= ctlr *ctlr) > &ctlr->right_stick_cal_x, > &ctlr->right_stick_cal_y, > false); > - if (ret) { > + > + /* > + * Check whether read succeeded and perform plausibility check > + * for retrieved values. > + */ > + if (ret || > + ctlr->right_stick_cal_x.min >=3D ctlr->right_stick_cal_x.center || > + ctlr->right_stick_cal_x.center >=3D ctlr->right_stick_cal_x.max || > + ctlr->right_stick_cal_y.min >=3D ctlr->right_stick_cal_y.center || > + ctlr->right_stick_cal_y.center >=3D ctlr->right_stick_cal_y.max > + ) { > hid_warn(ctlr->hdev, > "Failed to read right stick cal, using dflts; e=3D%d\n", > ret);