2010-07-02 01:40:29

by Axel Lin

[permalink] [raw]
Subject: [PATCH] fujitsu-laptop: remove unnecessary input_free_device calls

input_free_device should only be used if input_register_device()
was not called yet or if it failed.
This patch removes unnecessary input_free_device calls.

Signed-off-by: Axel Lin <[email protected]>
---
drivers/platform/x86/fujitsu-laptop.c | 21 ++++++++-------------
1 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
index e325aeb..dab1a0e 100644
--- a/drivers/platform/x86/fujitsu-laptop.c
+++ b/drivers/platform/x86/fujitsu-laptop.c
@@ -686,8 +686,10 @@ static int acpi_fujitsu_add(struct acpi_device *device)
set_bit(KEY_UNKNOWN, input->keybit);

error = input_register_device(input);
- if (error)
- goto err_free_input_dev;
+ if (error) {
+ input_free_device(input);
+ goto err_stop;
+ }

result = acpi_bus_get_power(fujitsu->acpi_handle, &state);
if (result) {
@@ -725,8 +727,6 @@ static int acpi_fujitsu_add(struct acpi_device *device)

err_unregister_input_dev:
input_unregister_device(input);
-err_free_input_dev:
- input_free_device(input);
err_stop:
return result;
}
@@ -737,9 +737,6 @@ static int acpi_fujitsu_remove(struct acpi_device *device, int type)
struct input_dev *input = fujitsu->input;

input_unregister_device(input);
-
- input_free_device(input);
-
fujitsu->acpi_handle = NULL;

return 0;
@@ -855,8 +852,10 @@ static int acpi_fujitsu_hotkey_add(struct acpi_device *device)
set_bit(KEY_UNKNOWN, input->keybit);

error = input_register_device(input);
- if (error)
- goto err_free_input_dev;
+ if (error) {
+ input_free_device(input);
+ goto err_free_fifo;
+ }

result = acpi_bus_get_power(fujitsu_hotkey->acpi_handle, &state);
if (result) {
@@ -930,8 +929,6 @@ static int acpi_fujitsu_hotkey_add(struct acpi_device *device)

err_unregister_input_dev:
input_unregister_device(input);
-err_free_input_dev:
- input_free_device(input);
err_free_fifo:
kfifo_free(&fujitsu_hotkey->fifo);
err_stop:
@@ -953,8 +950,6 @@ static int acpi_fujitsu_hotkey_remove(struct acpi_device *device, int type)

input_unregister_device(input);

- input_free_device(input);
-
kfifo_free(&fujitsu_hotkey->fifo);

fujitsu_hotkey->acpi_handle = NULL;
--
1.5.4.3



2010-07-02 02:19:28

by Jonathan Woithe

[permalink] [raw]
Subject: Re: [PATCH] fujitsu-laptop: remove unnecessary input_free_device calls

> input_free_device should only be used if input_register_device()
> was not called yet or if it failed.
>
> This patch removes unnecessary input_free_device calls.

Yes, indeed. Good catch. The patch looks good to me - thanks.

Acked-by: Jonathan Woithe <[email protected]>

> Signed-off-by: Axel Lin <[email protected]>
> ---
> drivers/platform/x86/fujitsu-laptop.c | 21 ++++++++-------------
> 1 files changed, 8 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
> index e325aeb..dab1a0e 100644
> --- a/drivers/platform/x86/fujitsu-laptop.c
> +++ b/drivers/platform/x86/fujitsu-laptop.c
> @@ -686,8 +686,10 @@ static int acpi_fujitsu_add(struct acpi_device *device)
> set_bit(KEY_UNKNOWN, input->keybit);
>
> error = input_register_device(input);
> - if (error)
> - goto err_free_input_dev;
> + if (error) {
> + input_free_device(input);
> + goto err_stop;
> + }
>
> result = acpi_bus_get_power(fujitsu->acpi_handle, &state);
> if (result) {
> @@ -725,8 +727,6 @@ static int acpi_fujitsu_add(struct acpi_device *device)
>
> err_unregister_input_dev:
> input_unregister_device(input);
> -err_free_input_dev:
> - input_free_device(input);
> err_stop:
> return result;
> }
> @@ -737,9 +737,6 @@ static int acpi_fujitsu_remove(struct acpi_device *device, int type)
> struct input_dev *input = fujitsu->input;
>
> input_unregister_device(input);
> -
> - input_free_device(input);
> -
> fujitsu->acpi_handle = NULL;
>
> return 0;
> @@ -855,8 +852,10 @@ static int acpi_fujitsu_hotkey_add(struct acpi_device *device)
> set_bit(KEY_UNKNOWN, input->keybit);
>
> error = input_register_device(input);
> - if (error)
> - goto err_free_input_dev;
> + if (error) {
> + input_free_device(input);
> + goto err_free_fifo;
> + }
>
> result = acpi_bus_get_power(fujitsu_hotkey->acpi_handle, &state);
> if (result) {
> @@ -930,8 +929,6 @@ static int acpi_fujitsu_hotkey_add(struct acpi_device *device)
>
> err_unregister_input_dev:
> input_unregister_device(input);
> -err_free_input_dev:
> - input_free_device(input);
> err_free_fifo:
> kfifo_free(&fujitsu_hotkey->fifo);
> err_stop:
> @@ -953,8 +950,6 @@ static int acpi_fujitsu_hotkey_remove(struct acpi_device *device, int type)
>
> input_unregister_device(input);
>
> - input_free_device(input);
> -
> kfifo_free(&fujitsu_hotkey->fifo);
>
> fujitsu_hotkey->acpi_handle = NULL;
> --
> 1.5.4.3
>
>
>

2010-07-02 06:20:12

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH] fujitsu-laptop: remove unnecessary input_free_device calls

Hi Axel,

On Fri, Jul 02, 2010 at 09:42:57AM +0800, Axel Lin wrote:
> input_free_device should only be used if input_register_device()
> was not called yet or if it failed.
> This patch removes unnecessary input_free_device calls.
>
> Signed-off-by: Axel Lin <[email protected]>
> ---
> drivers/platform/x86/fujitsu-laptop.c | 21 ++++++++-------------
> 1 files changed, 8 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
> index e325aeb..dab1a0e 100644
> --- a/drivers/platform/x86/fujitsu-laptop.c
> +++ b/drivers/platform/x86/fujitsu-laptop.c
> @@ -686,8 +686,10 @@ static int acpi_fujitsu_add(struct acpi_device *device)
> set_bit(KEY_UNKNOWN, input->keybit);
>
> error = input_register_device(input);
> - if (error)
> - goto err_free_input_dev;
> + if (error) {
> + input_free_device(input);
> + goto err_stop;
> + }

Instead of using mixed in-line and goto style cleanup I prefer doig the
following:

err_unregister_input_dev:
input_unregister_device(input);
input = NULL; <-- !!!
err_free_input_dev:
input_free_device(input);

input_free_device() happily accepts NULL pointers.

Otherwise the patch looks good.

Thanks.

--
Dmitry

2010-07-02 07:20:36

by Axel Lin

[permalink] [raw]
Subject: Re: [PATCH] fujitsu-laptop: remove unnecessary input_free_device calls

hi Dmitry,

2010/7/2 Dmitry Torokhov <[email protected]>:
> Hi Axel,
>
> On Fri, Jul 02, 2010 at 09:42:57AM +0800, Axel Lin wrote:
>> input_free_device should only be used if input_register_device()
>> was not called yet or if it failed.
>> This patch removes unnecessary input_free_device calls.
>>
>> Signed-off-by: Axel Lin <[email protected]>
>> ---
>> ?drivers/platform/x86/fujitsu-laptop.c | ? 21 ++++++++-------------
>> ?1 files changed, 8 insertions(+), 13 deletions(-)
>>
>> diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
>> index e325aeb..dab1a0e 100644
>> --- a/drivers/platform/x86/fujitsu-laptop.c
>> +++ b/drivers/platform/x86/fujitsu-laptop.c
>> @@ -686,8 +686,10 @@ static int acpi_fujitsu_add(struct acpi_device *device)
>> ? ? ? set_bit(KEY_UNKNOWN, input->keybit);
>>
>> ? ? ? error = input_register_device(input);
>> - ? ? if (error)
>> - ? ? ? ? ? ? goto err_free_input_dev;
>> + ? ? if (error) {
>> + ? ? ? ? ? ? input_free_device(input);
>> + ? ? ? ? ? ? goto err_stop;
>> + ? ? }
>
> Instead of using mixed in-line and goto style cleanup I prefer doig the
> following:
>
> ?err_unregister_input_dev:
> ? ? ? ?input_unregister_device(input);
> ? ? ? ?input = NULL; <-- !!!
> ?err_free_input_dev:
> ? ? ? ?input_free_device(input);
>
> input_free_device() happily accepts NULL pointers.

Thanks for the review. I will send a revised patch.

Regards,
Axel
>
> Otherwise the patch looks good.
>
> Thanks.
>
> --
> Dmitry
>