All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Input: rotary_encoder - default steps to 24 to avoid divide by zero
@ 2026-12-05 11:28 Shirong Zhao
  2026-12-06  4:36 ` Dmitry Torokhov
  2026-12-06  4:43 ` [PATCH v2] Input: rotary-encoder - honour the documented default step count Shirong Zhao
  0 siblings, 2 replies; 3+ messages in thread
From: Shirong Zhao @ 2026-12-05 11:28 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, stable, Shirong Zhao

The driver reads the device-tree property "rotary-encoder,steps" but
ignores the return value and applies no default.  If the property is
absent (or explicitly 0), steps stays 0 after the kzalloc'd structure is
filled, and the IRQ handler does

	if (encoder->rollover)
		pos %= encoder->steps;

i.e. a modulo by zero when "rotary-encoder,rollover" is set.  The binding
documented a default of 24; honour it and also treat a failing read as
using the default.

Fixes: 80c99bcd2861 ("Input: rotary-encoder - add DT bindings")
Cc: stable@vger.kernel.org
Signed-off-by: Shirong Zhao <shxzhaosr@163.com>
---
 drivers/input/misc/rotary_encoder.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c
index 6c932e4..440ac27 100644
--- a/drivers/input/misc/rotary_encoder.c
+++ b/drivers/input/misc/rotary_encoder.c
@@ -30,6 +30,8 @@ enum rotary_encoder_encoding {
 	ROTENC_BINARY,
 };
 
+#define ROTARY_ENCODER_DEFAULT_STEPS	24
+
 struct rotary_encoder {
 	struct input_dev *input;
 
@@ -191,7 +193,9 @@ static int rotary_encoder_probe(struct platform_device *pdev)
 
 	mutex_init(&encoder->access_mutex);
 
-	device_property_read_u32(dev, "rotary-encoder,steps", &encoder->steps);
+	if (device_property_read_u32(dev, "rotary-encoder,steps",
+				     &encoder->steps) || !encoder->steps)
+		encoder->steps = ROTARY_ENCODER_DEFAULT_STEPS;
 
 	err = device_property_read_u32(dev, "rotary-encoder,steps-per-period",
 				       &steps_per_period);
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-06  4:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 11:28 [PATCH] Input: rotary_encoder - default steps to 24 to avoid divide by zero Shirong Zhao
2026-12-06  4:36 ` Dmitry Torokhov
2026-12-06  4:43 ` [PATCH v2] Input: rotary-encoder - honour the documented default step count Shirong Zhao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.