Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jun Yan" <jerrysteve1101@gmail.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org,
	dmitry.torokhov@gmail.com, linux-input@vger.kernel.org,
	robh@kernel.org
Subject: Re: [PATCH v4 07/10] Input: cap11xx - refactor code for better CAP1114 support.
Date: Wed, 17 Jun 2026 20:57:48 +0000	[thread overview]
Message-ID: <20260617205748.7EB501F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260617150318.753148-8-jerrysteve1101@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [High] Bitmask truncation in `cap11xx_led_set` causing silent failure for LEDs >= 8.
- [High] Regmap cache staleness due to missing volatile register definition for the dynamic `sensor_input_reg_base`.

Pre-existing issues:
- [High] Buffer overflow and Fortify Source panic when reading `calib_sensitivities` for devices with more than 8 channels.
--

commit 837f207153012dfc0860b6d46ad5d3ae4f7b3004
Author: Jun Yan <jerrysteve1101@gmail.com>

Extend cap11xx_hw_model structure to support CAP1114

This patch extends the cap11xx_hw_model structure to support CAP1114
with different register offsets and hardware characteristics.

> diff --git a/drivers/input/keyboard/cap11xx.c b/drivers/input/keyboard/cap11xx.c
> index 1db4a9090705..0f19ee036e78 100644
> --- a/drivers/input/keyboard/cap11xx.c
> +++ b/drivers/input/keyboard/cap11xx.c

[ ... ]

> @@ -211,8 +215,8 @@ static int cap11xx_init_keys(struct cap11xx_priv *priv)
>  	}
>  
>  	if (!of_property_read_u32_array(node, "microchip,input-threshold",
> -					priv->thresholds, priv->model->num_channels)) {
> +					priv->thresholds, priv->model->num_sensor_thresholds)) {
> -		for (i = 0; i < priv->model->num_channels; i++) {
> +		for (i = 0; i < priv->model->num_sensor_thresholds; i++) {
>  			if (priv->thresholds[i] > 127) {
>  				dev_err(dev, "Invalid input-threshold value %u\n",
>  					priv->thresholds[i]);

[Severity: High]
This is a pre-existing issue, but looking at cap11xx_init_keys(), could
reading "microchip,calib-sensitivity" overflow the calib_sensitivities array
for devices with more than 8 channels?

In cap11xx_init_keys():

    } else if (!of_property_read_u32_array(node, "microchip,calib-sensitivity",
                                           priv->calib_sensitivities,
                                           priv->model->num_channels)) {

The calib_sensitivities array is statically allocated to 8 elements in
struct cap11xx_priv. For models with more than 8 channels (like the CAP1114
which has 14), could this cause a buffer overflow into the keycodes array
and trigger a kernel panic if FORTIFY_SOURCE is enabled?

[ ... ]

> @@ -308,7 +314,7 @@ static irqreturn_t cap11xx_thread_func(int irq_num, void *data)
>  	if (ret < 0)
>  		goto out;
>  
> -	ret = regmap_read(priv->regmap, CAP11XX_REG_SENSOR_INPUT, &status);
> +	ret = regmap_read(priv->regmap, priv->model->sensor_input_reg_base, &status);
>  	if (ret < 0)
>  		goto out;

[Severity: High]
Will this result in reading stale cached values instead of the actual
hardware state?

The interrupt handler now dynamically reads from sensor_input_reg_base.
However, cap11xx_volatile_reg() still hardcodes CAP11XX_REG_SENSOR_INPUT as
a volatile register.

Since the new dynamic base register (and the subsequent register for devices
with more than 8 channels) is no longer marked volatile, will the regmap
cache return stale data and break input events for these models?

[ ... ]

> @@ -362,7 +368,7 @@ static int cap11xx_led_set(struct led_classdev *cdev,
>  	 * 0 (OFF) and 1 (ON).
>  	 */
>  	return regmap_update_bits(priv->regmap,
> -				  CAP11XX_REG_LED_OUTPUT_CONTROL,
> +				  priv->model->led_output_control_reg_base,
>  				  BIT(led->reg),
>  				  value ? BIT(led->reg) : 0);
>  }

[Severity: High]
Will this bitmask be truncated for LEDs with an index of 8 or higher?

The bitmask passed to regmap_update_bits() is BIT(led->reg). Since models
like CAP1114 support more than 8 LEDs, and the register operations are 8-bit,
BIT(led->reg) will exceed 8 bits for higher-index LEDs.

The initialization code in cap11xx_init_leds() caps the LED clearance mask to
8 bits:

    GENMASK(min(num_leds, 8) - 1, 0)

Does cap11xx_led_set() also need an update to handle devices with more than
8 LEDs to avoid silently failing?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260617150318.753148-1-jerrysteve1101@gmail.com?part=7

  reply	other threads:[~2026-06-17 20:57 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-17 15:02 [PATCH v4 00/10] Input: cap11xx - Add support for CAP1114 Jun Yan
2026-06-17 15:02 ` [PATCH v4 01/10] Input: cap11xx - clean up duplicate log and add probe error logs Jun Yan
2026-06-17 15:02 ` [PATCH v4 02/10] Input: cap11xx - remove unused register macros Jun Yan
2026-06-17 20:21   ` sashiko-bot
2026-06-17 15:02 ` [PATCH v4 03/10] dt-bindings: input: microchip,cap11xx: Update datasheet URL and LED reg range Jun Yan
2026-06-17 20:31   ` sashiko-bot
2026-06-17 15:02 ` [PATCH v4 04/10] dt-bindings: input: microchip,cap11xx: Add microchip,cap1126 LED reg constraints Jun Yan
2026-06-17 15:02 ` [PATCH v4 05/10] dt-bindings: input: microchip,cap11xx: Add reset-gpios property Jun Yan
2026-06-17 15:02 ` [PATCH v4 06/10] Input: cap11xx - add reset gpio support Jun Yan
2026-06-17 15:02 ` [PATCH v4 07/10] Input: cap11xx - refactor code for better CAP1114 support Jun Yan
2026-06-17 20:57   ` sashiko-bot [this message]
2026-06-17 15:02 ` [PATCH v4 08/10] Input: cap11xx - guard unsupported DT properties before parsing Jun Yan
2026-06-17 15:02 ` [PATCH v4 09/10] dt-bindings: input: microchip,cap11xx: Add CAP1114 support Jun Yan
2026-06-17 21:15   ` sashiko-bot
2026-06-17 15:02 ` [PATCH v4 10/10] Input: cap11xx - add support for CAP1114 Jun Yan
2026-06-17 21:25   ` sashiko-bot

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=20260617205748.7EB501F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jerrysteve1101@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