From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796371785; b=g+4OFGdWsKoRiklm7gdzsF7F2sp0Om8rNZLYK7CBoLEDGtcy1ZskDi1g9K4hxswXhJoG Fk2c44RC+9ZNShy1ZxJrR9ns3f4aS7WrYzEbZsVXmv6CutkE8K1rBF7wKFpNXIc9vP7Bm 74HYXZJNNdpY1sIFcGLXVFHL1HeMT8BwYMQKpY/knaIKWYGL9TMp6qEw3NrEugEqypn0q cGzbfCLzu/JNiQcpN5+9m1QQqAAqNtFOXmrsr8T1QDRTIBXhS8Bp+0zE+zfaZShsftagq f+AtTvLeqlNEZASG3ymnNf3hyM7uQHPUt/7/KgEG5QnT9Pem8CaNKYZ+VxyFb6gMEZQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796371785; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=H+I1C0eqSsNacv9Zvxgav1Hy4DQyYQvLxUtFe7CJ9go=; b=iKxNWMw9+k3MunOcqByPqn0pxk5hgTFLKX4ioARhrvYGUDmDQRxlL+k542CudayJ7kih eWc7gtMTfU5clL3i/3Wk2nFwI2Am/Jk3hJ617CzEYFVyQepNdyq8NIs6465njU63ZhDER 5sPTB1R6WHO5IAsH9p90+2F0BqowjwLTeoCrX7qNTgbqBeYKdGrpf1eS+0tct4xdpyOwI qB6hWFkhP/+g8UjLfeDDPtihD8k7RgQRaHkzRu4flWfvkvqBpc3jxl0/+xKzUJgCI3fnx rgLcJI8EnjeyiG21y3wUxJkkjei5A68AE9nUNAGwc3hnpawRMosbe/N9a4ZtxV4gEtA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FVqPFI1s; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB637606A322 for ; Fri, 4 Dec 2026 08:09:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FVqPFI1s Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4363C1F0092C; Fri, 4 Dec 2026 08:09:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796371785; bh=H+I1C0eqSsNacv9Zvxgav1Hy4DQyYQvLxUtFe7CJ9go=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=FVqPFI1sOkmL5gooOXVgv/R2o4re53YwUuXBaZE19fIvIOsRL3wNWgkGnJsdMe10Z 9ZAYrduVBxzRVkc7DerjPtFZQc+X0rPeR4Bg48Wp9/dP+VZUYDpe6NKSS8WYEytbJR 1nbKB6zjhk7fG/2+w0isFOi6DnmERKgphA0cJu9EoO/MzRZUfqopD84ttoEQtRUmN5 At4tJWQ1H0Vyl9wLGxag9kdii+6QCEivs2r16s+2VDyqaXWVCkd5ECGNwdhKA+1sgM yDfVKrwcpL2AbzDaScoLpu5MxAgGWi9Gpwq4vaNbCbRMUgc0YMIkXaOOefwQc+HmHj FYMxKQck1D9Lg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 2/2] Input: add STMicroelectronics FTM5 touchscreen driver Reply-To: sashiko-reviews@lists.linux.dev To: "sthho law" <17236081@qq.com> Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: References: <1796370440.32551.0@17236081.qq.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 08:09:44 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 14 potential issues to consider: - [High] input: fts5_touch: unsynchronized concurrent fts5_drain() from IRQ and poll - [High] input: fts5_touch: fts5_resume() enables IRQ and poll on startup failure - [Medium] input: fts5_touch: fts5_remove() races with active devm-managed IRQ - [Medium] input: fts5_touch: FTS5_EVENT_ID_READY collides with empty-FIFO check - [Medium] input: fts5_touch: fts5_probe() enables IRQ before ts->ready is set - [Medium] input: fts5_touch: ts->ready race and early IRQ enable in fts5_probe() - [Medium] input: fts5_touch: unconditional 100 ms polling in fts5_poll() wastes power - [Medium] input: fts5_touch: missing input_mt_sync_frame() breaks pointer emulation - [Medium] input: fts5_touch: ABS_MT_PRESSURE set after touchscreen_parse_properties() - [Medium] input: fts5_touch: missing max_x/max_y validation in fts5_probe() - [Medium] input: fts5_touch: fts5_probe() ignores optional reset-gpios DT property - [Low] input: fts5_touch: I2C helpers mask errors as -EIO and skip I2C_FUNC_I2C - [Low] input: fts5_touch: positional fts5_id, style issues, and over-sized ts->buf - [Low] input: fts5_touch: missing client->irq validation in fts5_probe() -- commit 652df6ed697a53efcef86296d5d490e2bdd42e7d Author: sthho law <17236081@qq.com> Input: add STMicroelectronics FTM5 touchscreen driver This commit adds an I2C touchscreen driver for STMicroelectronics FTM5 FingerTip controllers, implementing the 0xFA register access, 0xA0 scan mode, and 0x86 8-byte event FIFO protocol with threaded IRQ handling, periodic workqueue draining, and suspend/resume support. > diff --git a/drivers/input/touchscreen/fts5_touch.c b/drivers/input/touch= screen/fts5_touch.c > new file mode 100644 > index 0000000000000..60a0f8f50b57e > --- /dev/null > +++ b/drivers/input/touchscreen/fts5_touch.c [ ... ] > +/* the upper nibble of the first event byte selects the event class */ > +#define FTS5_EVENT_ID(ev) ((ev)[0] & 0xf0) > +#define FTS5_EVENT_ID_READY 0x00 [Severity: Medium] Does masking to the upper nibble make FTS5_EVENT_ID_READY indistinguishable from an empty FIFO? fts5_drain() stops on !FTS5_EVENT_ID(ts->buf), while fts5_startup() waits for FTS5_EVENT_ID(ts->buf) =3D=3D FTS5_EVENT_ID_READY. Because FTS5_EVENT_ID_READY is 0x00, those two checks are identical: fts5_startup() exits its readiness loop on the first iteration whenever the FIFO returns 0x00, and fts5_drain() stops early if any 0x01..0x0f event appears ahead of touch events, leaving unread entries in the FIFO and nIRQ asserted low. [ ... ] > + if (i2c_transfer(ts->client->adapter, &msg, 1) !=3D 1) > + return -EIO; > + > + return 0; > +} > + > +static int fts5_i2c_wr_rd(struct fts5_data *ts, const u8 *wbuf, int wlen, > + u8 *rbuf, int rlen) > +{ > + struct i2c_msg msg[2] =3D { > + { > + .addr =3D ts->client->addr, > + .len =3D wlen, > + .buf =3D (u8 *)wbuf, > + }, { > + .addr =3D ts->client->addr, > + .flags =3D I2C_M_RD, > + .len =3D rlen, > + .buf =3D rbuf, > + }, > + }; > + > + if (i2c_transfer(ts->client->adapter, msg, 2) !=3D 2) > + return -EIO; [Severity: Low] Should fts5_i2c_write() and fts5_i2c_wr_rd() propagate negative error codes returned by i2c_transfer() instead of replacing them with -EIO? Discarding the return value hides errors like -ETIMEDOUT or -ENXIO in probe and runtime logs. fts5_probe() also skips i2c_check_functionality(client->adapter, I2C_FUNC_I2C), so probing on an SMBus-only adapter enables regulators and waits 20 ms before failing on the first raw transfer. [ ... ] > + if (count) > + input_sync(ts->input); [Severity: Medium] Should fts5_drain() and fts5_release_contacts() call input_mt_sync_frame() before input_sync()? fts5_probe() passes INPUT_MT_DIRECT to input_mt_init_slots(), which sets BTN_TOUCH (making the explicit input_set_capability() for BTN_TOUCH redundant) and advertises single-touch ABS_X, ABS_Y, and ABS_PRESSURE axes. Without input_mt_sync_frame() or input_mt_report_pointer_emulation(), those emulated axes are never reported, leaving single-touch consumers with zero coordinates and pressure while BTN_TOUCH toggles. Using input_mt_sync_frame() also removes the need to track ts->contacts and report BTN_TOUCH manually. [ ... ] > +static void fts5_poll(struct work_struct *work) > +{ > + struct fts5_data *ts =3D container_of(to_delayed_work(work), > + struct fts5_data, poll); > + > + if (ts->ready) > + fts5_drain(ts); > + > + schedule_delayed_work(&ts->poll, msecs_to_jiffies(100)); > +} [Severity: Medium] Is an unconditional 100 ms polling loop needed here? fts5_poll() re-arms itself forever while the device is awake, issuing an I2C transaction every 100 ms even when the panel is idle, no input client has opened the device, or fts5_resume() failed. That prevents deep CPU idle and I2C controller runtime autosuspend on mobile hardware. Since the controller drives nIRQ low while its FIFO is non-empty, an active-low level-triggered interrupt (as specified in Documentation/devicetree/bindings/input/touchscreen/st,stmfts.yaml) with IRQF_ONESHOT handles unread FIFO data without permanent background polling. > + > +static irqreturn_t fts5_irq(int irq, void *data) > +{ > + struct fts5_data *ts =3D data; > + > + if (ts->ready) > + fts5_drain(ts); > + > + return IRQ_HANDLED; > +} [Severity: High] Can fts5_irq() and fts5_poll() run fts5_drain() concurrently and corrupt ts->buf, ts->contacts, and MT slot state? struct fts5_data has no lock serializing fts5_drain(). Both the threaded IRQ handler and the 100 ms workqueue run in sleepable context and share the single ts->buf buffer: CPU0 (fts5_irq) CPU1 (fts5_poll) fts5_drain() fts5_drain() fts5_read_events(..., ts->buf) fts5_read_events(..., ts->buf) fts5_handle_event(ts, ts->buf) <-- reads overwritten ts->buf __set_bit(slot, &ts->contacts) __clear_bit(slot, &ts->contacts) input_mt_slot(input, slot) input_mt_slot(input, other_slot) input_mt_report_slot_state(...) <-- reports into wrong slot Once one thread's i2c_transfer() finishes, the other overwrites ts->buf in place mid-decode, non-atomic bitops on ts->contacts can lose updates and leave BTN_TOUCH stuck, and concurrent input_mt_slot() calls attribute coordinates and tracking IDs to the wrong slot. Serializing fts5_drain() and fts5_release_contacts() with a mutex in struct fts5_data would prevent this. [ ... ] > + ts->ready =3D false; > + disable_irq(ts->client->irq); > + cancel_delayed_work_sync(&ts->poll); [Severity: Medium] Does writing ts->ready without synchronization race with fts5_irq() and fts5_poll()? fts5_suspend() and fts5_remove() store ts->ready =3D false before disable_irq() and cancel_delayed_work_sync() complete, and fts5_probe() stores ts->ready =3D true after the IRQ and poll work are already active, while fts5_irq() and fts5_poll() read ts->ready with plain accesses. Calling disable_irq() and cancel_delayed_work_sync() before clearing ts->ready (or protecting it under a lock) removes the data race. [ ... ] > + ret =3D fts5_startup(ts); > + if (ret) > + dev_err(dev, "failed to resume: %d\n", ret); > + > + ts->ready =3D !ret; > + fts5_drain(ts); > + enable_irq(ts->client->irq); > + schedule_delayed_work(&ts->poll, msecs_to_jiffies(100)); > + > + return ret; [Severity: High] Can a failed fts5_startup() in fts5_resume() trigger a permanent interrupt storm? When fts5_startup() fails, fts5_resume() sets ts->ready =3D false but still calls fts5_drain(), enable_irq(), and schedule_delayed_work(). If nIRQ is asserted low on a level-triggered line, fts5_irq() skips fts5_drain() because ts->ready is false yet still returns IRQ_HANDLED, which unmasks the IRQF_ONESHOT line and defeats spurious-IRQ detection, causing the IRQ thread to spin continuously. Returning early on failure avoids the storm, the I2C reads against a failed chip, and the 10 Hz no-op poll; fts5_suspend() will then need to track whether the IRQ is enabled to avoid an unbalanced disable_irq(). [ ... ] > +static void fts5_remove(struct i2c_client *client) > +{ > + struct fts5_data *ts =3D i2c_get_clientdata(client); > + > + ts->ready =3D false; > + cancel_delayed_work_sync(&ts->poll); > + fts5_release_contacts(ts); > +} [Severity: Medium] Can fts5_remove() race with an active fts5_irq() because the devm-managed IRQ is still enabled? i2c_device_remove() runs driver->remove() before devres_release_group() frees the IRQ registered with devm_request_threaded_irq(): CPU0 (fts5_remove) CPU1 (fts5_irq) if (ts->ready) ts->ready =3D false cancel_delayed_work_sync(...) fts5_release_contacts(ts) fts5_drain(ts) <-- races on ts->input An in-flight fts5_irq() can race with fts5_release_contacts() and re-report contacts, and any level-low IRQ arriving while cancel_delayed_work_sync() sleeps will storm until devres frees the IRQ. fts5_remove() also leaves the controller in active scan mode on the shared display rails instead of switching to FTS5_SCAN_MODE_LOW_POWER. [ ... ] > + ret =3D regulator_bulk_enable(ARRAY_SIZE(ts->supplies), ts->supplies); > + if (ret) > + return ret; > + > + ret =3D devm_add_action_or_reset(dev, fts5_power_off, ts); > + if (ret) > + return ret; > + > + /* let the rails settle before the controller is talked to */ > + msleep(20); > + > + ret =3D fts5_startup(ts); [Severity: Medium] Should fts5_probe() handle the optional reset-gpios property defined in Documentation/devicetree/bindings/input/touchscreen/st,stmfts.yaml? If a board wires the active-low reset line and leaves it asserted at boot, the controller stays in reset and fts5_startup() fails to communicate over I2C. Acquiring it via devm_gpiod_get_optional() and deasserting it before fts5_startup() (matching stmfts.c) avoids that. [ ... ] > + input_set_abs_params(input, ABS_MT_POSITION_X, 0, 0, 0, 0); > + input_set_abs_params(input, ABS_MT_POSITION_Y, 0, 0, 0, 0); > + touchscreen_parse_properties(input, true, &ts->prop); [Severity: Medium] Should fts5_probe() reject !ts->prop.max_x || !ts->prop.max_y after touchscreen_parse_properties()? Because touchscreen-size-x and touchscreen-size-y are optional in st,stmfts.yaml and the driver never reads panel dimensions from hardware, omitting them leaves the advertised axis limits at [0, 0] while emitting raw 0..4095 coordinates. If touchscreen-inverted-x or touchscreen-inverted-y is set, touchscreen_apply_prop_to_x_y() computes 0 - x and underflows. > + > + input_set_abs_params(input, ABS_MT_PRESSURE, 0, 255, 0, 0); [Severity: Medium] Does setting ABS_MT_PRESSURE after touchscreen_parse_properties() ignore device tree pressure properties? touchscreen_parse_properties() parses touchscreen-max-pressure and touchscreen-fuzz-pressure into ABS_MT_PRESSURE, but touchscreen_set_params() warns and returns early if the axis bit is not yet set, and this call then overwrites the range to [0, 255]. Moving this call before touchscreen_parse_properties() establishes the default while allowing DT overrides. [ ... ] > + ret =3D devm_request_threaded_irq(dev, client->irq, NULL, fts5_irq, > + IRQF_ONESHOT, dev_name(dev), ts); > + if (ret) { > + dev_err(dev, "failed to request irq %d: %d\n", client->irq, ret); > + return ret; > + } [Severity: Low] Should fts5_probe() check client->irq <=3D 0 up front instead of passing 0 = to devm_request_threaded_irq()? When no interrupt is assigned (for example via sysfs new_device or a DT node missing interrupts), i2c_device_probe() leaves client->irq as 0. On architectures with a legacy IRQ 0 descriptor, request_threaded_irq() tries to claim IRQ 0 after powering on the panel and registering the input device, rather than failing probe immediately with -EINVAL. > + > + INIT_DELAYED_WORK(&ts->poll, fts5_poll); > + schedule_delayed_work(&ts->poll, msecs_to_jiffies(100)); > + ts->ready =3D true; > + > + i2c_set_clientdata(client, ts); [Severity: Medium] Can an interrupt firing right after devm_request_threaded_irq() storm or be dropped before ts->ready becomes true? fts5_startup() has already enabled active scanning, and devm_request_threaded_irq() enables client->irq without IRQF_NO_AUTOEN while ts->ready is still false and before ts->poll and clientdata are initialized. If nIRQ is already asserted low, fts5_irq() skips fts5_drain() and returns IRQ_HANDLED, causing a level-triggered interrupt storm until ts->ready =3D true is visible (or dropping an edge until the 100 ms poll runs). Initializing ts->poll, clientdata, and ts->ready before requesting the IRQ (or using IRQF_NO_AUTOEN) closes that window. [ ... ] > +static const struct i2c_device_id fts5_id[] =3D { > + { "fts5_touch" }, > + { } > +}; [Severity: Low] This isn't a bug, but a few style and cleanup points: - New struct i2c_device_id entries should use named initializers ({ .name =3D "fts5_touch" }). - Input drivers conventionally name error-only variables error or err rather than ret, and use expanded error checks with an explicit return 0 in multi-failure functions such as fts5_scan_mode() and fts5_startup(). - fts5_probe() allocates FTS5_EVENT_SIZE * FTS5_FIFO_DEPTH (256 bytes) for ts->buf, but fts5_read_events() is only ever called with count =3D 1 (8 bytes). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/tencent_3ED5BA051BB= D45CEA724F0EF5BAEAE089C09@qq.com?part=3D2