All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Ranjan Kumar <kumarranja@chromium.org>
Cc: bleung@chromium.org, bentiss@kernel.org,
	linux-input@vger.kernel.org,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] Input: elan_i2c - prevent division by zero on invalid device parameters
Date: Mon, 8 Jun 2026 22:18:16 -0700	[thread overview]
Message-ID: <aiefjOflOlbUiWDa@google.com> (raw)
In-Reply-To: <20260518062624.1147959-1-kumarranja@chromium.org>

Hi Ranjan,

On Mon, May 18, 2026 at 06:26:24AM +0000, Ranjan Kumar wrote:
> The Elan I2C touchpad driver queries the device for its physical
> dimensions and trace counts to calculate the device resolution and width.
> However, if the device firmware or device tree provides invalid zero
> values for x_traces, y_traces, x_mm, or y_mm, it results in a fatal
> division-by-zero exception leading to a kernel panic during device probe.
> 
> Add sanity checks to ensure these physical parameters are non-zero
> before performing the division. If invalid trace values are detected,
> log a warning and fall back to ETP_FWIDTH_REDUCE to prevent arithmetic
> underflow during touch reporting.

I would define some defaults that are not necessarily the same as
ETP_FWIDTH_REDUCE. The arithmetic overflow should be handled separately,
as it may still happen if we read (or set up via device tree) some small
(but non-zero) values.

> For invalid physical dimensions, fall
> back to a safe default of 1.
> 
> This prevents the kernel panic while allowing the probe to complete
> successfully. Completing the probe ensures the sysfs nodes are created,
> keeping the firmware update path intact so a recovery firmware can be
> flashed to the device.
> 
> Fixes: 6696777c6506 ("Input: add driver for Elan I2C/SMbus touchpad")
> Fixes: e3a9a1290688 ("Input: elan_i2c - do not query the info if they are provided")
> Signed-off-by: Ranjan Kumar <kumarranja@chromium.org>
> ---
> Changes in v3:
>  - Changed trace fallback values from 1 to ETP_FWIDTH_REDUCE to prevent 
>    an unsigned integer underflow in elan_report_absolute(). 
>  Changes in v2:
>  - Changed error handling from aborting probe with -EINVAL to logging a
>    warning and falling back to default values.
> 
>  drivers/input/mouse/elan_i2c_core.c | 25 +++++++++++++++++++++----
>  1 file changed, 21 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/input/mouse/elan_i2c_core.c b/drivers/input/mouse/elan_i2c_core.c
> index fee1796da3d0..c64e1dd1e60b 100644
> --- a/drivers/input/mouse/elan_i2c_core.c
> +++ b/drivers/input/mouse/elan_i2c_core.c
> @@ -425,8 +425,17 @@ static int elan_query_device_parameters(struct elan_tp_data *data)
>  		if (error)
>  			return error;
>  	}
> -	data->width_x = data->max_x / x_traces;
> -	data->width_y = data->max_y / y_traces;
> +
> +	if (unlikely(x_traces == 0 || y_traces == 0)) {

I'd say "if (!x_traces || !y_traces) ...". This is not hot path so
annotating with unlikely does not buy us anything.

I wonder if we should be comparing with some threshold instead of 0.
Something above 90 I guess.

Thanks.

-- 
Dmitry

      reply	other threads:[~2026-06-09  5:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-13  7:39 [PATCH] Input: elan_i2c - prevent division by zero on invalid device parameters Ranjan Kumar
2026-05-13 21:00 ` Dmitry Torokhov
2026-05-15  6:52   ` [PATCH v2] " Ranjan Kumar
2026-05-15  7:10     ` sashiko-bot
2026-05-18  6:26       ` [PATCH v3] " Ranjan Kumar
2026-06-09  5:18         ` Dmitry Torokhov [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=aiefjOflOlbUiWDa@google.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=bentiss@kernel.org \
    --cc=bleung@chromium.org \
    --cc=kumarranja@chromium.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.