Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

HID: multitouch: prevent memleak with the allocated name

mt_free_input_name() was never called during .remove():
hid_hw_stop() removes the hid_input items in hdev->inputs, and so the
list is therefore empty after the call. In the end, we never free the
special names that has been allocated during .probe().

Restore the original name before freeing it to avoid acessing already
freed pointer.

This fixes a regression introduced by 49a5a827a ("HID: multitouch: append " Pen" to
the name of the stylus input")

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>

authored by

Benjamin Tissoires and committed by
Jiri Kosina
5939212d 1deb9d34

+7 -4
+7 -4
drivers/hid/hid-multitouch.c
··· 264 264 static void mt_free_input_name(struct hid_input *hi) 265 265 { 266 266 struct hid_device *hdev = hi->report->device; 267 + const char *name = hi->input->name; 267 268 268 - if (hi->input->name != hdev->name) 269 - kfree(hi->input->name); 269 + if (name != hdev->name) { 270 + hi->input->name = hdev->name; 271 + kfree(name); 272 + } 270 273 } 271 274 272 275 static ssize_t mt_show_quirks(struct device *dev, ··· 1043 1040 struct hid_input *hi; 1044 1041 1045 1042 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group); 1046 - hid_hw_stop(hdev); 1047 - 1048 1043 list_for_each_entry(hi, &hdev->inputs, list) 1049 1044 mt_free_input_name(hi); 1045 + 1046 + hid_hw_stop(hdev); 1050 1047 1051 1048 kfree(td); 1052 1049 hid_set_drvdata(hdev, NULL);