* [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
0 siblings, 1 reply; 2+ 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] 2+ messages in thread
* Re: [PATCH] Input: rotary_encoder - default steps to 24 to avoid divide by zero
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
0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Torokhov @ 2026-12-06 4:36 UTC (permalink / raw)
To: Shirong Zhao, Rob Herring; +Cc: linux-input, stable
Hi Shirong,
On Sat, Dec 05, 2026 at 07:28:55PM +0800, Shirong Zhao wrote:
> 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.
I can see using the default if the schema says its an optional property,
but if somebody trues to specify 0 why not reject it?
>
> Fixes: 80c99bcd2861 ("Input: rotary-encoder - add DT bindings")
> Cc: stable@vger.kernel.org
In any case, I do not see the reason for this to be in stable. DT data
it is not an untrusted input.
I really am not sure how much we want to validate in kernel vs relying
on schema validation. Rob, anything from your side?
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-06 4:36 UTC | newest]
Thread overview: 2+ 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox