Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Patrick Fischer" <admin@tsv-stahl-riesa.de>
Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH RFC 2/2] Input: add Maxim MAX11936 touchscreen driver
Date: Sun, 29 Nov 2026 19:07:56 +0000	[thread overview]
Message-ID: <sashiko-outbox-239936@kernel.org> (raw)
In-Reply-To: <20261129-upstream-touch-max11936-v1-2-6f98b121b56b@tsv-stahl-riesa.de>

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 <admin@tsv-stahl-riesa.de>

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/touchscreen/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 = a->p;
> +	s32 floor = SIG(a, s, c) >> FLOOR_SHIFT;
> +	s32 sw = 0, ss = 0, sc = 0, sq, cq;
> +
> +	for (int ds = -WIN_S; ds <= WIN_S; ds++) {
> +		for (int dc = -WIN_C; dc <= WIN_C; dc++) {
> +			int u = s + ds, w = c + dc;
> +			s32 q;
> +
> +			if (u < 0 || u >= p->n_tx || w < 0 || w >= p->n_rx ||
> +			    SIG(a, u, w) <= floor)
> +				continue;
> +			q = SIG(a, u, w) - floor;
> +			sw += q;
> +			ss += q * u;
> +			sc += 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 = (ss * 256 + sw / 2) / sw;
> +	cq = (sc * 256 + sw / 2) / sw;
> +	pk->x = (p->x0 - ((p->kx * cq) >> 8)) >> 8;
> +	pk->y = (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 = 23) or drive line (s = 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] = { };
> +
> +	for (int i = 0; i < n; i++)
> +		if (slot[i] >= 0 && slot[i] < nslots && slots[slot[i]].reported)
> +			taken[slot[i]] = true;
> +
> +	for (int i = 0; i < n; i++) {
> +		s32 best = dmax * dmax + 1;
> +		int u = -1;
> +
> +		if (slot[i] < 0 || slot[i] >= nslots || slots[slot[i]].reported)
> +			continue;
> +		for (int k = 0; k < nslots; k++) {
> +			s32 dx = c[i].x - slots[k].x, dy = c[i].y - slots[k].y;
> +
> +			if (!slots[k].active || slots[k].reported || taken[k] ||
> +			    dx * dx + dy * dy >= best)
> +				continue;
> +			best = dx * dx + dy * dy;
> +			u = k;
> +		}
> +		if (u < 0)
> +			continue;
> +		/* swap with a contact that got slot u */
> +		for (int j = 0; j < n; j++)
> +			if (slot[j] == u)
> +				slot[j] = slot[i];
> +		slot[i] = u;
> +		taken[u] = 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 looks
> + * 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 shorter
> + * 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 stays
> + * for @p->release frames at its last position, which bridges the flicker 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] = { };
> +
> +	for (int i = 0; i < n; i++) {
> +		struct max11936_slot *s;
> +
> +		if (slot[i] < 0 || slot[i] >= nslots || seen[slot[i]])
> +			continue;
> +		s = &slots[slot[i]];
> +		seen[slot[i]] = true;
> +		s->missed = 0;
> +		s->x = c[i].x;
> +		s->y = c[i].y;
> +
> +		if (!s->active) {
> +			s->active = true;
> +			s->reported = false;
> +			s->frames = 0;
> +		}
> +		if (!s->reported) {
> +			s->frames++;
> +			if (!c[i].pen || s->frames >= p->pen_frames) {
> +				s->pen = c[i].pen;
> +				s->reported = 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] = 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] == 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/touchscreen/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 = ts->page;
> +	unsigned int len = ts->frame_words, off = 0;
> +	u16 base = 0;
> +	int error;
> +
> +	while (off < len) {
> +		unsigned int n = min(len - off, MAX11936_PAGE_WORDS);
> +
> +		error = max11936_read(ts, REG_MAILBOX, page, n + 4);
> +		if (error)
> +			return error;
> +
> +		if (page[3] == 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] != PAGE_DATA) {
> +			max11936_write_reg(ts, REG_LEGACY_MODE, 1);
> +			return -EAGAIN;
> +		}
> +		if (!off && (page[1] == ts->data->buf0 || page[1] == ts->data->buf1))
> +			base = page[1];
> +		if (page[1] != base + off) {
> +			max11936_write_reg(ts, REG_LEGACY_MODE, 1);
> +			return -EAGAIN;
> +		}

[Severity: Low]
Does page[1] == 0 on the first page bypass the buffer address check here?
Because base is initialized to 0, page[1] == 0 at off == 0 satisfies
page[1] == base + off even though it matches neither buf0 nor buf1.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129-upstream-touch-max11936-v1-0-6f98b121b56b@tsv-stahl-riesa.de?part=2

      reply	other threads:[~2026-11-29 19:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 18:54 [PATCH RFC 0/2] Input: Maxim MAX11936 touchscreen (NVIDIA Tegra Note 7) Patrick Fischer via B4 Relay
2026-11-29 18:54 ` [PATCH RFC 1/2] dt-bindings: input: touchscreen: Add Maxim MAX11936 Patrick Fischer via B4 Relay
2026-11-29 18:54 ` [PATCH RFC 2/2] Input: add Maxim MAX11936 touchscreen driver Patrick Fischer via B4 Relay
2026-11-29 19:07   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-239936@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=admin@tsv-stahl-riesa.de \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox