From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED764C433E7 for ; Sun, 18 Oct 2020 12:23:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22708207FF for ; Sun, 18 Oct 2020 12:23:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="Gku9EbnA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726618AbgJRMXW (ORCPT ); Sun, 18 Oct 2020 08:23:22 -0400 Received: from mail-40132.protonmail.ch ([185.70.40.132]:14719 "EHLO mail-40132.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726537AbgJRMXW (ORCPT ); Sun, 18 Oct 2020 08:23:22 -0400 X-Greylist: delayed 77103 seconds by postgrey-1.27 at vger.kernel.org; Sun, 18 Oct 2020 08:23:21 EDT Date: Sun, 18 Oct 2020 12:23:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1603023799; bh=Si/sDxp81cibqgSxPPtoAjFrCd8mtAH2nl/znWmdQGY=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=Gku9EbnAj06ght/wpRe3tHwnyij60K657O40Flpnx0uzmEFzcUfhLjSOzX9oU98O5 6mciQLsTfknvbP+z/OLEFb5NKZWE+mAlwTT5wxlHIONPEoyiGlzMvOD1Fpi1uuul4Y riA8tjrkk3oyVp1Rpr66GBnqR4EvzZMX3awKRNm0= To: Coiby Xu From: =?utf-8?Q?Barnab=C3=A1s_P=C5=91cze?= Cc: "linux-input@vger.kernel.org" , Helmut Stult , "stable@vger.kernel.org" , Jiri Kosina , Benjamin Tissoires , "linux-kernel@vger.kernel.org" Reply-To: =?utf-8?Q?Barnab=C3=A1s_P=C5=91cze?= Subject: Re: [PATCH v2] HID: i2c-hid: add polling mode based on connected GPIO chip's pin status Message-ID: In-Reply-To: References: <20201016131335.8121-1-coiby.xu@gmail.com> <20201017004556.kuoxzmbvef4yr3kg@Rk> <20201017140541.fggujaz2klpv3cd5@Rk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org > [...] > > > > > > +static int i2c_hid_polling_thread(void *i2c_hid) > > > > > > +{ > > > > > > > > > > > > - struct i2c_hid *ihid =3D i2c_hid; > > > > > > - struct i2c_client *client =3D ihid->client; > > > > > > - unsigned int polling_interval_idle; > > > > > > - > > > > > > - while (1) { > > > > > > - /* > > > > > > > > > > > > > > > > > > - * re-calculate polling_interval_idle > > > > > > > > > > > > > > > > > > - * so the module parameters polling_interval_idle_ms ca= n be > > > > > > > > > > > > > > > > > > - * changed dynamically through sysfs as polling_interva= l_active_us > > > > > > > > > > > > > > > > > > - */ > > > > > > > > > > > > > > > > > > - polling_interval_idle =3D polling_interval_idle_ms * 10= 00; > > > > > > > > > > > > > > > > > > - if (test_bit(I2C_HID_READ_PENDING, &ihid->flags)) > > > > > > > > > > > > > > > > > > - =09usleep_range(50000, 100000); > > > > > > > > > > > > > > > > > > - > > > > > > - if (kthread_should_stop()) > > > > > > > > > > > > > > > > > > - =09break; > > > > > > > > > > > > > > > > > > - > > > > > > - while (interrupt_line_active(client)) { > > > > > > > > > > > > > > > > > > > > > > I realize it's quite unlikely, but can't this be a endless loop i= f data is coming > > > > > in at a high enough rate? Maybe the maximum number of iterations = could be limited here? > > > > > > > > If we find HID reports are constantly read and send to front-end > > > > application like libinput, won't it help expose the problem of the = I2C > > > > HiD device? > > > > > > > > > > > > > > > I'm not sure I completely understand your point. The reason why I wro= te what I wrote > > > is that this kthread could potentially could go on forever (since `kt= hread_should_stop()` > > > is not checked in the inner while loop) if the data is supplied at a = high enough rate. > > > That's why I said, to avoid this problem, only allow a certain number= of iterations > > > for the inner loop, to guarantee that the kthread can stop in any cas= e. > > > > I mean if "data is supplied at a high enough rate" does happen, this is > > an abnormal case and indicates a bug. So we shouldn't cover it up. We > > expect the user to report it to us. > > > > > > > I agree in principle, but if this abnormal case ever occurs, that'll prev= ent > this module from being unloaded since `kthread_stop()` will hang because = the > thread is "stuck" in the inner loop, never checking `kthread_should_stop(= )`. > That's why I think it makes sense to only allow a certain number of opera= tions > for the inner loop, and maybe show a warning if that's exceeded: > > for (i =3D 0; i < max_iter && interrupt_line_active(...); i++) { > .... > } > > WARN_ON[CE](i =3D=3D max_iter[, "data is coming in at an unreasonably hig= h rate"]); > I now realize that WARN_ON[CE] is probably not the best fit here, `hid_warn= ()` is possibly better. > or something like this, where `max_iter` could possibly be some value dep= endent on > `polling_interval_active_us`, or even just a constant. > [...] Regards, Barnab=C3=A1s P=C5=91cze