Linux Input/HID development
 help / color / mirror / Atom feed
From: Ranjan Kumar <kumarranja@chromium.org>
To: dmitry.torokhov@gmail.com
Cc: bleung@chromium.org, dusonlin@emc.com.tw, bentiss@kernel.org,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ranjan Kumar <kumarranja@chromium.org>
Subject: [PATCH] Input: elan_i2c - prevent division by zero on invalid device parameters
Date: Wed, 13 May 2026 07:39:08 +0000	[thread overview]
Message-ID: <20260513073908.3326178-1-kumarranja@chromium.org> (raw)

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 values are detected, log an
error and return -EINVAL to gracefully abort the initialization and
maintain system stability.

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>
---
 drivers/input/mouse/elan_i2c_core.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/input/mouse/elan_i2c_core.c b/drivers/input/mouse/elan_i2c_core.c
index fee1796da3d0..b5fd63928afd 100644
--- a/drivers/input/mouse/elan_i2c_core.c
+++ b/drivers/input/mouse/elan_i2c_core.c
@@ -425,6 +425,14 @@ static int elan_query_device_parameters(struct elan_tp_data *data)
 		if (error)
 			return error;
 	}
+
+	if (unlikely(x_traces == 0 || y_traces == 0)) {
+		dev_err(&client->dev,
+			"Invalid trace numbers: x=%u, y=%u\n",
+			x_traces, y_traces);
+		return -EINVAL;
+	}
+
 	data->width_x = data->max_x / x_traces;
 	data->width_y = data->max_y / y_traces;
 
@@ -440,6 +448,14 @@ static int elan_query_device_parameters(struct elan_tp_data *data)
 		data->x_res = elan_convert_resolution(hw_x_res, data->pattern);
 		data->y_res = elan_convert_resolution(hw_y_res, data->pattern);
 	} else {
+
+		if (unlikely(x_mm == 0 || y_mm == 0)) {
+			dev_err(&client->dev,
+				"Invalid physical dimensions: x_mm=%u, y_mm=%u\n",
+				x_mm, y_mm);
+			return -EINVAL;
+		}
+
 		data->x_res = (data->max_x + 1) / x_mm;
 		data->y_res = (data->max_y + 1) / y_mm;
 	}
-- 
2.54.0.563.g4f69b47b94-goog


             reply	other threads:[~2026-05-13  7:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-13  7:39 Ranjan Kumar [this message]
2026-05-13 21:00 ` [PATCH] Input: elan_i2c - prevent division by zero on invalid device parameters Dmitry Torokhov
2026-05-15  6:52   ` [PATCH v2] " Ranjan Kumar
2026-05-15  7:10     ` 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=20260513073908.3326178-1-kumarranja@chromium.org \
    --to=kumarranja@chromium.org \
    --cc=bentiss@kernel.org \
    --cc=bleung@chromium.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=dusonlin@emc.com.tw \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox