Skip to content

Commit ccdd699

Browse files
bentissJiri Kosina
authored andcommitted
HID: round return value of hidinput_calc_abs_res
hidinput_calc_abs_res should return the closest int in the division instead of the floor. On a device with a logical_max of 3008 and a physical_max of 255mm, previous implementation gave a resolution of 11 instead of 12. With 11, user-space computes a physical size of 273.5mm and the round_closest results gives 250.6mm. The old implementation introduced an error of 2cm in this example. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com> Acked-by: Jiri Kosina <jkosina@suse.cz> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent 37cf6e6 commit ccdd699

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎drivers/hid/hid-input.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code)
287287
}
288288

289289
/* Calculate resolution */
290-
return logical_extents / physical_extents;
290+
return DIV_ROUND_CLOSEST(logical_extents, physical_extents);
291291
}
292292
EXPORT_SYMBOL_GPL(hidinput_calc_abs_res);
293293

0 commit comments

Comments
 (0)