Thread (9 messages) 9 messages, 3 authors, 2020-09-15

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

From: Sebastian Reichel <hidden>
Date: 2020-09-07 20:41:15
Also in: linux-devicetree, lkml
Subsystem: input (keyboard, mouse, joystick, touchscreen) drivers, the rest · Maintainers: Dmitry Torokhov, Linus Torvalds

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 <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help