[PATCH 04/11] Input: iqs7222 - protect against undefined slider size

Jeff LaBundy
2022-09-08T13:17:13Z

Select variants of silicon do not define a default slider size, in
which case the size must be specified in the device tree. If it is
not, the axis's maximum value is reported as 65535 due to unsigned
integer overflow.

To solve this problem, move the existing zero-check outside of the
conditional block that checks whether the property is present.

Fixes: e505edaedcb9 ("Input: add support for Azoteq IQS7222A/B/C")
Signed-off-by: Jeff LaBundy <jeff@labundy.com>
---
drivers/input/misc/iqs7222.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/input/misc/iqs7222.c b/drivers/input/misc/iqs7222.c
index fdade24caa8a..ba12c49e972c 100644
--- a/drivers/input/misc/iqs7222.c
+++ b/drivers/input/misc/iqs7222.c
@@ -2126,7 +2126,7 @@ static int iqs7222_parse_sldr(struct iqs7222_private *iqs7222, int sldr_index)
goto put_sldr_node;
}

- if (!val || val > dev_desc->sldr_res) {
+ if (val > dev_desc->sldr_res) {
dev_err(&client->dev, "Invalid %s size: %u\n",
fwnode_get_name(sldr_node), val);
error = -EINVAL;
@@ -2142,6 +2142,14 @@ static int iqs7222_parse_sldr(struct iqs7222_private *iqs7222, int sldr_index)
}
}

+ if (!(reg_offset ? sldr_setup[3]
+ : sldr_setup[2] & IQS7222_SLDR_SETUP_2_RES_MASK)) {
+ dev_err(&client->dev, "Undefined %s size\n",
+ fwnode_get_name(sldr_node));
+ error = -EINVAL;
+ goto put_sldr_node;
+ }
+
if (fwnode_property_present(sldr_node, "azoteq,top-speed")) {
error = fwnode_property_read_u32(sldr_node,
"azoteq,top-speed", &val);
--
2.25.1