linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [v2] HID: elan: Fix memleak in elan_input_configured
@ 2020-08-31  9:06 Dinghao Liu
  2020-09-01  7:13 ` Jiri Kosina
  0 siblings, 1 reply; 2+ messages in thread
From: Dinghao Liu @ 2020-08-31  9:06 UTC (permalink / raw)
  To: dinghao.liu, kjlu
  Cc: Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel

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>
---

Changelog:

v2: - Add input_mt_destroy_slots() on failure of
      input_register_device().
---
 drivers/hid/hid-elan.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/hid/hid-elan.c b/drivers/hid/hid-elan.c
index 45c4f888b7c4..dae193749d44 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;
 	}
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] [v2] HID: elan: Fix memleak in elan_input_configured
  2020-08-31  9:06 [PATCH] [v2] HID: elan: Fix memleak in elan_input_configured Dinghao Liu
@ 2020-09-01  7:13 ` Jiri Kosina
  0 siblings, 0 replies; 2+ messages in thread
From: Jiri Kosina @ 2020-09-01  7:13 UTC (permalink / raw)
  To: Dinghao Liu; +Cc: kjlu, Benjamin Tissoires, linux-input, linux-kernel

On Mon, 31 Aug 2020, Dinghao Liu wrote:

> 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>
> ---
> 
> Changelog:
> 
> v2: - Add input_mt_destroy_slots() on failure of
>       input_register_device().

Thanks, applied.

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-09-01  7:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-31  9:06 [PATCH] [v2] HID: elan: Fix memleak in elan_input_configured Dinghao Liu
2020-09-01  7:13 ` Jiri Kosina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).