linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Input: zinitix - Don't fail if linux,keycodes prop is absent
@ 2024-10-02 13:01 Nikita Travkin
  2024-10-02 14:11 ` Linus Walleij
  2024-10-03 11:43 ` Dmitry Torokhov
  0 siblings, 2 replies; 7+ messages in thread
From: Nikita Travkin @ 2024-10-02 13:01 UTC (permalink / raw)
  To: Dmitry Torokhov, Linus Walleij
  Cc: linux-input, linux-kernel, Jakob Hauser, Nikita Travkin

When initially adding the touchkey support, a mistake was made in the
property parsing code. The possible negative errno from
device_property_count_u32() was never checked, which was an oversight
left from converting to it from the of_property as part of the review
fixes.

Re-add the correct handling of the absent property, in which case zero
touchkeys should be assumed, which would disable the feature.

Reported-by: Jakob Hauser <jahau@rocketmail.com>
Tested-by: Jakob Hauser <jahau@rocketmail.com>
Fixes: 075d9b22c8fe ("Input: zinitix - add touchkey support")
Signed-off-by: Nikita Travkin <nikita@trvn.ru>
---
 drivers/input/touchscreen/zinitix.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/drivers/input/touchscreen/zinitix.c b/drivers/input/touchscreen/zinitix.c
index 52b3950460e2..1f726653940c 100644
--- a/drivers/input/touchscreen/zinitix.c
+++ b/drivers/input/touchscreen/zinitix.c
@@ -645,19 +645,30 @@ static int zinitix_ts_probe(struct i2c_client *client)
 		return error;
 	}
 
-	bt541->num_keycodes = device_property_count_u32(&client->dev, "linux,keycodes");
-	if (bt541->num_keycodes > ARRAY_SIZE(bt541->keycodes)) {
-		dev_err(&client->dev, "too many keys defined (%d)\n", bt541->num_keycodes);
-		return -EINVAL;
+	error = device_property_count_u32(&client->dev, "linux,keycodes");
+	if (error == -EINVAL || error == -ENODATA) {
+		bt541->num_keycodes = 0;
+	} else if (error < 0) {
+		dev_err(&client->dev, "Failed to count \"linux,keycodes\" property: %d\n", error);
+		return error;
+	} else {
+		bt541->num_keycodes = error;
 	}
 
-	error = device_property_read_u32_array(&client->dev, "linux,keycodes",
-					       bt541->keycodes,
-					       bt541->num_keycodes);
-	if (error) {
-		dev_err(&client->dev,
-			"Unable to parse \"linux,keycodes\" property: %d\n", error);
-		return error;
+	if (bt541->num_keycodes > 0) {
+		if (bt541->num_keycodes > ARRAY_SIZE(bt541->keycodes)) {
+			dev_err(&client->dev, "too many keys defined (%d)\n", bt541->num_keycodes);
+			return -EINVAL;
+		}
+
+		error = device_property_read_u32_array(&client->dev, "linux,keycodes",
+						       bt541->keycodes,
+						       bt541->num_keycodes);
+		if (error) {
+			dev_err(&client->dev,
+				"Unable to parse \"linux,keycodes\" property: %d\n", error);
+			return error;
+		}
 	}
 
 	error = zinitix_init_input_dev(bt541);

---
base-commit: fe21733536749bb1b31c9c84e0b8d2ab8d82ce13
change-id: 20241002-zinitix-no-keycodes-f0fe1bdaccb2

Best regards,
-- 
Nikita Travkin <nikita@trvn.ru>


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-10-03 13:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-02 13:01 [PATCH] Input: zinitix - Don't fail if linux,keycodes prop is absent Nikita Travkin
2024-10-02 14:11 ` Linus Walleij
2024-10-02 14:48   ` Nikita Travkin
2024-10-02 21:20     ` Linus Walleij
2024-10-03 11:43 ` Dmitry Torokhov
2024-10-03 13:08   ` Nikita Travkin
2024-10-03 13:10     ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).