2021-11-08 03:09:31

by Christophe JAILLET

[permalink] [raw]
Subject: [PATCH] platform/x86: hp_accel: Fix an error handling path in 'lis3lv02d_probe()'

If 'led_classdev_register()' fails, some additional resources should be
released.

Add the missing 'i8042_remove_filter()' and 'lis3lv02d_remove_fs()' calls
that are already in the remove function but are missing here.

Fixes: a4c724d0723b ("platform: hp_accel: add a i8042 filter to remove HPQ6000 data from kb bus stream")
Fixes: 9e0c79782143 ("lis3lv02d: merge with leds hp disk")
Signed-off-by: Christophe JAILLET <[email protected]>
---
drivers/platform/x86/hp_accel.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/platform/x86/hp_accel.c b/drivers/platform/x86/hp_accel.c
index b183967ecfb7..435a91fe2568 100644
--- a/drivers/platform/x86/hp_accel.c
+++ b/drivers/platform/x86/hp_accel.c
@@ -331,9 +331,11 @@ static int lis3lv02d_probe(struct platform_device *device)
INIT_WORK(&hpled_led.work, delayed_set_status_worker);
ret = led_classdev_register(NULL, &hpled_led.led_classdev);
if (ret) {
+ i8042_remove_filter(hp_accel_i8042_filter);
lis3lv02d_joystick_disable(&lis3_dev);
lis3lv02d_poweroff(&lis3_dev);
flush_work(&hpled_led.work);
+ lis3lv02d_remove_fs(&lis3_dev);
return ret;
}

--
2.30.2


2021-11-09 01:03:02

by Mark Gross

[permalink] [raw]
Subject: Re: [PATCH] platform/x86: hp_accel: Fix an error handling path in 'lis3lv02d_probe()'

On Sun, Nov 07, 2021 at 08:57:07PM +0100, Christophe JAILLET wrote:
> If 'led_classdev_register()' fails, some additional resources should be
> released.
>
> Add the missing 'i8042_remove_filter()' and 'lis3lv02d_remove_fs()' calls
> that are already in the remove function but are missing here.
>
> Fixes: a4c724d0723b ("platform: hp_accel: add a i8042 filter to remove HPQ6000 data from kb bus stream")
> Fixes: 9e0c79782143 ("lis3lv02d: merge with leds hp disk")
> Signed-off-by: Christophe JAILLET <[email protected]>
> ---
> drivers/platform/x86/hp_accel.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/platform/x86/hp_accel.c b/drivers/platform/x86/hp_accel.c
> index b183967ecfb7..435a91fe2568 100644
> --- a/drivers/platform/x86/hp_accel.c
> +++ b/drivers/platform/x86/hp_accel.c
> @@ -331,9 +331,11 @@ static int lis3lv02d_probe(struct platform_device *device)
adding some lines of context:

326 /* filter to remove HPQ6000 accelerometer data
327 * from keyboard bus stream */
328 if (strstr(dev_name(&device->dev), "HPQ6000"))
329 i8042_install_filter(hp_accel_i8042_filter);
330
> INIT_WORK(&hpled_led.work, delayed_set_status_worker);
> ret = led_classdev_register(NULL, &hpled_led.led_classdev);
> if (ret) {
> + i8042_remove_filter(hp_accel_i8042_filter);
This filter was added under a conditional. Should it not be removed under a
similar conditional?
> lis3lv02d_joystick_disable(&lis3_dev);
> lis3lv02d_poweroff(&lis3_dev);
> flush_work(&hpled_led.work);
> + lis3lv02d_remove_fs(&lis3_dev);
where was the fs ever added?

--mark

> return ret;
> }
>
> --
> 2.30.2
>

2021-11-09 03:26:29

by Christophe JAILLET

[permalink] [raw]
Subject: Re: [PATCH] platform/x86: hp_accel: Fix an error handling path in 'lis3lv02d_probe()'

Le 08/11/2021 à 20:48, Mark Gross a écrit :
> On Sun, Nov 07, 2021 at 08:57:07PM +0100, Christophe JAILLET wrote:
>> If 'led_classdev_register()' fails, some additional resources should be
>> released.
>>
>> Add the missing 'i8042_remove_filter()' and 'lis3lv02d_remove_fs()' calls
>> that are already in the remove function but are missing here.
>>
>> Fixes: a4c724d0723b ("platform: hp_accel: add a i8042 filter to remove HPQ6000 data from kb bus stream")
>> Fixes: 9e0c79782143 ("lis3lv02d: merge with leds hp disk")
>> Signed-off-by: Christophe JAILLET <[email protected]>
>> ---
>> drivers/platform/x86/hp_accel.c | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/platform/x86/hp_accel.c b/drivers/platform/x86/hp_accel.c
>> index b183967ecfb7..435a91fe2568 100644
>> --- a/drivers/platform/x86/hp_accel.c
>> +++ b/drivers/platform/x86/hp_accel.c
>> @@ -331,9 +331,11 @@ static int lis3lv02d_probe(struct platform_device *device)
> adding some lines of context:
>
> 326 /* filter to remove HPQ6000 accelerometer data
> 327 * from keyboard bus stream */
> 328 if (strstr(dev_name(&device->dev), "HPQ6000"))
> 329 i8042_install_filter(hp_accel_i8042_filter);
> 330
>> INIT_WORK(&hpled_led.work, delayed_set_status_worker);
>> ret = led_classdev_register(NULL, &hpled_led.led_classdev);
>> if (ret) {
>> + i8042_remove_filter(hp_accel_i8042_filter);
> This filter was added under a conditional. Should it not be removed under a
> similar conditional?

Agreed that it looks odd, but in the remove function, we already don't
have the conditional.

Moreover, in, we have 'i8042_remove_filter()':
if (i8042_platform_filter != filter) {
ret = -EINVAL;
goto out;
}
So, if 'i8042_install_filter(hp_accel_i8042_filter)' is not called, the
removal will be a no-op.

>> lis3lv02d_joystick_disable(&lis3_dev);
>> lis3lv02d_poweroff(&lis3_dev);
>> flush_work(&hpled_led.work);
>> + lis3lv02d_remove_fs(&lis3_dev);
> where was the fs ever added?

In 'lis3lv02d_init_device()' (see [1]), like what is undone with
'lis3lv02d_joystick_disable()' and 'lis3lv02d_poweroff()'.

'lis3lv02d_remove_fs()' is also already part of the remove function.

I guess that having a 'lis3lv02d_uninit_device()' would be much more
cleaner.


[1]:
https://elixir.bootlin.com/linux/v5.15.1/source/drivers/misc/lis3lv02d/lis3lv02d.c#L1188

CJ
>
> --mark
>
>> return ret;
>> }
>>
>> --
>> 2.30.2
>>
>

2021-11-11 09:50:09

by Hans de Goede

[permalink] [raw]
Subject: Re: [PATCH] platform/x86: hp_accel: Fix an error handling path in 'lis3lv02d_probe()'

Hi,

On 11/7/21 20:57, Christophe JAILLET wrote:
> If 'led_classdev_register()' fails, some additional resources should be
> released.
>
> Add the missing 'i8042_remove_filter()' and 'lis3lv02d_remove_fs()' calls
> that are already in the remove function but are missing here.
>
> Fixes: a4c724d0723b ("platform: hp_accel: add a i8042 filter to remove HPQ6000 data from kb bus stream")
> Fixes: 9e0c79782143 ("lis3lv02d: merge with leds hp disk")
> Signed-off-by: Christophe JAILLET <[email protected]>

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <[email protected]>

I will add this fix to my tree once 5.16-rc1 is out and
I will include this fix in my first pdx86 fixes pull-req
for 5.16.

Regards,

Hans

> ---
> drivers/platform/x86/hp_accel.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/platform/x86/hp_accel.c b/drivers/platform/x86/hp_accel.c
> index b183967ecfb7..435a91fe2568 100644
> --- a/drivers/platform/x86/hp_accel.c
> +++ b/drivers/platform/x86/hp_accel.c
> @@ -331,9 +331,11 @@ static int lis3lv02d_probe(struct platform_device *device)
> INIT_WORK(&hpled_led.work, delayed_set_status_worker);
> ret = led_classdev_register(NULL, &hpled_led.led_classdev);
> if (ret) {
> + i8042_remove_filter(hp_accel_i8042_filter);
> lis3lv02d_joystick_disable(&lis3_dev);
> lis3lv02d_poweroff(&lis3_dev);
> flush_work(&hpled_led.work);
> + lis3lv02d_remove_fs(&lis3_dev);
> return ret;
> }
>
>