diff mbox series

HID: elan: Fix memleak in elan_input_configured

Message ID 20200824072400.9612-1-dinghao.liu@zju.edu.cn (mailing list archive)
State Superseded
Delegated to: Jiri Kosina
Headers show
Series HID: elan: Fix memleak in elan_input_configured | expand

Commit Message

Dinghao Liu Aug. 24, 2020, 7:23 a.m. UTC
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(+)

Comments

Jiri Kosina Aug. 31, 2020, 7:48 a.m. UTC | #1
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!
Dinghao Liu Aug. 31, 2020, 7:56 a.m. UTC | #2
> 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
diff mbox series

Patch

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