lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20241217222100.376752-1-Frank.Li@nxp.com>
Date: Tue, 17 Dec 2024 17:20:59 -0500
From: Frank Li <Frank.Li@....com>
To: Dmitry Torokhov <dmitry.torokhov@...il.com>,
	Fugang Duan <B38611@...escale.com>,
	Uwe Kleine-König <u.kleine-koenig@...gutronix.de>,
	Vipul Kumar <vipul_kumar@...tor.com>,
	Luwei Zhou <b45643@...escale.com>,
	linux-input@...r.kernel.org (open list:INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN)...),
	linux-kernel@...r.kernel.org (open list)
Cc: imx@...ts.linux.dev
Subject: [PATCH v3 1/1] input: mma8450: Add chip ID check in probe

From: Luwei Zhou <b45643@...escale.com>

Prevent continuous polling error logs by adding a chip ID check in the
probe  function. This ensures the driver only proceeds when the mma8450 is
present, avoiding issues in scenarios like missing add-on cards.

Signed-off-by: Luwei Zhou <b45643@...escale.com>
Signed-off-by: Fugang Duan <B38611@...escale.com>
Signed-off-by: Vipul Kumar <vipul_kumar@...tor.com>
Signed-off-by: Dong Aisheng <aisheng.dong@....com>
Signed-off-by: Frank Li <Frank.Li@....com>
---
change from v2 to v3
- add if (client_id < 0)
		return dev_err_probe(&c->dev, client_id, "Failed to read chip ID\n");

change from v1 to v2
- Use  *adapter = c->adapter
- Use if (!i2c_check_functionality())
---
 drivers/input/misc/mma8450.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c
index 08412239b8e69..5d1455bffbb05 100644
--- a/drivers/input/misc/mma8450.c
+++ b/drivers/input/misc/mma8450.c
@@ -38,6 +38,8 @@
 
 #define MMA8450_CTRL_REG1	0x38
 #define MMA8450_CTRL_REG2	0x39
+#define MMA8450_ID		0xc6
+#define MMA8450_WHO_AM_I	0x0f
 
 static int mma8450_read(struct i2c_client *c, unsigned int off)
 {
@@ -148,8 +150,19 @@ static void mma8450_close(struct input_dev *input)
  */
 static int mma8450_probe(struct i2c_client *c)
 {
+	struct i2c_adapter *adapter = c->adapter;
 	struct input_dev *input;
-	int err;
+	int err, client_id;
+
+	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA))
+		return dev_err_probe(&c->dev, -EINVAL, "I2C adapter can't support SMBUS BYTE");
+
+	client_id = i2c_smbus_read_byte_data(c, MMA8450_WHO_AM_I);
+	if (client_id < 0)
+		return dev_err_probe(&c->dev, client_id, "Failed to read chip ID\n");
+	if (client_id != MMA8450_ID)
+		return dev_err_probe(&c->dev, -EINVAL, "Read chip ID 0x%x is not equal to 0x%x!\n",
+				     client_id, MMA8450_ID);
 
 	input = devm_input_allocate_device(&c->dev);
 	if (!input)
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ