ACPI / button: Add input_free_device() on registration failure
PATCH 1/1 ACPI / button: Add input_free_device() on registration failure
Add input_free_device() call when input_register_device() fails to prevent memory leak. According to input_register_device() documentation, "If function fails the device must be freed with input_free_device()", but the current code only jumps to err_remove_fs without freeing the allocated input device.
This ensures proper cleanup of the input device structure when device registration encounters an error, preventing resource leaks in the ACPI button driver.
--- drivers/acpi/button.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/acpi/button.c +3 -1
@@ -619,8 +619,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 :
Signature · 1 line
2.34.1
Quoted 23 lines · Kaushlendra Kumar
Add
input_free_device()call wheninput_register_device()fails to prevent memory leak. According toinput_register_device()documentation, "If function fails the device must be freed withinput_free_device()", but the current code only jumps toerr_remove_fswithout freeing the allocated input device.This ensures proper cleanup of the input device structure when device registration encounters an error, preventing resource leaks in the ACPI button driver.
Signed-off-by Kaushlendra Kumar <[email protected]>--- drivers/acpi/button.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/acpi/button.c +0
-0@@ -619,8 +619,10 @@ static int acpi_button_add(struct acpi_device *device)input_set_drvdata (input, device);
drivers/acpi/button.c static int acpi_button_add(struct acpi_device *device)
Quoted 10 lines
drivers/acpi/button.c +3
-2error =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 : --
Applied as 6.18-rc material with rewritten subject and changelog, thanks!