From: Dinghao Liu Date: Mon, 31 Aug 2020 09:06:43 +0000 (+0800) Subject: HID: elan: Fix memleak in elan_input_configured X-Git-Tag: v5.15~2663^2~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b7429ea53d6c0936a0f10a5d64164f0aea440143;p=platform%2Fkernel%2Flinux-starfive.git HID: elan: Fix memleak in elan_input_configured 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 Signed-off-by: Jiri Kosina --- diff --git a/drivers/hid/hid-elan.c b/drivers/hid/hid-elan.c index 45c4f88..dae1937 100644 --- a/drivers/hid/hid-elan.c +++ b/drivers/hid/hid-elan.c @@ -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; } @@ -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; }