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=1796371179; b=Ou7h7Z/NYaVjeeh32SRmTKKirMspELNFVK5ZNULHD1wEtTHcCLuQNHSW9CYYFL0q8zXy okbDrvFHjoupJjOU5Jge3v4yJFa+Lv4FPCLKM5C7XbeyAExBBjcvelO9FIVe9NkcOCc3N z9NkdjHfJUMcWexh/ZPvRVQs6m7p5aRDXYkKkiPnWImfDFfrVWPPt2hxrM6dtudPeymXH X2JYYGwSn87Q4W+/IgGRvvTKBe9ggR00KhQ0QLCoEAGqb+mAk3EYLyfXRmbVqQeYmll/W S3UHn0fBMsL9ZDZtdN1waQf7FANAAYtC3ksIaPWUXFeHj53Obbdta/4UGuCejqbmnIg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796371179; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=4LBVvS03ii4lEqE2vkdk31ibhiroGwWPl9HSsQXY4Fk=; b=nOcO+2JLSBU6gpXZD8FnD6B+Avh87Sn48SpN7sccUabEh2VOddq0ilBA5f+CI1164nwO GcP7hILgd/xJaZCqy4FyWyMvt3LDWDVFvk94mkPNl3MnuYeQaaiOzVUaTmtkQK8d3AG98 hdErKBSbaO8kF/IDtFMFynxeQE6n4IF39OKB+XzTV8/oNn3QhhkcBkBURhsrmcfa8F49E FpxAVXTg98ZWIE/bvvJCZpGKbVAbyFLR/1J57y6uqL8ATxJlo4mc5mPI/2Ijjzd/+IkLp XCbFSs9iM9UpvETfYA825Tr2RVQ5UCl4wMbetVqWFNnsXZcjvDJxYrS8xSysQ/KXFXg== 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=WC21DvkM; 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 0006C606A322 for ; Fri, 4 Dec 2026 07:59:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=WC21DvkM Received: by smtp.kernel.org (Postfix) with ESMTPSA id 941151F000C2; Fri, 4 Dec 2026 07:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796371178; bh=4LBVvS03ii4lEqE2vkdk31ibhiroGwWPl9HSsQXY4Fk=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=WC21DvkMCz7i1BXjez7/zTDUPWqGhqRcv05NICPThHVIr8Jj7eZ4fa1zf7gwPPJEU N5iX0JcRaow2cD7Zu1OWPYOCf7uTtA+yeU6HiONJCcdE/f9wQqpJ3t7kk4LXVzu5XW exVsZQMxZ4Un5BkHQmC5s6Z5zDFj6usBcWNVmOIo7fzVNDikPAGdJLz5TL6jjxasSw 0x9l8RVOJlw8u0I6zwOU3xaYUwwAVOkfNKute6oxfiH7QJ2eYU05CUj53QkOVNu05J HriLiUmNCEda3zNE0SAVf768qkIshuciKwozrJyLMzg9SEkUt6McNNlhOcOvbGnxB+ YQZu1fQyqTUkA== 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: <1796369755.32249.0@17236081.qq.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 07:59:38 +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: unsynchronized fts5_drain() calls race on ts->buf and MT state - [High] Input: FTS5_EVENT_ID_READY aliases empty FIFO under 0xf0 mask - [High] Input: fts5_resume() enables IRQ and polling after fts5_startup() failure - [Medium] Input: fts5_probe() and fts5_suspend() misorder IRQ enable and ts->ready - [Medium] Input: fts5_remove() releases contacts while devm IRQ is still active - [Medium] Input: fts5_touch advertises INPUT_MT_DIRECT without pointer emulation - [Medium] Input: unconditional 10 Hz fts5_poll() continuously wakes CPU and I2C - [Medium] input: fts5_probe() sets ABS_MT_PRESSURE after touchscreen_parse_properties() - [Medium] input: fts5_probe() ignores optional reset-gpios defined in st,stmfts.yaml - [Medium] input: fts5_probe() leaves X/Y axis maximums at 0 when DT sizes are absent - [Low] input: fts5_i2c_write() and fts5_i2c_wr_rd() discard i2c_transfer() errnos - [Low] input: fts5_id table uses positional initializer instead of named initializer - [Low] input: fts5_touch.c violates Input error variable and return conventions - [Low] input: fts5_probe() omits client->irq > 0 check before requesting IRQ -- commit 0699178567233d6ab1558029861fa1f8b53c9dac 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 FTM5 register, scan mode, and 8-byte event FIFO protocol with a periodic workqueue drain and sleep power management. > 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 > @@ -0,0 +1,478 @@ [ ... ] > +/* 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: High] Does masking to the upper nibble make FTS5_EVENT_ID_READY indistinguishable from an empty FIFO? fts5_startup() polls for FTS5_EVENT_ID(ts->buf) =3D=3D FTS5_EVENT_ID_READY = while fts5_drain() stops on !FTS5_EVENT_ID(ts->buf), so both evaluate (ts->buf[0] & 0xf0) =3D=3D 0x00. As a result, fts5_startup() breaks out on= the first empty 0x00 read before the controller finishes resetting, and fts5_drain() aborts early on any 0x01..0x0f event, leaving later touch events in the FIFO with active-low nIRQ asserted. Matching the exact empty-FIFO byte (0x00) separately from the CONTROLLER_READY event byte avoids both issues. [ ... ] > +static int fts5_i2c_write(struct fts5_data *ts, const u8 *data, int len) > +{ > + struct i2c_msg msg =3D { > + .addr =3D ts->client->addr, > + .len =3D len, > + .buf =3D (u8 *)data, > + }; > + > + 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; > + > + return 0; > +} [Severity: Low] Should fts5_i2c_write() and fts5_i2c_wr_rd() propagate negative error codes from i2c_transfer() instead of replacing them with -EIO? Returning -EIO only on a short transfer count preserves bus errors like -ETIMEDOUT or -ENXIO. Also, fts5_probe() does not check i2c_check_functionality(client->adapter, I2C_FUNC_I2C), so an SMBus-only adapter powers on the regulators and sleeps before failing in fts5_startup(). [ ... ] > +static int fts5_scan_mode(struct fts5_data *ts, u8 mode, u8 settings) > +{ > + /* select the FTM5 system command page */ > + const u8 page[7] =3D { > + FTS5_CMD_HW_REG, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, > + }; > + u8 scan[3] =3D { FTS5_CMD_SCAN_MODE, mode, settings }; > + int ret; > + > + ret =3D fts5_i2c_write(ts, page, sizeof(page)); > + if (ret) > + return ret; > + > + return fts5_i2c_write(ts, scan, sizeof(scan)); > +} [Severity: Low] Input subsystem convention prefers naming error-only variables error (or err) instead of ret, and checking the final error-returning call with an explicit return 0 on the success path in functions with multiple failure points. The same pattern appears in fts5_startup(), fts5_resume(), fts5_suspend(), fts5_drain(), and fts5_probe(). [ ... ] > +static int fts5_drain(struct fts5_data *ts) > +{ > + int count =3D 0; > + int i, ret; > + > + for (i =3D 0; i < 2 * FTS5_FIFO_DEPTH; i++) { > + ret =3D fts5_read_events(ts, ts->buf, 1); > + if (ret) { > + dev_warn_ratelimited(&ts->client->dev, "read events: %d\n", > + ret); > + break; > + } > + > + if (!FTS5_EVENT_ID(ts->buf)) > + break; > + > + fts5_handle_event(ts, ts->buf); > + count++; > + } > + > + if (count) > + input_sync(ts->input); > + > + return count; > +} [Severity: High] Can fts5_irq() and fts5_poll() run fts5_drain() concurrently and corrupt ts->buf, ts->contacts, and multi-touch slot state? Both the threaded IRQ handler and the 100 ms delayed work run in process context with no lock in struct fts5_data: IRQ thread kworker (fts5_poll) fts5_irq() fts5_poll() fts5_drain() fts5_drain() fts5_read_events(..., ts->buf) fts5_handle_event(..., ts->buf) fts5_report_contact() fts5_read_events(..., ts->buf) reads ts->buf[0..7] <-- torn event / overwritten buffer __set_bit(..., &ts->contacts) fts5_report_contact() input_mt_slot() input_mt_slot() <-- clobbers slot Because i2c_transfer() only locks the adapter during the transfer, one thread can overwrite ts->buf while the other decodes it. Concurrent non-atomic bitops on ts->contacts can also leave BTN_TOUCH stuck, and input_mt_report_slot_state() relies on callers to serialize updates to mt->slot and tracking IDs. Serializing FIFO drains, contact release, and state transitions with a mutex in struct fts5_data would prevent this race. > +/* > + * The controller drives nIRQ low while its FIFO is not empty, so a miss= ed > + * edge silences the panel until the next event. Empty the FIFO from a = slow > + * workqueue as well, which keeps the line moving regardless of the IRQ = state. > + */ > +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 this unconditional 10 Hz polling workqueue needed when nIRQ is driven low while the FIFO is non-empty? Running fts5_poll() every 100 ms from probe until remove wakes the CPU and issues I2C transfers continuously while awake, even when idle or when no consumer has opened the input device. With an active-low level-triggered interrupt (IRQ_TYPE_LEVEL_LOW, as documented in st,stmfts.yaml) and IRQF_ONESHOT, there is no missed-edge problem. In addition, the driver has no input->open/close callbacks or runtime PM to stop scanning when unused, and fts5_remove() leaves the controller scanning even though the shared display rails stay powered. [ ... ] > +static int fts5_resume(struct device *dev) > +{ > + struct fts5_data *ts =3D dev_get_drvdata(dev); > + int ret; > + > + if (!ts) > + return 0; > + > + 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 fts5_resume() trigger an infinite interrupt storm if fts5_startup() fails? When fts5_startup() returns an error, ts->ready stays false, yet fts5_resume() still drains the failed controller, enables client->irq, and restarts the 100 ms poll work. If an active-low level-triggered nIRQ is asserted, fts5_irq() sees ts->ready =3D=3D false, skips draining the FIFO, = and returns IRQ_HANDLED, causing the threaded IRQ to spin forever and bypassing spurious-IRQ detection. On startup failure, fts5_resume() should skip draining, enabling the IRQ, and scheduling ts->poll, while tracking IRQ enable state so a later fts5_suspend() does not call disable_irq() twice. [ ... ] > +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 an active fts5_irq() thread race with fts5_release_contacts() during driver removal? i2c_device_remove() calls fts5_remove() before devres_release_group() frees the devm-managed IRQ: CPU0 CPU1 (IRQ thread) fts5_remove() fts5_irq() if (ts->ready) -> true ts->ready =3D false cancel_delayed_work_sync(...) fts5_release_contacts() fts5_drain() clears MT slots / contacts fts5_report_contact() <-- races While cancel_delayed_work_sync() blocks with ts->ready =3D=3D false and the= IRQ still enabled, an asserted active-low level IRQ also causes fts5_irq() to return IRQ_HANDLED repeatedly without draining. Managing the work teardown via devres ordered with IRQ disable/synchronization avoids both the race and mixing devm with manual cleanup. [ ... ] > + 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() request and deassert the optional reset-gpios property? Commit "dt-bindings: input: touchscreen: st,stmfts: add st,fts" adds st,fts to the shared st,stmfts.yaml binding, which documents an optional active-low reset-gpios line. On boards where that line defaults asserted, the controller stays held in reset and fts5_startup() fails over I2C. [ ... ] > + 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] What happens if touchscreen-size-x or touchscreen-size-y is omitted from the device tree? Neither property is required by st,stmfts.yaml. Without them, the input device registers X and Y with range [0, 0], and enabling touchscreen-inverted-x or touchscreen-inverted-y causes unsigned underflow (prop->max_x - *x) in touchscreen_apply_prop_to_x_y(). Setting a non-zero default range before touchscreen_parse_properties() or rejecting zero max_x/max_y would prevent this. > + input_set_abs_params(input, ABS_MT_PRESSURE, 0, 255, 0, 0); [Severity: Medium] Does setting ABS_MT_PRESSURE after touchscreen_parse_properties() discard device tree pressure properties? When touchscreen-max-pressure or touchscreen-fuzz-pressure is present, touchscreen_set_params() warns that ABS_MT_PRESSURE is not set up yet and skips it, and this call would overwrite any parsed limits anyway. Moving this call before touchscreen_parse_properties() fixes both. [ ... ] > + input_set_capability(input, EV_KEY, BTN_TOUCH); > + > + ret =3D input_mt_init_slots(input, FTS5_MAX_CONTACTS, INPUT_MT_DIRECT); [Severity: Medium] Does passing INPUT_MT_DIRECT without calling input_mt_sync_frame() leave advertised single-touch axes unreported? input_mt_init_slots() with INPUT_MT_DIRECT sets BTN_TOUCH (making the explicit input_set_capability() above redundant) and copies ABS_MT_POSITION_X/Y and ABS_MT_PRESSURE to ABS_X, ABS_Y, and ABS_PRESSURE. Because neither fts5_drain() nor fts5_release_contacts() calls input_mt_sync_frame() or input_mt_report_pointer_emulation(), those advertised single-touch axes stay at 0 for single-touch userspace clients. Calling input_mt_sync_frame() before input_sync() in fts5_drain() and fts5_release_contacts() handles pointer emulation and removes the need for manual ts->contacts tracking. [ ... ] > + ret =3D input_register_device(input); > + if (ret) > + return ret; > + > + ts->input =3D input; > + > + /* > + * The trigger type comes from the device tree, so request the > + * interrupt without IRQF_TRIGGER_* flags. > + */ > + ret =3D devm_request_threaded_irq(dev, client->irq, NULL, fts5_irq, > + IRQF_ONESHOT, dev_name(dev), ts); [Severity: Low] Should fts5_probe() verify client->irq > 0 before requesting the interrupt? When no IRQ is assigned (for example via sysfs new_device), i2c_device_probe() sets client->irq to 0. request_threaded_irq() does not reject 0 unconditionally and looks up irq_to_desc(0), so validating client->irq early fails cleanly before powering on the hardware or registering the input device. [ ... ] > + INIT_DELAYED_WORK(&ts->poll, fts5_poll); > + schedule_delayed_work(&ts->poll, msecs_to_jiffies(100)); > + ts->ready =3D true; [Severity: Medium] Can enabling the IRQ and starting ts->poll before ts->ready is set cause spurious handling or a level-IRQ spin during probe? 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. If nIRQ is already asserted low, fts5_irq() fires, skips draining, and returns IRQ_HANDLED repeatedly until ts->ready =3D true becomes visible (and fts5_suspend() opens the same window by clearing ts->ready before disable_irq()). In addition, input_register_device() exposes the input device before IRQ acquisition succeeds, and plain bool ts->ready is accessed across threads without locking or READ_ONCE()/WRITE_ONCE(). Requesting the IRQ with IRQF_NO_AUTOEN before input_register_device(), disabling it before clearing ts->ready on suspend, and protecting state transitions with a mutex would close these windows. [ ... ] > +static const struct i2c_device_id fts5_id[] =3D { > + { "fts5_touch" }, > + { } > +}; [Severity: Low] I2C subsystem convention expects new struct i2c_device_id entries to use named initializers, i.e. { .name =3D "fts5_touch" }. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/tencent_24E2E777121= 4F73657B404816A24822DDE08@qq.com?part=3D2