Skip to contentSkip to conversation

HID: elan: Fix potential double free in elan_input_configured

PATCH In review Miaoqian Lin 3 participants 3 messages Apr 16, 2022 – Apr 21, 2022 HID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: elan: Fix potential double free in elan_input_configured

'input' is a managed resource allocated with devm_input_allocate_device(), so there is no need to call input_free_device() explicitly or there will be a double free.

According to the doc of devm_input_allocate_device():
* Managed input devices do not need to be explicitly unregistered or
* freed as it will be done automatically when owner device unbinds from
* its driver (or binding fails).

Fixes b7429ea53d6c ("HID: elan: Fix memleak in elan_input_configured")
Fixes 9a6a4193d65b ("HID: Add driver for USB ELAN Touchpad")
---
 drivers/hid/hid-elan.c | 2 --
 1 file changed, 2 deletions(-)
drivers/hid/hid-elan.c +0 -2
index 3091355d48df..8e4a5528e25d 100644
@@ -188,7 +188,6 @@ 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;
 	}
 
@@ -200,7 +199,6 @@ static int elan_input_configured(struct hid_device *hdev, struct hid_input *hi)
 		hid_err(hdev, "Failed to register elan input device: %d\n",
 			ret);
 		input_mt_destroy_slots(input);
-		input_free_device(input);
 		return ret;
 	}
 
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Miaoqian Lin

'input' is a managed resource allocated with devm_input_allocate_device(), so there is no need to call input_free_device() explicitly or there will be a double free.

Quoted 8 lines

According to the doc of devm_input_allocate_device():
* Managed input devices do not need to be explicitly unregistered or
* freed as it will be done automatically when owner device unbinds from
* its driver (or binding fails).

Fixes b7429ea53d6c ("HID: elan: Fix memleak in elan_input_configured")
Fixes 9a6a4193d65b ("HID: Add driver for USB ELAN Touchpad")

Thanks for the patch!

Cheers,
Benjamin

Quoted 27 lines
---
 drivers/hid/hid-elan.c | 2 --
 1 file changed, 2 deletions(-)
drivers/hid/hid-elan.c +0 -3
index 3091355d48df..8e4a5528e25d 100644
@@ -188,7 +188,6 @@ 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;
        }
 
@@ -200,7 +199,6 @@ static int elan_input_configured(struct hid_device *hdev, struct hid_input *hi)
                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

maintainer
#2 lore raw
Quoted 11 lines · Benjamin Tissoires
Quoted 10 lines · Miaoqian Lin

'input' is a managed resource allocated with devm_input_allocate_device(), so there is no need to call input_free_device() explicitly or there will be a double free.

According to the doc of devm_input_allocate_device():
* Managed input devices do not need to be explicitly unregistered or
* freed as it will be done automatically when owner device unbinds from
* its driver (or binding fails).

Quoted 7 lines
Quoted 3 lines
Fixes b7429ea53d6c ("HID: elan: Fix memleak in elan_input_configured")
Fixes 9a6a4193d65b ("HID: Add driver for USB ELAN Touchpad")

Thanks for the patch!

Hmm, this patch never seems to have reached my inbox, but we've had some trouble with our mailserver over the Easter weekend, so that could be it.

Thanks for the fix indeed, applied now to hid.git#for-5.18/upstream-fixes

Signature · 2 lines
Jiri Kosina
SUSE Labs