提交 a1091118 编写于 作者: C Claudia Pellegrino 提交者: Jiri Kosina

HID: magicmouse: prevent division by 0 on scroll

In hid_magicmouse, if the user has set scroll_speed to a value between
55 and 63 and scrolls seven times in quick succession, the
step_hr variable in the magicmouse_emit_touch function becomes 0.

That causes a division by zero further down in the function when
it does `step_x_hr /= step_hr`.

To reproduce, create `/etc/modprobe.d/hid_magicmouse.conf` with the
following content:

```
options hid_magicmouse scroll_acceleration=1 scroll_speed=55
```

Then reboot, connect a Magic Mouse and scroll seven times quickly.
The system will freeze for a minute, and after that `dmesg` will
confirm that a division by zero occurred.

Enforce a minimum of 1 for the variable so the high resolution
step count can never reach 0 even at maximum scroll acceleration.

Fixes: d4b9f10a ("HID: magicmouse: enable high-resolution scroll")
Signed-off-by: NClaudia Pellegrino <linux@cpellegrino.de>
Tested-by: NJosé Expósito <jose.exposito89@gmail.com>
Signed-off-by: NJiri Kosina <jkosina@suse.cz>
上级 fa48020c
...@@ -256,8 +256,11 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda ...@@ -256,8 +256,11 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
unsigned long now = jiffies; unsigned long now = jiffies;
int step_x = msc->touches[id].scroll_x - x; int step_x = msc->touches[id].scroll_x - x;
int step_y = msc->touches[id].scroll_y - y; int step_y = msc->touches[id].scroll_y - y;
int step_hr = ((64 - (int)scroll_speed) * msc->scroll_accel) / int step_hr =
SCROLL_HR_STEPS; max_t(int,
((64 - (int)scroll_speed) * msc->scroll_accel) /
SCROLL_HR_STEPS,
1);
int step_x_hr = msc->touches[id].scroll_x_hr - x; int step_x_hr = msc->touches[id].scroll_x_hr - x;
int step_y_hr = msc->touches[id].scroll_y_hr - y; int step_y_hr = msc->touches[id].scroll_y_hr - y;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册