Skip to content

Commit

Permalink
HID: multitouch: prevent memleak with the allocated name
Browse files Browse the repository at this point in the history
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 49a5a82 ("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>
  • Loading branch information
Benjamin Tissoires authored and Jiri Kosina committed Jun 12, 2013
1 parent 1deb9d3 commit 5939212
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions drivers/hid/hid-multitouch.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,12 @@ static struct mt_class mt_classes[] = {
static void mt_free_input_name(struct hid_input *hi)
{
struct hid_device *hdev = hi->report->device;
const char *name = hi->input->name;

if (hi->input->name != hdev->name)
kfree(hi->input->name);
if (name != hdev->name) {
hi->input->name = hdev->name;
kfree(name);
}
}

static ssize_t mt_show_quirks(struct device *dev,
Expand Down Expand Up @@ -1040,11 +1043,11 @@ static void mt_remove(struct hid_device *hdev)
struct hid_input *hi;

sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
hid_hw_stop(hdev);

list_for_each_entry(hi, &hdev->inputs, list)
mt_free_input_name(hi);

hid_hw_stop(hdev);

kfree(td);
hid_set_drvdata(hdev, NULL);
}
Expand Down

0 comments on commit 5939212

Please sign in to comment.