diff mbox series

platform/x86: asus-tf103c-dock: fix possible memory leak in tf103c_dock_probe()

Message ID 20221029062759.2581143-1-yangyingliang@huawei.com (mailing list archive)
State Rejected, archived
Headers show
Series platform/x86: asus-tf103c-dock: fix possible memory leak in tf103c_dock_probe() | expand

Commit Message

Yang Yingliang Oct. 29, 2022, 6:27 a.m. UTC
If hid_add_device() returns error, it should call hid_destroy_device()
to free the hid which is allocated in hid_allocate_device().

Fixes: 0a6509b0926d ("platform/x86: Add Asus TF103C dock driver")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/platform/x86/asus-tf103c-dock.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Hans de Goede Nov. 7, 2022, 2:28 p.m. UTC | #1
Hi Yang,

On 10/29/22 08:27, Yang Yingliang wrote:
> If hid_add_device() returns error, it should call hid_destroy_device()
> to free the hid which is allocated in hid_allocate_device().
> 
> Fixes: 0a6509b0926d ("platform/x86: Add Asus TF103C dock driver")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>  drivers/platform/x86/asus-tf103c-dock.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/platform/x86/asus-tf103c-dock.c b/drivers/platform/x86/asus-tf103c-dock.c
> index 62310e06282b..f81d58dfd322 100644
> --- a/drivers/platform/x86/asus-tf103c-dock.c
> +++ b/drivers/platform/x86/asus-tf103c-dock.c
> @@ -850,8 +850,10 @@ static int tf103c_dock_probe(struct i2c_client *client)
>  	strscpy(dock->hid->phys, dev_name(dev), sizeof(dock->hid->phys));
>  
>  	ret = hid_add_device(dock->hid);
> -	if (ret)
> +	if (ret) {
> +		hid_destroy_device(dock->hid);
>  		return dev_err_probe(dev, ret, "adding hid dev\n");
> +	}

hid_destroy_device() is already called by tf103c_dock_non_devm_cleanup()
which is registered early on as a cleanup handler through
devm_add_action_or_reset().

Regards,

Hans
Yang Yingliang Nov. 7, 2022, 3:02 p.m. UTC | #2
Hi,

On 2022/11/7 22:28, Hans de Goede wrote:
> Hi Yang,
>
> On 10/29/22 08:27, Yang Yingliang wrote:
>> If hid_add_device() returns error, it should call hid_destroy_device()
>> to free the hid which is allocated in hid_allocate_device().
>>
>> Fixes: 0a6509b0926d ("platform/x86: Add Asus TF103C dock driver")
>> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
>> ---
>>   drivers/platform/x86/asus-tf103c-dock.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/platform/x86/asus-tf103c-dock.c b/drivers/platform/x86/asus-tf103c-dock.c
>> index 62310e06282b..f81d58dfd322 100644
>> --- a/drivers/platform/x86/asus-tf103c-dock.c
>> +++ b/drivers/platform/x86/asus-tf103c-dock.c
>> @@ -850,8 +850,10 @@ static int tf103c_dock_probe(struct i2c_client *client)
>>   	strscpy(dock->hid->phys, dev_name(dev), sizeof(dock->hid->phys));
>>   
>>   	ret = hid_add_device(dock->hid);
>> -	if (ret)
>> +	if (ret) {
>> +		hid_destroy_device(dock->hid);
>>   		return dev_err_probe(dev, ret, "adding hid dev\n");
>> +	}
> hid_destroy_device() is already called by tf103c_dock_non_devm_cleanup()
> which is registered early on as a cleanup handler through
> devm_add_action_or_reset().
Thanks for correcting me.

Yang
>
> Regards,
>
> Hans
>
>
> .
diff mbox series

Patch

diff --git a/drivers/platform/x86/asus-tf103c-dock.c b/drivers/platform/x86/asus-tf103c-dock.c
index 62310e06282b..f81d58dfd322 100644
--- a/drivers/platform/x86/asus-tf103c-dock.c
+++ b/drivers/platform/x86/asus-tf103c-dock.c
@@ -850,8 +850,10 @@  static int tf103c_dock_probe(struct i2c_client *client)
 	strscpy(dock->hid->phys, dev_name(dev), sizeof(dock->hid->phys));
 
 	ret = hid_add_device(dock->hid);
-	if (ret)
+	if (ret) {
+		hid_destroy_device(dock->hid);
 		return dev_err_probe(dev, ret, "adding hid dev\n");
+	}
 
 	/* 5. Setup irqchip for touchpad IRQ pass-through */
 	dock->tp_irqchip.name = KBUILD_MODNAME;