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

When input_mt_init_slots() fails, input should be
freed to prevent memleak.

Fixes: 9a6a4193d65b8 ("HID: Add driver for USB ELAN Touchpad")
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
 drivers/hid/hid-elan.c | 1 +
 1 file changed, 1 insertion(+)

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


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

* Re: [PATCH] HID: elan: Fix memleak in elan_input_configured
  2020-08-24  7:23 [PATCH] HID: elan: Fix memleak in elan_input_configured Dinghao Liu
@ 2020-08-31  7:48 ` Jiri Kosina
  2020-08-31  7:56   ` dinghao.liu
  0 siblings, 1 reply; 3+ messages in thread
From: Jiri Kosina @ 2020-08-31  7:48 UTC (permalink / raw)
  To: Dinghao Liu
  Cc: kjlu, Benjamin Tissoires, Alexandrov Stansilav, linux-input,
	linux-kernel

On Mon, 24 Aug 2020, Dinghao Liu wrote:

> When input_mt_init_slots() fails, input should be
> freed to prevent memleak.
> 
> Fixes: 9a6a4193d65b8 ("HID: Add driver for USB ELAN Touchpad")
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
>  drivers/hid/hid-elan.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/hid/hid-elan.c b/drivers/hid/hid-elan.c
> index 45c4f888b7c4..858442004258 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;

Good catch, but apparently it's not the only memleak there -- 
input_mt_init_slots() allocates the input_mt slots and friends, so we need 
input_mt_destroy_slots() there as well.

Could you please add this to your patch too, while you are at fixing this 
error codepath anyway, and resubmit?

Thanks!

-- 
Jiri Kosina
SUSE Labs


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

* Re: Re: [PATCH] HID: elan: Fix memleak in elan_input_configured
  2020-08-31  7:48 ` Jiri Kosina
@ 2020-08-31  7:56   ` dinghao.liu
  0 siblings, 0 replies; 3+ messages in thread
From: dinghao.liu @ 2020-08-31  7:56 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: kjlu, Benjamin Tissoires, Alexandrov Stansilav, linux-input,
	linux-kernel

> On Mon, 24 Aug 2020, Dinghao Liu wrote:
> 
> > When input_mt_init_slots() fails, input should be
> > freed to prevent memleak.
> > 
> > Fixes: 9a6a4193d65b8 ("HID: Add driver for USB ELAN Touchpad")
> > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> > ---
> >  drivers/hid/hid-elan.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/drivers/hid/hid-elan.c b/drivers/hid/hid-elan.c
> > index 45c4f888b7c4..858442004258 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;
> 
> Good catch, but apparently it's not the only memleak there -- 
> input_mt_init_slots() allocates the input_mt slots and friends, so we need 
> input_mt_destroy_slots() there as well.
> 
> Could you please add this to your patch too, while you are at fixing this 
> error codepath anyway, and resubmit?
> 

Thank you for your advice! I will fix this and resend the patch soon.

Regards,
Dinghao

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

end of thread, other threads:[~2020-08-31  7:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-24  7:23 [PATCH] HID: elan: Fix memleak in elan_input_configured Dinghao Liu
2020-08-31  7:48 ` Jiri Kosina
2020-08-31  7:56   ` dinghao.liu

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