HID: wacom: generic: Treat serial number and related fields as unsigned
authorJason Gerecke <killertofu@gmail.com>
Wed, 6 Nov 2019 19:59:46 +0000 (11:59 -0800)
committerJiri Kosina <jkosina@suse.cz>
Wed, 6 Nov 2019 20:37:29 +0000 (21:37 +0100)
commitff479731c3859609530416a18ddb3db5db019b66
tree4a09d3a6037b7085058506029ceb1ed7beb2aac9
parent43b7029f475e7497da1de1f4a1742241812bf266
HID: wacom: generic: Treat serial number and related fields as unsigned

The HID descriptors for most Wacom devices oddly declare the serial
number and other related fields as signed integers. When these numbers
are ingested by the HID subsystem, they are automatically sign-extended
into 32-bit integers. We treat the fields as unsigned elsewhere in the
kernel and userspace, however, so this sign-extension causes problems.
In particular, the sign-extended tool ID sent to userspace as ABS_MISC
does not properly match unsigned IDs used by xf86-input-wacom and libwacom.

We introduce a function 'wacom_s32tou' that can undo the automatic sign
extension performed by 'hid_snto32'. We call this function when processing
the serial number and related fields to ensure that we are dealing with
and reporting the unsigned form. We opt to use this method rather than
adding a descriptor fixup in 'wacom_hid_usage_quirk' since it should be
more robust in the face of future devices.

Ref: https://github.com/linuxwacom/input-wacom/issues/134
Fixes: f85c9dc678 ("HID: wacom: generic: Support tool ID and additional tool types")
CC: <stable@vger.kernel.org> # v4.10+
Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
Reviewed-by: Aaron Armstrong Skomra <aaron.skomra@wacom.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/wacom.h
drivers/hid/wacom_wac.c