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=1795979278; b=5VYvVRg2wcxwyNVoAzUMrjLbElS3k3K4qbGNvBmQ88VzN6WLX2VE1gfXT2UsfTrAZ3L1 LYYgjVhDS6yj+yGH9wdb2aj2lvL29mhUFe4+48ll9KI8yYgJV4vsKFUQu1KrP1O/bV6DD oUVEFtaTnqsK9mJu1GgkysrWWcWYE7ENU46is2vy206IPjTRJyQiUDAAOjoFh3BJcwX0s GuOUQEAxqo5PcU6Ysnt8wb/OgB691SMqKsQ9fv07guj9OlHfbft2COH/MbexHbOgq4v+V 0vlaGzHSJYKg9cfPKadKSh6M4oGFduxYhWhUz+eLJHJwczO30q00XQ7guTGLXjbMBtg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795979278; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=k2+OdHvcIAgdey6n0vPOjXAwTvdhERdTNI1DhV7v5Ds=; b=EJ4cjA/3XwivsZ7tHQQOrVRVpnioCDxSPkTYs0zbrb7JY4DtjiGj4R2KSokRz/K/5duU OieE1aSph6lDJjb15UjThzG7pFXe4AdvwREF5U1CWxri6XOU3OvY0hNYv8OkugQCElX4t Ro+jsgQKSA71IKrfFPHHWaZ7ZW6xFe58DtVwj4xZ8ckrGiY/qQzb9HAE5EEnnyh+SvUQC SbcCcHKjaCvjX4LDcWhZAAAzS1/ra+gYv0WrkuXpxmEyge8L5uVXsVdipFb4ewuU+d5Hd 3qhxARLJHK0TLeQnX1GiCR5nEwaNxsn/kw225LQDzvQEg6hdxTfmFOxNuOTVgxAU0BQ== 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=cc7blVXG; 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 F2E97606A31C; Sun, 29 Nov 2026 19:07:57 +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=cc7blVXG Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BB101F00896; Sun, 29 Nov 2026 19:07:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795979277; bh=k2+OdHvcIAgdey6n0vPOjXAwTvdhERdTNI1DhV7v5Ds=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=cc7blVXGXcrIfurVqbSogWlrOwtcMUq0LBHokKm7GmAWO7HWYgMtK1rQrR2CL/r2S IjpKvgRZdLWuIf7XP01l1tOw0E9ML2WKZg9rT8Dvg89F1W3rg1klJ5L1MUExPAjgB0 IJXcKubBQaDh+ScW2oIWdAqpjfyXQFumZFudT8KcOfiZV7RKBX14OrJIL3NS9OCqEE oBxLXH7XANo5rJFm7uD8mrXf5uIwvu0yKBEFoucUL1WhvscFgLmp/hCQFKdQmBR94v IOaJ4ORYqIMKkh8QU+M9ICQGfqRaeSJ+Bhl1PjvZIwAZJqP2907P8Jx3BqQCSMsJ4o 8Eiv1a9Of0uog== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH RFC 2/2] Input: add Maxim MAX11936 touchscreen driver Reply-To: sashiko-reviews@lists.linux.dev To: "Patrick Fischer" Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org, dmitry.torokhov@gmail.com In-Reply-To: <20261129-upstream-touch-max11936-v1-2-6f98b121b56b@tsv-stahl-riesa.de> References: <20261129-upstream-touch-max11936-v1-0-6f98b121b56b@tsv-stahl-riesa.de> <20261129-upstream-touch-max11936-v1-2-6f98b121b56b@tsv-stahl-riesa.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 29 Nov 2026 19:07:56 +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 3 potential issues to consider: - [Medium] Input: max11936 - unmatched contacts inherit undecided slots in max11936_slots_match() - [Medium] Input: max11936 - negative coordinates in max11936_centroid() not clamped - [Low] Input: max11936 - page address 0 bypasses buffer check in max11936_read_frame() -- commit 86f2cacf758e1982ade848c538a3a8dd41492144 Author: Patrick Fischer Input: add Maxim MAX11936 touchscreen driver This commit adds an input driver for the Maxim MAX11936 SPI touchscreen controller used in the NVIDIA Tegra Note 7, decoding raw capacitance frames into touch and pen contacts in the kernel. > diff --git a/drivers/input/touchscreen/max11936-algo.c b/drivers/input/to= uchscreen/max11936-algo.c > new file mode 100644 > index 0000000000000..77adb224d8e2f > --- /dev/null > +++ b/drivers/input/touchscreen/max11936-algo.c [ ... ] > +/* centroid around a peak, mapped to the screen */ > +static void max11936_centroid(struct max11936_algo *a, int s, int c, > + struct max11936_peak *pk) > +{ > + const struct max11936_panel *p =3D a->p; > + s32 floor =3D SIG(a, s, c) >> FLOOR_SHIFT; > + s32 sw =3D 0, ss =3D 0, sc =3D 0, sq, cq; > + > + for (int ds =3D -WIN_S; ds <=3D WIN_S; ds++) { > + for (int dc =3D -WIN_C; dc <=3D WIN_C; dc++) { > + int u =3D s + ds, w =3D c + dc; > + s32 q; > + > + if (u < 0 || u >=3D p->n_tx || w < 0 || w >=3D p->n_rx || > + SIG(a, u, w) <=3D floor) > + continue; > + q =3D SIG(a, u, w) - floor; > + sw +=3D q; > + ss +=3D q * u; > + sc +=3D q * w; > + } > + } > + > + /* > + * The peak itself is above floor (t_off > 0), so sw > 0. |S| stays > + * below n_tx * max|code_inv| * DIFF_CLAMP >> 16, for the Tegra Note 7 > + * 8523, which keeps ss * 256 and sc * 256 below 1.3 * 10^9. > + */ > + sq =3D (ss * 256 + sw / 2) / sw; > + cq =3D (sc * 256 + sw / 2) / sw; > + pk->x =3D (p->x0 - ((p->kx * cq) >> 8)) >> 8; > + pk->y =3D (p->y0 - ((p->ky * sq) >> 8)) >> 8; > +} [Severity: Medium] Should pk->x and pk->y be clamped to [0, p->x_max] and [0, p->y_max]? With max11936_tegratab's mapping constants, peaks on the outermost sense line (c =3D 23) or drive line (s =3D 39) produce coordinates down to -4. max11936_report() passes those negative values to touchscreen_set_mt_pos() and touchscreen_report_pos(), which take unsigned int coordinates and report values outside the advertised axis ranges. [ ... ] > +void max11936_slots_match(const struct max11936_slot *slots, int nslots, > + const struct max11936_contact *c, int *slot, int n, > + s32 dmax) > +{ > + bool taken[MAX11936_MAX_CONTACTS] =3D { }; > + > + for (int i =3D 0; i < n; i++) > + if (slot[i] >=3D 0 && slot[i] < nslots && slots[slot[i]].reported) > + taken[slot[i]] =3D true; > + > + for (int i =3D 0; i < n; i++) { > + s32 best =3D dmax * dmax + 1; > + int u =3D -1; > + > + if (slot[i] < 0 || slot[i] >=3D nslots || slots[slot[i]].reported) > + continue; > + for (int k =3D 0; k < nslots; k++) { > + s32 dx =3D c[i].x - slots[k].x, dy =3D c[i].y - slots[k].y; > + > + if (!slots[k].active || slots[k].reported || taken[k] || > + dx * dx + dy * dy >=3D best) > + continue; > + best =3D dx * dx + dy * dy; > + u =3D k; > + } > + if (u < 0) > + continue; > + /* swap with a contact that got slot u */ > + for (int j =3D 0; j < n; j++) > + if (slot[j] =3D=3D u) > + slot[j] =3D slot[i]; > + slot[i] =3D u; > + taken[u] =3D true; > + } > +} > + > +/** > + * max11936_slots_update() - apply the contacts of a frame to the slots > + * @p: panel data > + * @slots: slot state > + * @nslots: number of @slots > + * @c: contacts of the frame > + * @slot: slot of each contact (input_mt_assign_slots(), max11936_slots_= match()) > + * @n: number of contacts > + * > + * A contact is a finger as soon as one frame shows a finger; one that l= ooks > + * like a pen in its first @p->pen_frames frames is a pen. Until then it= is > + * not reported, and it is dropped if it vanishes before: pen taps short= er > + * than that are lost (the shortest one recorded lasted 11 frames). The = tool > + * stays for the life of the contact. A reported contact that vanishes s= tays > + * for @p->release frames at its last position, which bridges the flicke= r of > + * a finger whose signal crosses t_off while it is lifted. > + */ > +void max11936_slots_update(const struct max11936_panel *p, > + struct max11936_slot *slots, int nslots, > + const struct max11936_contact *c, const int *slot, > + int n) > +{ > + bool seen[MAX11936_MAX_CONTACTS] =3D { }; > + > + for (int i =3D 0; i < n; i++) { > + struct max11936_slot *s; > + > + if (slot[i] < 0 || slot[i] >=3D nslots || seen[slot[i]]) > + continue; > + s =3D &slots[slot[i]]; > + seen[slot[i]] =3D true; > + s->missed =3D 0; > + s->x =3D c[i].x; > + s->y =3D c[i].y; > + > + if (!s->active) { > + s->active =3D true; > + s->reported =3D false; > + s->frames =3D 0; > + } > + if (!s->reported) { > + s->frames++; > + if (!c[i].pen || s->frames >=3D p->pen_frames) { > + s->pen =3D c[i].pen; > + s->reported =3D true; > + } > + } > + } [Severity: Medium] Can an unmatched contact inherit an active undecided slot in max11936_slots_match()? Because unreported slots have no tracking ID in input->mt, input_mt_assign_slots() treats them as free and can assign slot[i] =3D k for a slot k where slots[k].active is true and slots[k].reported is false. If the previous undecided contact in slot k vanished and a new contact c[i] appears farther than dmax away, max11936_slots_match() finds u < 0 (or swaps another contact into slot[i]) and leaves slot[i] =3D=3D k. max11936_slots_update() then sees s->active already set, so it neither expires the vanished contact nor resets s->frames to 0, and the new contact inherits the vanished contact's frame count toward p->pen_frames. Also, because c[] is ordered by signal strength, the greedy loop in max11936_slots_match() lets a stronger new contact within dmax claim an existing weaker pen contact's undecided slot before that pen contact is matched. > diff --git a/drivers/input/touchscreen/max11936-core.c b/drivers/input/to= uchscreen/max11936-core.c > new file mode 100644 > index 0000000000000..e1532df781a3f > --- /dev/null > +++ b/drivers/input/touchscreen/max11936-core.c [ ... ] > +static int max11936_read_frame(struct max11936 *ts) > +{ > + u16 *page =3D ts->page; > + unsigned int len =3D ts->frame_words, off =3D 0; > + u16 base =3D 0; > + int error; > + > + while (off < len) { > + unsigned int n =3D min(len - off, MAX11936_PAGE_WORDS); > + > + error =3D max11936_read(ts, REG_MAILBOX, page, n + 4); > + if (error) > + return error; > + > + if (page[3] =3D=3D PAGE_NOT_LEGACY) { > + max11936_write_reg(ts, REG_LEGACY_MODE, 1); > + max11936_legacy(ts, true); > + return -EAGAIN; > + } > + > + usleep_range(MAX11936_PAGE_DELAY_US, MAX11936_PAGE_DELAY_US + 25); > + > + if (page[0] !=3D PAGE_DATA) { > + max11936_write_reg(ts, REG_LEGACY_MODE, 1); > + return -EAGAIN; > + } > + if (!off && (page[1] =3D=3D ts->data->buf0 || page[1] =3D=3D ts->data-= >buf1)) > + base =3D page[1]; > + if (page[1] !=3D base + off) { > + max11936_write_reg(ts, REG_LEGACY_MODE, 1); > + return -EAGAIN; > + } [Severity: Low] Does page[1] =3D=3D 0 on the first page bypass the buffer address check her= e? Because base is initialized to 0, page[1] =3D=3D 0 at off =3D=3D 0 satisfies page[1] =3D=3D base + off even though it matches neither buf0 nor buf1. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261129-upstream-t= ouch-max11936-v1-0-6f98b121b56b@tsv-stahl-riesa.de?part=3D2