input: misc: max7360-rotary: reject zero steps to avoid divide by zero
Subsystems (4)
PATCH 1/1 input: misc: max7360-rotary: reject zero steps to avoid divide by zero
max7360_rotary->steps is only defaulted when reading the device-tree property "rotary-encoder,steps" fails. An explicit DT value of 0 makes the read succeed while leaving steps 0, and the event handler then does
pos += steps % maxval; // maxval == steps == 0 pos = (pos + maxval) % maxval;
i.e. a modulo by zero. Treat a zero result like a failed read and fall back to the default.
Fixes 229c15e9a69c ("input: misc: Add support for MAX7360 rotary")
Signed-off-by Shirong Zhao <[email protected]>
--- drivers/input/misc/max7360-rotary.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/misc/max7360-rotary.c +1 -1
@@ -127,7 +127,7 @@ static int max7360_rotary_probe(struct platform_device *pdev) error =device_property_read_u32 (dev->parent,"rotary-encoder,steps" , &max7360_rotary->steps); -if (error) +if (error || !max7360_rotary->steps) max7360_rotary->steps =MAX7360_ROTARY_DEFAULT_STEPS ; device_property_read_u32(dev->parent, "rotary-debounce-delay-ms",
Signature · 1 line
2.53.0