]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
Input: zinitix - don't fail if linux,keycodes prop is absent
authorNikita Travkin <nikita@trvn.ru>
Fri, 4 Oct 2024 16:17:30 +0000 (21:17 +0500)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Fri, 18 Oct 2024 23:03:04 +0000 (16:03 -0700)
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")
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Nikita Travkin <nikita@trvn.ru>
Tested-by: Yassine Oudjana <y.oudjana@protonmail.com>
Link: https://lore.kernel.org/r/20241004-zinitix-no-keycodes-v2-1-876dc9fea4b6@trvn.ru
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/touchscreen/zinitix.c

index 52b3950460e21b74abfe0161e9198dc237271b18..716d6fa60f86440e3d0ee996523fad0dacb14bc8 100644 (file)
@@ -645,19 +645,29 @@ 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;
-       }
+       if (device_property_present(&client->dev, "linux,keycodes")) {
+               bt541->num_keycodes = device_property_count_u32(&client->dev,
+                                                               "linux,keycodes");
+               if (bt541->num_keycodes < 0) {
+                       dev_err(&client->dev, "Failed to count keys (%d)\n",
+                               bt541->num_keycodes);
+                       return bt541->num_keycodes;
+               } else 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 = 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);