Skip to contentSkip to conversation

ACPI / button: Add input_free_device() on registration failure

PATCH Applied Kaushlendra Kumar 2 participants 2 messages Oct 6, 2025 – Oct 22, 2025 ACPI

lore
Share & tools
lore
#0 lore raw

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
index 0a7026040188..3c6dd9b4ba0a 100644
@@ -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
maintainer Applied
#1 lore raw
Quoted 23 lines · Kaushlendra Kumar

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 +0 -0
index 0a7026040188..3c6dd9b4ba0a 100644
@@ -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 -2
        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:
--

Applied as 6.18-rc material with rewritten subject and changelog, thanks!