Skip to content

Commit 2a5e597

Browse files
jigpuJiri Kosina
authored andcommitted
HID: wacom: Always increment hdev refcount within wacom_get_hdev_data
The wacom_get_hdev_data function is used to find and return a reference to the "other half" of a Wacom device (i.e., the touch device associated with a pen, or vice-versa). To ensure these references are properly accounted for, the function is supposed to automatically increment the refcount before returning. This was not done, however, for devices which have pen & touch on different interfaces of the same USB device. This can lead to a WARNING ("refcount_t: underflow; use-after-free") when removing the module or device as we call kref_put() more times than kref_get(). Triggering an "actual" use- after-free would be difficult since both devices will disappear nearly- simultaneously. To silence this warning and prevent the potential error, we need to increment the refcount for all cases within wacom_get_hdev_data. Fixes: 41372d5 ("HID: wacom: Augment 'oVid' and 'oPid' with heuristics for HID_GENERIC") Cc: <stable@vger.kernel.org> # v4.9+ Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com> Reviewed-by: Ping Cheng <ping.cheng@wacom.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent 92380b5 commit 2a5e597

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

drivers/hid/wacom_sys.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,10 @@ static struct wacom_hdev_data *wacom_get_hdev_data(struct hid_device *hdev)
668668

669669
/* Try to find an already-probed interface from the same device */
670670
list_for_each_entry(data, &wacom_udev_list, list) {
671-
if (compare_device_paths(hdev, data->dev, '/'))
671+
if (compare_device_paths(hdev, data->dev, '/')) {
672+
kref_get(&data->kref);
672673
return data;
674+
}
673675
}
674676

675677
/* Fallback to finding devices that appear to be "siblings" */

0 commit comments

Comments
 (0)