Skip to content

Commit

Permalink
Input: zinitix - Don't fail if linux,keycodes prop is absent
Browse files Browse the repository at this point in the history
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 <[email protected]>
Fixes: 075d9b2 ("Input: zinitix - add touchkey support")
Signed-off-by: Nikita Travkin <[email protected]>
  • Loading branch information
TravMurav committed Oct 1, 2024
1 parent 193a0a7 commit f5ce532
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions drivers/input/touchscreen/zinitix.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,19 +576,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 (bt541->num_keycodes < 0) {
dev_err(&client->dev, "Failed to count \"linux,keycodes\" property: %d\n", bt541->num_keycodes);
return bt541->num_keycodes;
} 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);
Expand Down

0 comments on commit f5ce532

Please sign in to comment.