Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp2516226pxu; Sun, 18 Oct 2020 05:33:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqQFu1UaDUm00YcwrTjZk8lIpyb6UPQgngYGb3+nUyrGx74CA3yp64NDyeyM6FOIIf6CDt X-Received: by 2002:a17:907:1010:: with SMTP id ox16mr12960481ejb.379.1603024426296; Sun, 18 Oct 2020 05:33:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603024426; cv=none; d=google.com; s=arc-20160816; b=ZoP1Uqz7WTtxMhF93jrAcdb5Liw0Baj5W/UL63XmbzYjZDXwBps65fLRZyYeQcYyPU xEZFRSEBFg0B3PMVSAMBAvbDXrrYKMDNdwOCG4D7ZLGJwa0/H0bdsE99vXMpUmNl67wE 5yAFpdjoi5eFUi5LNR/y9caL8rGTVSsUDHwL89MswmU0oCeCtlnFDBwmQdE4akdsG+ky iPVVW7vwxQwc3bAjPMuQw7d5oqbQI1ueEOMhpodbOwru4Syhho2zDkqGIAU/okGaIfig gtzt7uBLPAJBg6+e7PBCuTsjDDLzFMnaKagEAjOf8WVZUsP0OMS+LdKSj3JpbQ2ua7+x GEoA== 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 :references:in-reply-to:message-id:subject:reply-to:cc:from:to :dkim-signature:date; bh=Si/sDxp81cibqgSxPPtoAjFrCd8mtAH2nl/znWmdQGY=; b=04kJblYrasyZtOKvShDh93BP1xoDRdj68P0O/jx/UKhKU7iSdxULT8p96yo7Q/sfct HhNY4WVkrsfo1wDKc+l+gdI02zoJ+0k7acaGucrZHvZjpQdZUhnV9imeQYHZnAZz/zfS SJhfqAVkF5ColZwcjfG9JeWA+BWTrIr0f9zjVxOyTcHX6MB/up10FP4ieSN80unbzs1+ fhHDHXLWl/0e9Ce+nc51hmcKB3aW4A/KCqJnkgi77tFzMioGbfaz+UTRJ2o/Hjwv5VQ2 vkpxaJyn0D2yQ0SpB4LRHdN0Adh09SwUOxj/I2F+S9D4HVqdzmqMk0eUwqgYw0uWi8hf bCZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail header.b=Gku9EbnA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o8si5981240eji.35.2020.10.18.05.33.23; Sun, 18 Oct 2020 05:33:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail header.b=Gku9EbnA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726689AbgJRMXZ (ORCPT + 99 others); Sun, 18 Oct 2020 08:23:25 -0400 Received: from mail-03.mail-europe.com ([91.134.188.129]:56990 "EHLO mail-03.mail-europe.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726671AbgJRMXY (ORCPT ); Sun, 18 Oct 2020 08:23:24 -0400 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 X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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