[PATCHv2 2/4] Input: rotary-encoder - Fix steps property reading

From: Sebastian Reichel
Date: Mon Sep 07 2020 - 16:41:16 EST


The DT binding specifies 24 being used by default, but driver
initializes to 0. The steps variable will be used for a modulo
operation at a later step, so do not allow 0 (does not make
sense in any case).

Signed-off-by: Sebastian Reichel <sebastian.reichel@xxxxxxxxxxxxx>
---
drivers/input/misc/rotary_encoder.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c
index 6d613f2a017c..e9a5dbb10513 100644
--- a/drivers/input/misc/rotary_encoder.c
+++ b/drivers/input/misc/rotary_encoder.c
@@ -198,7 +198,12 @@ static int rotary_encoder_probe(struct platform_device *pdev)

mutex_init(&encoder->access_mutex);

+ encoder->steps = 24;
device_property_read_u32(dev, "rotary-encoder,steps", &encoder->steps);
+ if (!encoder->steps) {
+ dev_err(dev, "invalid steps setting\n");
+ return -EINVAL;
+ }

err = device_property_read_u32(dev, "rotary-encoder,steps-per-period",
&steps_per_period);
--
2.28.0