Input: zinitix - don't fail if linux,keycodes prop is absent

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>

authored by Nikita Travkin and committed by Dmitry Torokhov 2de01e0e 22a18935

+22 -12
+22 -12
drivers/input/touchscreen/zinitix.c
··· 645 645 return error; 646 646 } 647 647 648 - bt541->num_keycodes = device_property_count_u32(&client->dev, "linux,keycodes"); 649 - if (bt541->num_keycodes > ARRAY_SIZE(bt541->keycodes)) { 650 - dev_err(&client->dev, "too many keys defined (%d)\n", bt541->num_keycodes); 651 - return -EINVAL; 652 - } 648 + if (device_property_present(&client->dev, "linux,keycodes")) { 649 + bt541->num_keycodes = device_property_count_u32(&client->dev, 650 + "linux,keycodes"); 651 + if (bt541->num_keycodes < 0) { 652 + dev_err(&client->dev, "Failed to count keys (%d)\n", 653 + bt541->num_keycodes); 654 + return bt541->num_keycodes; 655 + } else if (bt541->num_keycodes > ARRAY_SIZE(bt541->keycodes)) { 656 + dev_err(&client->dev, "Too many keys defined (%d)\n", 657 + bt541->num_keycodes); 658 + return -EINVAL; 659 + } 653 660 654 - error = device_property_read_u32_array(&client->dev, "linux,keycodes", 655 - bt541->keycodes, 656 - bt541->num_keycodes); 657 - if (error) { 658 - dev_err(&client->dev, 659 - "Unable to parse \"linux,keycodes\" property: %d\n", error); 660 - return error; 661 + error = device_property_read_u32_array(&client->dev, 662 + "linux,keycodes", 663 + bt541->keycodes, 664 + bt541->num_keycodes); 665 + if (error) { 666 + dev_err(&client->dev, 667 + "Unable to parse \"linux,keycodes\" property: %d\n", 668 + error); 669 + return error; 670 + } 661 671 } 662 672 663 673 error = zinitix_init_input_dev(bt541);