diff mbox series

ACPI: button: call input_free_device when input_register_device fails

Message ID 20240620085147.1097187-1-hongao@uniontech.com
State New
Headers show
Series ACPI: button: call input_free_device when input_register_device fails | expand

Commit Message

hongao June 20, 2024, 8:51 a.m. UTC
Call input_free_device when input_register_device fails.

Signed-off-by: hongao <hongao@uniontech.com>


base-commit: e5b3efbe1ab1793bb49ae07d56d0973267e65112

Comments

Rafael J. Wysocki July 2, 2024, 7:13 p.m. UTC | #1
On Thu, Jun 20, 2024 at 10:52 AM hongao <hongao@uniontech.com> wrote:
>
> Call input_free_device when input_register_device fails.

And this is in order to address a memory leak, isn't it?

> Signed-off-by: hongao <hongao@uniontech.com>
>
> diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
> index cc61020756be..8765e9a64404 100644
> --- a/drivers/acpi/button.c
> +++ b/drivers/acpi/button.c
> @@ -602,8 +602,10 @@ static int acpi_button_add(struct acpi_device *device)
>
>         input_set_drvdata(input, device);
>         error = input_register_device(input);
> -       if (error)
> +       if (error) {
> +               input_free_device(input);
>                 goto err_remove_fs;

AFAICS, there is one other case in which something like this would
need to be done and it's better to rearrange the error handling to
cover all of these cases without duplicating input_free_device()
calls.

> +       }
>
>         switch (device->device_type) {
>         case ACPI_BUS_TYPE_POWER_BUTTON:
>
> base-commit: e5b3efbe1ab1793bb49ae07d56d0973267e65112
> --
diff mbox series

Patch

diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index cc61020756be..8765e9a64404 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -602,8 +602,10 @@  static int acpi_button_add(struct acpi_device *device)
 
 	input_set_drvdata(input, device);
 	error = input_register_device(input);
-	if (error)
+	if (error) {
+		input_free_device(input);
 		goto err_remove_fs;
+	}
 
 	switch (device->device_type) {
 	case ACPI_BUS_TYPE_POWER_BUTTON: