Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Michał Kopeć" <michal@nozomi.space>
Cc: dmitry.torokhov@gmail.com, conor+dt@kernel.org, robh@kernel.org,
	linux-input@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v5 5/6] HID: himax: Report the touch and heatmap data
Date: Sat, 03 Oct 2026 17:56:13 +0000	[thread overview]
Message-ID: <20261003175613.CE88F1F0089C@smtp.kernel.org> (raw)
In-Reply-To: <20261003142741.48634-6-michal@nozomi.space>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Heap buffer overflow in heatmap decompression due to integer truncation
- [High] Null pointer dereference in himax_decompress_heatmap due to concurrent IRQ execution
--

commit c3f3c5296c4dbb7b96df08e22f2c194d4ef65577
Author: Michał Kopeć <michal@nozomi.space>

HID: himax: Report the touch and heatmap data

This commit adds reporting of heatmap data for the HX83102J firmware.
It extracts the heatmap following the stylus report and decompresses
it from 12-bit to 16-bit values.

Link: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/5326106

> diff --git a/drivers/hid/hid-himax.c b/drivers/hid/hid-himax.c
> index 533d7be629147..40abae724743d 100644
> --- a/drivers/hid/hid-himax.c
> +++ b/drivers/hid/hid-himax.c
> @@ -2150,6 +2150,37 @@ static void himax_hid_remove(struct himax_ts_data *ts)
>  	ts->hid = NULL;
>  }
>  
> +/**
> + * himax_decompress_heatmap() - Unpack the heatmap into its HID report
> + * @ts: Himax touch screen data
> + * @src: Heatmap as read from the event stack
> + *
> + * The IC packs two 12-bit heatmap values into three bytes, while the HID
> + * report descriptor of the firmware declares 16-bit values. Copy the report
> + * ID and heatmap info header, then widen every pair of values to the
> + * little-endian 16-bit layout of the report.
> + *
> + * Return: None
> + */
> +static void himax_decompress_heatmap(struct himax_ts_data *ts, const u8 *src)
> +{
> +	u32 i;
> +	u32 count = ts->ic_data.rx_num * ts->ic_data.tx_num;
> +	const u32 header_size = HIMAX_HEAT_MAP_INFO_SZ + 1;
> +	u8 *dst = ts->heatmap_buf;
> +
> +	memcpy(dst, src, header_size);

[Severity: High]
Does this code dereference a NULL pointer if the IRQ fires concurrently?

If an interrupt fires early, himax_ts_thread() executes himax_ts_operation()
which locklessly checks ts->hid_probed.

If another thread running himax_initial_work() sets ts->hid_probed = true via
himax_hid_register(), but hasn't yet allocated ts->heatmap_buf in
himax_hid_report_data_init(), won't dst be NULL here when memcpy() is called?

> +	for (i = 0; i < count; i += 2) {
> +		const u8 *packed = src + header_size + i * 3 / 2;
> +		u8 *unpacked = dst + header_size + i * 2;
> +
> +		unpacked[0] = packed[0];
> +		unpacked[1] = packed[2] >> 4;
> +		unpacked[2] = packed[1];
> +		unpacked[3] = packed[2] & 0x0f;
> +	}
> +}

[Severity: High]
Can this loop read and write past the end of the allocated buffers if count
is an odd number?

Since count is the product of rx_num and tx_num read dynamically from the
device, it might be odd. The loop processes elements in pairs (i += 2).

During the final iteration with an odd count, won't this write 4 bytes to
unpacked and read 3 bytes from packed, exceeding the bounds of both buffers?

[ ... ]

> @@ -2322,6 +2362,9 @@ static int himax_hid_report_data_init(struct himax_ts_data *ts)
>  	ts->touch_data_sz = ts->hid_desc.max_input_length;
>  	if (ts->ic_data.stylus_function)
>  		ts->touch_data_sz += ts->hid_desc.max_input_length;
> +	ts->heatmap_data_size = ts->ic_data.rx_num * ts->ic_data.tx_num * 3 / 2;

[Severity: High]
Does this calculation truncate the required size if the product of rx_num and
tx_num is odd?

If the count is odd, this division by 2 truncates the result, potentially
leading to an undersized allocation for xfer_buf that doesn't account for the
full packed heatmap size.

> +	ts->touch_data_sz += HIMAX_HEAT_MAP_HEADER_SZ +
> +			     HIMAX_HEAT_MAP_INFO_SZ + ts->heatmap_data_size;
>  	if (ts->touch_data_sz != ts->xfer_buf_sz) {
>  		kfree(ts->xfer_buf);
>  		ts->xfer_buf_sz = 0;
> @@ -2331,6 +2374,14 @@ static int himax_hid_report_data_init(struct himax_ts_data *ts)
>  		ts->xfer_buf_sz = ts->touch_data_sz;
>  	}
>  
> +	if (!ts->heatmap_buf) {
> +		ts->heatmap_buf = devm_kzalloc(ts->dev,
> +					       ts->ic_data.rx_num * ts->ic_data.tx_num * 2 +
> +					       HIMAX_HEAT_MAP_INFO_SZ + 1, GFP_KERNEL);

[Severity: High]
Does this allocation fail to account for the loop's 2-element processing
chunk size?

If the count is odd, the destination buffer is sized exactly for the odd count.
Since the decompression loop in himax_decompress_heatmap() processes elements
in pairs, won't it write past the end of this allocated buffer?

> +		if (!ts->heatmap_buf)
> +			return -ENOMEM;
> +	}
> +
>  	return 0;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261003142741.48634-1-michal@nozomi.space?part=5

  reply	other threads:[~2026-10-03 17:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-03 14:27 [PATCH v5 0/6] HID: Add support for the Himax HX83102J touchscreen Michał Kopeć
2026-10-03 14:27 ` [PATCH v5 1/6] dt-bindings: input: Add " Michał Kopeć
2026-10-03 17:56   ` sashiko-bot
2026-10-04  7:45   ` Krzysztof Kozlowski
2026-10-03 14:27 ` [PATCH v5 2/6] HID: Add Himax HX83102J touchscreen driver Michał Kopeć
2026-10-03 17:56   ` sashiko-bot
2026-10-04  7:50   ` Krzysztof Kozlowski
2026-10-03 14:27 ` [PATCH v5 3/6] HID: himax: Add DRM panel follower support Michał Kopeć
2026-10-03 17:56   ` sashiko-bot
2026-10-04  7:52   ` Krzysztof Kozlowski
2026-10-03 14:27 ` [PATCH v5 4/6] HID: himax: Load the firmware from a file Michał Kopeć
2026-10-03 17:56   ` sashiko-bot
2026-10-03 14:27 ` [PATCH v5 5/6] HID: himax: Report the touch and heatmap data Michał Kopeć
2026-10-03 17:56   ` sashiko-bot [this message]
2026-10-03 14:27 ` [PATCH v5 6/6] arm64: dts: mediatek: mt8188-geralt-ciri: Add the touchscreen Michał Kopeć

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=20261003175613.CE88F1F0089C@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=michal@nozomi.space \
    --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