Skip to content

Commit

Permalink
HID: elan: Fix memleak in elan_input_configured
Browse files Browse the repository at this point in the history
When input_mt_init_slots() fails, input should be freed
to prevent memleak. When input_register_device() fails,
we should call input_mt_destroy_slots() to free memory
allocated by input_mt_init_slots().

Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
Dinghao Liu authored and Jiri Kosina committed Sep 1, 2020
1 parent 724a419 commit b7429ea
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/hid/hid-elan.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ static int elan_input_configured(struct hid_device *hdev, struct hid_input *hi)
ret = input_mt_init_slots(input, ELAN_MAX_FINGERS, INPUT_MT_POINTER);
if (ret) {
hid_err(hdev, "Failed to init elan MT slots: %d\n", ret);
input_free_device(input);
return ret;
}

Expand All @@ -198,6 +199,7 @@ static int elan_input_configured(struct hid_device *hdev, struct hid_input *hi)
if (ret) {
hid_err(hdev, "Failed to register elan input device: %d\n",
ret);
input_mt_destroy_slots(input);
input_free_device(input);
return ret;
}
Expand Down

0 comments on commit b7429ea

Please sign in to comment.